improve code

This commit is contained in:
Daniel Seifert 2023-01-15 22:24:49 +01:00
parent 4632fe1df7
commit f61d77e489
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
21 changed files with 32 additions and 37 deletions

View File

@ -10,4 +10,5 @@ parameters:
phpVersion: 70100 phpVersion: 70100
ignoreErrors: ignoreErrors:
- '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#'
- '#Cannot cast mixed to string.#' - '#Cannot cast mixed to string.#'
- '#Method D3\\Linkmobility4OXID\\Setup\\Actions::getUniqueFieldTypes\(\) should return array\<string\> but returns array\<int, string\|null\>.#'

View File

@ -21,6 +21,7 @@ use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\Linkmobility4OXID\Application\Model\UserRecipients;
use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\Response\ResponseInterface;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminController; use OxidEsales\Eshop\Application\Controller\Admin\AdminController;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
@ -63,6 +64,7 @@ class AdminUser extends AdminController
/** /**
* @return string * @return string
* @throws noRecipientFoundException * @throws noRecipientFoundException
* @throws Exception
*/ */
protected function sendMessage(): string protected function sendMessage(): string
{ {

View File

@ -19,7 +19,6 @@ use Assert\Assert;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
class Configuration class Configuration
{ {

View File

@ -18,7 +18,6 @@ namespace D3\Linkmobility4OXID\Application\Model\Exceptions;
use Exception; use Exception;
use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Language; use OxidEsales\Eshop\Core\Language;
use OxidEsales\Eshop\Core\Registry;
class successfullySentException extends StandardException class successfullySentException extends StandardException
{ {

View File

@ -183,9 +183,8 @@ class Sms extends AbstractMessage
protected function getRequest(Configuration $configuration, Client $client): SmsRequestInterface protected function getRequest(Configuration $configuration, Client $client): SmsRequestInterface
{ {
$requestFactory = $this->getRequestFactory($this->getMessage(), $client); $requestFactory = $this->getRequestFactory($this->getMessage(), $client);
$sender = $this->getSender($configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry()); $sender = $this->getSender((string) $configuration->getSmsSenderNumber(), (string) $configuration->getSmsSenderCountry());
/** @var SmsRequestInterface $request */
$request = $requestFactory->getSmsRequest(); $request = $requestFactory->getSmsRequest();
$request->setTestMode($configuration->getTestMode())->setMethod(RequestInterface::METHOD_POST) $request->setTestMode($configuration->getTestMode())->setMethod(RequestInterface::METHOD_POST)
->setSenderAddress($sender) ->setSenderAddress($sender)
@ -221,6 +220,8 @@ class Sms extends AbstractMessage
* @return ResponseInterface * @return ResponseInterface
* @throws ApiException * @throws ApiException
* @throws GuzzleException * @throws GuzzleException
* @throws NumberParseException
* @throws RecipientException
*/ */
protected function submitMessage(RecipientsListInterface $recipientsList): ResponseInterface protected function submitMessage(RecipientsListInterface $recipientsList): ResponseInterface
{ {
@ -257,7 +258,7 @@ class Sms extends AbstractMessage
/** /**
* @return LoggerInterface * @return LoggerInterface
*/ */
public function getLogger() public function getLogger(): LoggerInterface
{ {
return Registry::getLogger(); return Registry::getLogger();
} }

View File

@ -70,7 +70,7 @@ class OrderRecipients
/** @var string $countryId */ /** @var string $countryId */
$countryId = $this->order->getFieldData(trim($countryIdFieldName)); $countryId = $this->order->getFieldData(trim($countryIdFieldName));
$country->load($countryId); $country->load($countryId);
return $this->getRecipient($content, $country->getFieldData('oxisoalpha2')); return $this->getRecipient($content, (string) $country->getFieldData('oxisoalpha2'));
} }
} catch (NumberParseException|RecipientException $e) { } catch (NumberParseException|RecipientException $e) {
/** @var LoggerHandler $loggerHandler */ /** @var LoggerHandler $loggerHandler */

View File

@ -40,7 +40,7 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
/** @var SmsRequestInterface $request */ /** @var SmsRequestInterface $request */
$request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']); $request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']);
$sender = $this->getSender($configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry()); $sender = $this->getSender((string) $configuration->getSmsSenderNumber(), (string) $configuration->getSmsSenderCountry());
$request->setTestMode($configuration->getTestMode()) $request->setTestMode($configuration->getTestMode())
->setSenderAddress($sender) ->setSenderAddress($sender)
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL); ->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);

View File

@ -70,7 +70,7 @@ class UserRecipients
/** @var string $countryId */ /** @var string $countryId */
$countryId = $this->user->getFieldData('oxcountryid'); $countryId = $this->user->getFieldData('oxcountryid');
$country->load($countryId); $country->load($countryId);
return $this->getRecipient($content, $country->getFieldData('oxisoalpha2')); return $this->getRecipient($content, (string) $country->getFieldData('oxisoalpha2'));
} }
} catch (NumberParseException|RecipientException $e) { } catch (NumberParseException|RecipientException $e) {
/** @var LoggerHandler $loggerHandler */ /** @var LoggerHandler $loggerHandler */

View File

@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\Modules\Application\Model;
use D3\Linkmobility4OXID\Modules\Core\EmailCore; use D3\Linkmobility4OXID\Modules\Core\EmailCore;
use D3\TestingTools\Production\IsMockable; use D3\TestingTools\Production\IsMockable;
use Exception;
use OxidEsales\Eshop\Core\Email; use OxidEsales\Eshop\Core\Email;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
@ -29,6 +30,7 @@ class OrderModel extends OrderModel_parent
* @return void * @return void
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws Exception
*/ */
public function cancelOrder(): void public function cancelOrder(): void
{ {

View File

@ -43,6 +43,7 @@ class EmailCore extends EmailCore_parent
* @return bool * @return bool
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws Exception
*/ */
public function sendOrderEmailToUser($order, $subject = null) public function sendOrderEmailToUser($order, $subject = null)
{ {
@ -62,6 +63,7 @@ class EmailCore extends EmailCore_parent
* @return bool * @return bool
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
* @throws Exception
*/ */
public function sendSendedNowMail($order, $subject = null) public function sendSendedNowMail($order, $subject = null)
{ {

View File

@ -194,15 +194,16 @@ class Actions
} }
/** /**
* @param $checkIdent * @param string $checkIdent
* @return bool * @return bool
* @throws DoctrineDriverException * @throws DoctrineDriverException
* @throws DoctrineException * @throws DoctrineException
*/ */
protected function cmsMissing($checkIdent): bool protected function cmsMissing(string $checkIdent): bool
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilderFactory $queryBuilderFactory */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
$qb = $queryBuilderFactory->create();
$qb->select('count(oxid)') $qb->select('count(oxid)')
->from(oxNew(Content::class)->getViewName()) ->from(oxNew(Content::class)->getViewName())
->where( ->where(
@ -232,8 +233,9 @@ class Actions
*/ */
protected function addCms1Item() protected function addCms1Item()
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilderFactory $queryBuilderFactory */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
$qb = $queryBuilderFactory->create();
$qb->insert('oxcontents') $qb->insert('oxcontents')
->values([ ->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',
@ -261,8 +263,9 @@ class Actions
*/ */
protected function addCms2Item() protected function addCms2Item()
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilderFactory $queryBuilderFactory */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
$qb = $queryBuilderFactory->create();
$qb->insert('oxcontents') $qb->insert('oxcontents')
->values([ ->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',
@ -290,8 +293,9 @@ class Actions
*/ */
protected function addCms3Item() protected function addCms3Item()
{ {
/** @var QueryBuilder $qb */ /** @var QueryBuilderFactory $queryBuilderFactory */
$qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class);
$qb = $queryBuilderFactory->create();
$qb->insert('oxcontents') $qb->insert('oxcontents')
->values([ ->values([
'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))',

View File

@ -17,13 +17,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\Setup; namespace D3\Linkmobility4OXID\Setup;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use D3\ModCfg\Application\Model\Install\d3install;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Exception\SystemComponentException;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests; namespace D3\Linkmobility4OXID\tests;
use D3\ModCfg\Tests\additional_abstract; use D3\ModCfg\Tests\additional_abstract;
use OxidEsales\Eshop\Core\Exception\StandardException;
class additional extends additional_abstract class additional extends additional_abstract
{ {

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\integration; namespace D3\Linkmobility4OXID\tests\integration;
use D3\Linkmobility4OXID\Application\Model\Configuration; use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Modules\Core\EmailCore;
use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Exception as DoctrineException;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use Exception; use Exception;
@ -27,7 +26,6 @@ use GuzzleHttp\Psr7\Response;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\Remark;
use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Email;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;

View File

@ -35,7 +35,6 @@ use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Spipu\Html2Pdf\Tag\Html\Em;
class finishedOrderTest extends LMIntegrationTestCase class finishedOrderTest extends LMIntegrationTestCase
{ {

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
use D3\DIContainerHandler\d3DicHandler;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
use D3\DIContainerHandler\d3DicHandler;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException;
@ -28,7 +27,6 @@ use D3\LinkmobilityClient\SMS\Response;
use D3\LinkmobilityClient\ValueObject\Recipient; use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use InvalidArgumentException; use InvalidArgumentException;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Core\Request; use OxidEsales\Eshop\Core\Request;
use OxidEsales\Eshop\Core\UtilsView; use OxidEsales\Eshop\Core\UtilsView;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;

View File

@ -15,7 +15,6 @@ declare(strict_types=1);
namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin;
use D3\DIContainerHandler\d3DicHandler;
use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser;
use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;

View File

@ -88,10 +88,11 @@ class ConfigurationTest extends LMUnitTestCase
/** /**
* @test * @test
* @param $testMode * @param $testMode
* @param $expected
* @return void * @return void
* @throws ReflectionException * @throws ReflectionException
* @dataProvider trueFalseDataProvider * @dataProvider trueFalseDataProvider
* @covers \D3\Linkmobility4OXID\Application\Model\Configuration::getTestMode * @covers \D3\Linkmobility4OXID\Application\Model\Configuration::getTestMode
*/ */
public function canGetTestMode($testMode, $expected) public function canGetTestMode($testMode, $expected)
{ {

View File

@ -21,7 +21,6 @@ use D3\Linkmobility4OXID\Application\Model\MessageSender;
use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\TestingTools\Development\CanAccessRestricted; use D3\TestingTools\Development\CanAccessRestricted;
use Hoa\Iterator\Mock;
use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException; use ReflectionException;

View File

@ -45,7 +45,7 @@ abstract class LMUnitTestCase extends UnitTestCase
* *
* @return MockObject * @return MockObject
*/ */
protected function getContainerMock($serviceName, $serviceMock) protected function getContainerMock($serviceName, $serviceMock): MockObject
{ {
$container = $this->getMockBuilder(ContainerInterface::class) $container = $this->getMockBuilder(ContainerInterface::class)
->onlyMethods(['get', 'has']) ->onlyMethods(['get', 'has'])