From f61d77e489906f74dccf5cdc250018fac51b23ca Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 15 Jan 2023 22:24:49 +0100 Subject: [PATCH] improve code --- phpstan.neon | 3 ++- .../Controller/Admin/AdminUser.php | 2 ++ src/Application/Model/Configuration.php | 1 - .../Exceptions/successfullySentException.php | 1 - src/Application/Model/MessageTypes/Sms.php | 7 +++--- src/Application/Model/OrderRecipients.php | 2 +- src/Application/Model/RequestFactory.php | 2 +- src/Application/Model/UserRecipients.php | 2 +- src/Modules/Application/Model/OrderModel.php | 2 ++ src/Modules/Core/EmailCore.php | 2 ++ src/Setup/Actions.php | 24 +++++++++++-------- src/Setup/Events.php | 7 ------ src/tests/additional.inc.php | 1 - src/tests/integration/canceledOrderTest.php | 2 -- src/tests/integration/finishedOrderTest.php | 1 - .../Controller/Admin/AdminOrderTest.php | 1 - .../Controller/Admin/AdminSend.php | 2 -- .../Controller/Admin/AdminUserTest.php | 1 - .../Application/Model/ConfigurationTest.php | 3 ++- .../Application/Model/MessageSenderTest.php | 1 - src/tests/unit/LMUnitTestCase.php | 2 +- 21 files changed, 32 insertions(+), 37 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index f15cc97..622f122 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,4 +10,5 @@ parameters: phpVersion: 70100 ignoreErrors: - '#Psr\\Container\\ContainerExceptionInterface is not subtype of Throwable#' - - '#Cannot cast mixed to string.#' \ No newline at end of file + - '#Cannot cast mixed to string.#' + - '#Method D3\\Linkmobility4OXID\\Setup\\Actions::getUniqueFieldTypes\(\) should return array\ but returns array\.#' \ No newline at end of file diff --git a/src/Application/Controller/Admin/AdminUser.php b/src/Application/Controller/Admin/AdminUser.php index 699d477..80c8e67 100644 --- a/src/Application/Controller/Admin/AdminUser.php +++ b/src/Application/Controller/Admin/AdminUser.php @@ -21,6 +21,7 @@ use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\Application\Model\UserRecipients; use D3\LinkmobilityClient\Response\ResponseInterface; use D3\LinkmobilityClient\ValueObject\Recipient; +use Exception; use InvalidArgumentException; use OxidEsales\Eshop\Application\Controller\Admin\AdminController; use OxidEsales\Eshop\Application\Model\User; @@ -63,6 +64,7 @@ class AdminUser extends AdminController /** * @return string * @throws noRecipientFoundException + * @throws Exception */ protected function sendMessage(): string { diff --git a/src/Application/Model/Configuration.php b/src/Application/Model/Configuration.php index 3182533..1bf3416 100644 --- a/src/Application/Model/Configuration.php +++ b/src/Application/Model/Configuration.php @@ -19,7 +19,6 @@ use Assert\Assert; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\User; use OxidEsales\Eshop\Core\Config; -use OxidEsales\Eshop\Core\Registry; class Configuration { diff --git a/src/Application/Model/Exceptions/successfullySentException.php b/src/Application/Model/Exceptions/successfullySentException.php index a54dde8..0074280 100644 --- a/src/Application/Model/Exceptions/successfullySentException.php +++ b/src/Application/Model/Exceptions/successfullySentException.php @@ -18,7 +18,6 @@ namespace D3\Linkmobility4OXID\Application\Model\Exceptions; use Exception; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Language; -use OxidEsales\Eshop\Core\Registry; class successfullySentException extends StandardException { diff --git a/src/Application/Model/MessageTypes/Sms.php b/src/Application/Model/MessageTypes/Sms.php index 3281d12..eea1067 100644 --- a/src/Application/Model/MessageTypes/Sms.php +++ b/src/Application/Model/MessageTypes/Sms.php @@ -183,9 +183,8 @@ class Sms extends AbstractMessage protected function getRequest(Configuration $configuration, Client $client): SmsRequestInterface { $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->setTestMode($configuration->getTestMode())->setMethod(RequestInterface::METHOD_POST) ->setSenderAddress($sender) @@ -221,6 +220,8 @@ class Sms extends AbstractMessage * @return ResponseInterface * @throws ApiException * @throws GuzzleException + * @throws NumberParseException + * @throws RecipientException */ protected function submitMessage(RecipientsListInterface $recipientsList): ResponseInterface { @@ -257,7 +258,7 @@ class Sms extends AbstractMessage /** * @return LoggerInterface */ - public function getLogger() + public function getLogger(): LoggerInterface { return Registry::getLogger(); } diff --git a/src/Application/Model/OrderRecipients.php b/src/Application/Model/OrderRecipients.php index f306a3a..ca7c4ac 100644 --- a/src/Application/Model/OrderRecipients.php +++ b/src/Application/Model/OrderRecipients.php @@ -70,7 +70,7 @@ class OrderRecipients /** @var string $countryId */ $countryId = $this->order->getFieldData(trim($countryIdFieldName)); $country->load($countryId); - return $this->getRecipient($content, $country->getFieldData('oxisoalpha2')); + return $this->getRecipient($content, (string) $country->getFieldData('oxisoalpha2')); } } catch (NumberParseException|RecipientException $e) { /** @var LoggerHandler $loggerHandler */ diff --git a/src/Application/Model/RequestFactory.php b/src/Application/Model/RequestFactory.php index 261e5ec..46ddeec 100644 --- a/src/Application/Model/RequestFactory.php +++ b/src/Application/Model/RequestFactory.php @@ -40,7 +40,7 @@ class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory /** @var SmsRequestInterface $request */ $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()) ->setSenderAddress($sender) ->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL); diff --git a/src/Application/Model/UserRecipients.php b/src/Application/Model/UserRecipients.php index ab48586..5ade901 100644 --- a/src/Application/Model/UserRecipients.php +++ b/src/Application/Model/UserRecipients.php @@ -70,7 +70,7 @@ class UserRecipients /** @var string $countryId */ $countryId = $this->user->getFieldData('oxcountryid'); $country->load($countryId); - return $this->getRecipient($content, $country->getFieldData('oxisoalpha2')); + return $this->getRecipient($content, (string) $country->getFieldData('oxisoalpha2')); } } catch (NumberParseException|RecipientException $e) { /** @var LoggerHandler $loggerHandler */ diff --git a/src/Modules/Application/Model/OrderModel.php b/src/Modules/Application/Model/OrderModel.php index 1f35a7f..d363f54 100644 --- a/src/Modules/Application/Model/OrderModel.php +++ b/src/Modules/Application/Model/OrderModel.php @@ -17,6 +17,7 @@ namespace D3\Linkmobility4OXID\Modules\Application\Model; use D3\Linkmobility4OXID\Modules\Core\EmailCore; use D3\TestingTools\Production\IsMockable; +use Exception; use OxidEsales\Eshop\Core\Email; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; @@ -29,6 +30,7 @@ class OrderModel extends OrderModel_parent * @return void * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface + * @throws Exception */ public function cancelOrder(): void { diff --git a/src/Modules/Core/EmailCore.php b/src/Modules/Core/EmailCore.php index de58d67..e789b1f 100644 --- a/src/Modules/Core/EmailCore.php +++ b/src/Modules/Core/EmailCore.php @@ -43,6 +43,7 @@ class EmailCore extends EmailCore_parent * @return bool * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface + * @throws Exception */ public function sendOrderEmailToUser($order, $subject = null) { @@ -62,6 +63,7 @@ class EmailCore extends EmailCore_parent * @return bool * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface + * @throws Exception */ public function sendSendedNowMail($order, $subject = null) { diff --git a/src/Setup/Actions.php b/src/Setup/Actions.php index 3672857..bbae610 100644 --- a/src/Setup/Actions.php +++ b/src/Setup/Actions.php @@ -194,15 +194,16 @@ class Actions } /** - * @param $checkIdent + * @param string $checkIdent * @return bool * @throws DoctrineDriverException * @throws DoctrineException */ - protected function cmsMissing($checkIdent): bool + protected function cmsMissing(string $checkIdent): bool { - /** @var QueryBuilder $qb */ - $qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + /** @var QueryBuilderFactory $queryBuilderFactory */ + $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class); + $qb = $queryBuilderFactory->create(); $qb->select('count(oxid)') ->from(oxNew(Content::class)->getViewName()) ->where( @@ -232,8 +233,9 @@ class Actions */ protected function addCms1Item() { - /** @var QueryBuilder $qb */ - $qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + /** @var QueryBuilderFactory $queryBuilderFactory */ + $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class); + $qb = $queryBuilderFactory->create(); $qb->insert('oxcontents') ->values([ 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', @@ -261,8 +263,9 @@ class Actions */ protected function addCms2Item() { - /** @var QueryBuilder $qb */ - $qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + /** @var QueryBuilderFactory $queryBuilderFactory */ + $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class); + $qb = $queryBuilderFactory->create(); $qb->insert('oxcontents') ->values([ 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', @@ -290,8 +293,9 @@ class Actions */ protected function addCms3Item() { - /** @var QueryBuilder $qb */ - $qb = $this->getContainer()->get(QueryBuilderFactoryInterface::class)->create(); + /** @var QueryBuilderFactory $queryBuilderFactory */ + $queryBuilderFactory = $this->getContainer()->get(QueryBuilderFactoryInterface::class); + $qb = $queryBuilderFactory->create(); $qb->insert('oxcontents') ->values([ 'oxid' => 'MD5(CONCAT('.$qb->createNamedParameter(__FUNCTION__).', NOW()))', diff --git a/src/Setup/Events.php b/src/Setup/Events.php index e305a97..af5f9cf 100644 --- a/src/Setup/Events.php +++ b/src/Setup/Events.php @@ -17,13 +17,6 @@ declare(strict_types=1); 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\NotFoundExceptionInterface; diff --git a/src/tests/additional.inc.php b/src/tests/additional.inc.php index c82ae12..6f731ab 100644 --- a/src/tests/additional.inc.php +++ b/src/tests/additional.inc.php @@ -16,7 +16,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\tests; use D3\ModCfg\Tests\additional_abstract; -use OxidEsales\Eshop\Core\Exception\StandardException; class additional extends additional_abstract { diff --git a/src/tests/integration/canceledOrderTest.php b/src/tests/integration/canceledOrderTest.php index fdbda28..c97b475 100644 --- a/src/tests/integration/canceledOrderTest.php +++ b/src/tests/integration/canceledOrderTest.php @@ -16,7 +16,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\tests\integration; use D3\Linkmobility4OXID\Application\Model\Configuration; -use D3\Linkmobility4OXID\Modules\Core\EmailCore; use Doctrine\DBAL\Exception as DoctrineException; use Doctrine\DBAL\Query\QueryBuilder; use Exception; @@ -27,7 +26,6 @@ use GuzzleHttp\Psr7\Response; use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Remark; use OxidEsales\Eshop\Application\Model\User; -use OxidEsales\Eshop\Core\Email; use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory; use OxidEsales\EshopCommunity\Internal\Framework\Database\QueryBuilderFactoryInterface; use PHPUnit\Framework\MockObject\MockObject; diff --git a/src/tests/integration/finishedOrderTest.php b/src/tests/integration/finishedOrderTest.php index 7540e76..3440546 100644 --- a/src/tests/integration/finishedOrderTest.php +++ b/src/tests/integration/finishedOrderTest.php @@ -35,7 +35,6 @@ use PHPUnit\Framework\MockObject\MockObject; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\RequestInterface; -use Spipu\Html2Pdf\Tag\Html\Em; class finishedOrderTest extends LMIntegrationTestCase { diff --git a/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php b/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php index 1e1fbf9..67341a3 100644 --- a/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php +++ b/src/tests/unit/Application/Controller/Admin/AdminOrderTest.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; -use D3\DIContainerHandler\d3DicHandler; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminOrder; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; diff --git a/src/tests/unit/Application/Controller/Admin/AdminSend.php b/src/tests/unit/Application/Controller/Admin/AdminSend.php index 2a17f90..b97fbc6 100644 --- a/src/tests/unit/Application/Controller/Admin/AdminSend.php +++ b/src/tests/unit/Application/Controller/Admin/AdminSend.php @@ -15,7 +15,6 @@ declare(strict_types=1); 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\AdminUser; use D3\Linkmobility4OXID\Application\Model\Exceptions\noRecipientFoundException; @@ -28,7 +27,6 @@ use D3\LinkmobilityClient\SMS\Response; use D3\LinkmobilityClient\ValueObject\Recipient; use D3\TestingTools\Development\CanAccessRestricted; use InvalidArgumentException; -use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Request; use OxidEsales\Eshop\Core\UtilsView; use PHPUnit\Framework\MockObject\MockObject; diff --git a/src/tests/unit/Application/Controller/Admin/AdminUserTest.php b/src/tests/unit/Application/Controller/Admin/AdminUserTest.php index e4753c6..85ca6bf 100644 --- a/src/tests/unit/Application/Controller/Admin/AdminUserTest.php +++ b/src/tests/unit/Application/Controller/Admin/AdminUserTest.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace D3\Linkmobility4OXID\tests\unit\Application\Controller\Admin; -use D3\DIContainerHandler\d3DicHandler; use D3\Linkmobility4OXID\Application\Controller\Admin\AdminUser; use D3\Linkmobility4OXID\Application\Model\Exceptions\successfullySentException; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; diff --git a/src/tests/unit/Application/Model/ConfigurationTest.php b/src/tests/unit/Application/Model/ConfigurationTest.php index 8db835b..70974e6 100644 --- a/src/tests/unit/Application/Model/ConfigurationTest.php +++ b/src/tests/unit/Application/Model/ConfigurationTest.php @@ -88,10 +88,11 @@ class ConfigurationTest extends LMUnitTestCase /** * @test * @param $testMode + * @param $expected * @return void * @throws ReflectionException * @dataProvider trueFalseDataProvider - * @covers \D3\Linkmobility4OXID\Application\Model\Configuration::getTestMode + * @covers \D3\Linkmobility4OXID\Application\Model\Configuration::getTestMode */ public function canGetTestMode($testMode, $expected) { diff --git a/src/tests/unit/Application/Model/MessageSenderTest.php b/src/tests/unit/Application/Model/MessageSenderTest.php index ecefd79..38e4bee 100644 --- a/src/tests/unit/Application/Model/MessageSenderTest.php +++ b/src/tests/unit/Application/Model/MessageSenderTest.php @@ -21,7 +21,6 @@ use D3\Linkmobility4OXID\Application\Model\MessageSender; use D3\Linkmobility4OXID\Application\Model\MessageTypes\Sms; use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase; use D3\TestingTools\Development\CanAccessRestricted; -use Hoa\Iterator\Mock; use OxidEsales\Eshop\Application\Model\Order; use PHPUnit\Framework\MockObject\MockObject; use ReflectionException; diff --git a/src/tests/unit/LMUnitTestCase.php b/src/tests/unit/LMUnitTestCase.php index 20e4a3d..4b6cb3e 100644 --- a/src/tests/unit/LMUnitTestCase.php +++ b/src/tests/unit/LMUnitTestCase.php @@ -45,7 +45,7 @@ abstract class LMUnitTestCase extends UnitTestCase * * @return MockObject */ - protected function getContainerMock($serviceName, $serviceMock) + protected function getContainerMock($serviceName, $serviceMock): MockObject { $container = $this->getMockBuilder(ContainerInterface::class) ->onlyMethods(['get', 'has'])