From cd34d77c2c4862edfec478797a0dc7a20fb5f78b Mon Sep 17 00:00:00 2001 From: Michael Telgmann Date: Wed, 13 Nov 2024 16:56:34 +0100 Subject: [PATCH] chore: Update PHPStan and its plugins --- .phpstan-baseline.neon | 94 +------------------ composer.json | 8 +- composer.lock | 54 +++++------ .../ShortForeachResolver.php | 15 +-- .../Commands/FirstRunWizardDisableCommand.php | 20 ++-- .../Commands/FirstRunWizardEnableCommand.php | 20 ++-- .../Components/AddLinkHeaderSubscriber.php | 39 +++----- .../Cart/ConditionalLineItemService.php | 37 +++----- .../Components/Plugin/CronjobSynchronizer.php | 26 ++--- .../Shopware/Controllers/Frontend/Forms.php | 2 +- .../Controllers/Backend/SwagUpdate.php | 6 +- .../StoreFrontBundle/ListProductTest.php | 7 +- .../Privacy/CookieRemoveSubscriberTest.php | 2 +- .../SitemapBundle/SitemapListenerTest.php | 3 +- 14 files changed, 109 insertions(+), 224 deletions(-) diff --git a/.phpstan-baseline.neon b/.phpstan-baseline.neon index 7fb526c8f98..4565c3865e9 100644 --- a/.phpstan-baseline.neon +++ b/.phpstan-baseline.neon @@ -3220,11 +3220,6 @@ parameters: count: 1 path: engine/Library/Enlight/Template/Plugins/block.stripLines.php - - - message: "#^Function smarty_block_stripLines\\(\\) never returns void so it can be removed from the return type\\.$#" - count: 1 - path: engine/Library/Enlight/Template/Plugins/block.stripLines.php - - message: "#^Method Smarty_Compiler_Config\\:\\:compile\\(\\) has parameter \\$args with no value type specified in iterable type array\\.$#" count: 1 @@ -11855,36 +11850,6 @@ parameters: count: 1 path: engine/Shopware/Commands/DatabaseSetupCommand.php - - - message: "#^Method Shopware\\\\Commands\\\\FirstRunWizardDisableCommand\\:\\:configure\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Shopware/Commands/FirstRunWizardDisableCommand.php - - - - message: "#^Query error\\: Column \"s_core_config_values\\.element_id\" expects value type int, got type mixed$#" - count: 2 - path: engine/Shopware/Commands/FirstRunWizardDisableCommand.php - - - - message: "#^Query error\\: Column \"s_core_config_values\\.id\" expects value type int, got type mixed~0\\|0\\.0\\|''\\|'0'\\|array\\{\\}\\|false\\|null$#" - count: 1 - path: engine/Shopware/Commands/FirstRunWizardDisableCommand.php - - - - message: "#^Method Shopware\\\\Commands\\\\FirstRunWizardEnableCommand\\:\\:configure\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Shopware/Commands/FirstRunWizardEnableCommand.php - - - - message: "#^Query error\\: Column \"s_core_config_values\\.element_id\" expects value type int, got type mixed$#" - count: 2 - path: engine/Shopware/Commands/FirstRunWizardEnableCommand.php - - - - message: "#^Query error\\: Column \"s_core_config_values\\.id\" expects value type int, got type mixed~0\\|0\\.0\\|''\\|'0'\\|array\\{\\}\\|false\\|null$#" - count: 1 - path: engine/Shopware/Commands/FirstRunWizardEnableCommand.php - - message: "#^Method Shopware\\\\Commands\\\\GenerateAttributesCommand\\:\\:configure\\(\\) has no return type specified\\.$#" count: 1 @@ -12685,11 +12650,6 @@ parameters: count: 1 path: engine/Shopware/Components/Acl.php - - - message: "#^Access to an undefined property Enlight_Controller_Response_Response\\:\\:\\$headers\\.$#" - count: 1 - path: engine/Shopware/Components/AddLinkHeaderSubscriber.php - - message: "#^Cannot call method setAcl\\(\\) on object\\|null\\.$#" count: 1 @@ -14125,21 +14085,6 @@ parameters: count: 1 path: engine/Shopware/Components/Cart/CartPersistService.php - - - message: "#^Query error\\: Column \"s_order_basket\\.currencyFactor\" expects value type float\\|int, got type mixed~0\\|0\\.0\\|''\\|'0'\\|array\\{\\}\\|false\\|null$#" - count: 1 - path: engine/Shopware/Components/Cart/ConditionalLineItemService.php - - - - message: "#^Query error\\: Column \"s_order_basket\\.sessionID\" expects value type string\\|null, got type mixed$#" - count: 1 - path: engine/Shopware/Components/Cart/ConditionalLineItemService.php - - - - message: "#^Query error\\: Column \"s_order_basket_attributes\\.basketID\" expects value type int\\|null, got type int\\|string\\|false$#" - count: 1 - path: engine/Shopware/Components/Cart/ConditionalLineItemService.php - - message: "#^Parameter \\#4 \\$path of class Symfony\\\\Component\\\\HttpFoundation\\\\Cookie constructor expects string\\|null, string\\|false given\\.$#" count: 1 @@ -17956,47 +17901,12 @@ parameters: path: engine/Shopware/Components/Plugin/Configuration/ReaderInterface.php - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:addCronjob\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:addCronjob\\(\\) has parameter \\$cronjob with no value type specified in iterable type array\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:removeNotExistingEntries\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:removeNotExistingEntries\\(\\) has parameter \\$cronjobActions with no value type specified in iterable type array\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:synchronize\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Method Shopware\\\\Components\\\\Plugin\\\\CronjobSynchronizer\\:\\:synchronize\\(\\) has parameter \\$cronjobs with no value type specified in iterable type array\\.$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Query error\\: Argument \\#1 is not a constant array, got array\\&hasOffsetValue\\('pluginID', int\\)$#" - count: 1 - path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - - - message: "#^Query error\\: Argument \\#1 is not a constant array, got hasOffsetValue\\('end', DateTime\\)&hasOffsetValue\\('next', DateTime\\)&hasOffsetValue\\('pluginID', int\\)&non\\-empty\\-array$#" + message: "#^Query error\\: Argument \\#1 is not a constant array, got array\\&hasOffsetValue\\('pluginID', int\\)$#" count: 1 path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php - - message: "#^Query error\\: Column \"s_crontab\\.id\" expects value type int, got type mixed~0\\|0\\.0\\|''\\|'0'\\|array\\{\\}\\|false\\|null$#" + message: "#^Query error\\: Argument \\#1 is not a constant array, got non\\-empty\\-array\\&hasOffsetValue\\('end', DateTime\\)&hasOffsetValue\\('next', DateTime\\)&hasOffsetValue\\('pluginID', int\\)$#" count: 1 path: engine/Shopware/Components/Plugin/CronjobSynchronizer.php diff --git a/composer.json b/composer.json index 38d87b32d72..081db649faa 100644 --- a/composer.json +++ b/composer.json @@ -112,10 +112,10 @@ "friends-of-behat/mink-extension": "2.7.5", "php-parallel-lint/php-var-dump-check": "^0.5", "phpstan/extension-installer": "1.4.3", - "phpstan/phpstan": "1.12.0", - "phpstan/phpstan-doctrine": "1.5.3", - "phpstan/phpstan-phpunit": "1.4.0", - "phpstan/phpstan-symfony": "1.4.11", + "phpstan/phpstan": "1.12.10", + "phpstan/phpstan-doctrine": "1.5.6", + "phpstan/phpstan-phpunit": "1.4.1", + "phpstan/phpstan-symfony": "1.4.12", "phpunit/phpunit": "^9.6", "sensiolabs/behat-page-object-extension": "2.3.7", "staabm/phpstan-dba": "0.2.81", diff --git a/composer.lock b/composer.lock index 4b4a3ad5aba..b55982ececd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94ebce4f23a81a22ab4a0d904fb0de9f", + "content-hash": "8946aa35e29d29bbfbb2157eeb4db359", "packages": [ { "name": "aws/aws-crt-php", @@ -8682,16 +8682,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.0", + "version": "1.12.10", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "384af967d35b2162f69526c7276acadce534d0e1" + "reference": "fc463b5d0fe906dcf19689be692c65c50406a071" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/384af967d35b2162f69526c7276acadce534d0e1", - "reference": "384af967d35b2162f69526c7276acadce534d0e1", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/fc463b5d0fe906dcf19689be692c65c50406a071", + "reference": "fc463b5d0fe906dcf19689be692c65c50406a071", "shasum": "" }, "require": { @@ -8736,25 +8736,25 @@ "type": "github" } ], - "time": "2024-08-27T09:18:05+00:00" + "time": "2024-11-11T15:37:09+00:00" }, { "name": "phpstan/phpstan-doctrine", - "version": "1.5.3", + "version": "1.5.6", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-doctrine.git", - "reference": "38db3bad8f1567d7bf64806738d724261f8a2b5c" + "reference": "8ba022846e79238872e315fff61e19b42ba2f139" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/38db3bad8f1567d7bf64806738d724261f8a2b5c", - "reference": "38db3bad8f1567d7bf64806738d724261f8a2b5c", + "url": "https://api.github.com/repos/phpstan/phpstan-doctrine/zipball/8ba022846e79238872e315fff61e19b42ba2f139", + "reference": "8ba022846e79238872e315fff61e19b42ba2f139", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.11.7" + "phpstan/phpstan": "^1.12.6" }, "conflict": { "doctrine/collections": "<1.0", @@ -8781,7 +8781,7 @@ "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/phpstan-phpunit": "^1.3.13", "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.6.16", + "phpunit/phpunit": "^9.6.20", "ramsey/uuid": "^4.2", "symfony/cache": "^5.4" }, @@ -8806,27 +8806,27 @@ "description": "Doctrine extensions for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-doctrine/issues", - "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.3" + "source": "https://github.com/phpstan/phpstan-doctrine/tree/1.5.6" }, - "time": "2024-09-01T13:17:34+00:00" + "time": "2024-11-09T17:34:01+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.0", + "version": "1.4.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "f3ea021866f4263f07ca3636bf22c64be9610c11" + "reference": "11d4235fbc6313ecbf93708606edfd3222e44949" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/f3ea021866f4263f07ca3636bf22c64be9610c11", - "reference": "f3ea021866f4263f07ca3636bf22c64be9610c11", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/11d4235fbc6313ecbf93708606edfd3222e44949", + "reference": "11d4235fbc6313ecbf93708606edfd3222e44949", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.11" + "phpstan/phpstan": "^1.12" }, "conflict": { "phpunit/phpunit": "<7.0" @@ -8858,22 +8858,22 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.0" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.1" }, - "time": "2024-04-20T06:39:00+00:00" + "time": "2024-11-12T12:43:59+00:00" }, { "name": "phpstan/phpstan-symfony", - "version": "1.4.11", + "version": "1.4.12", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-symfony.git", - "reference": "270c2ee1478d1f8dc5121f539e890017bd64b04c" + "reference": "c7b7e7f520893621558bfbfdb2694d4364565c1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/270c2ee1478d1f8dc5121f539e890017bd64b04c", - "reference": "270c2ee1478d1f8dc5121f539e890017bd64b04c", + "url": "https://api.github.com/repos/phpstan/phpstan-symfony/zipball/c7b7e7f520893621558bfbfdb2694d4364565c1d", + "reference": "c7b7e7f520893621558bfbfdb2694d4364565c1d", "shasum": "" }, "require": { @@ -8930,9 +8930,9 @@ "description": "Symfony Framework extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-symfony/issues", - "source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.11" + "source": "https://github.com/phpstan/phpstan-symfony/tree/1.4.12" }, - "time": "2024-10-30T12:07:21+00:00" + "time": "2024-11-06T10:13:18+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/engine/Shopware/Bundle/MailBundle/AutocompleteResolver/ShortForeachResolver.php b/engine/Shopware/Bundle/MailBundle/AutocompleteResolver/ShortForeachResolver.php index 0c909bf1621..7ada589c442 100644 --- a/engine/Shopware/Bundle/MailBundle/AutocompleteResolver/ShortForeachResolver.php +++ b/engine/Shopware/Bundle/MailBundle/AutocompleteResolver/ShortForeachResolver.php @@ -1,4 +1,7 @@ getValueFromPath($context, $match['arrayName']); if ($value === null) { @@ -46,14 +45,10 @@ public function completer(array $context, string $smartyCode): array if (\count($value)) { $key = array_keys($value)[0]; $context[$match['value']] = $value[$key]; - if (isset($match['key'])) { - $context[$match['key']] = $key; - } + $context[$match['key']] = $key; } else { $context[$match['value']] = []; - if (isset($match['key'])) { - $context[$match['key']] = 0; - } + $context[$match['key']] = 0; } } } diff --git a/engine/Shopware/Commands/FirstRunWizardDisableCommand.php b/engine/Shopware/Commands/FirstRunWizardDisableCommand.php index e2342ec711e..03060b8215a 100644 --- a/engine/Shopware/Commands/FirstRunWizardDisableCommand.php +++ b/engine/Shopware/Commands/FirstRunWizardDisableCommand.php @@ -1,4 +1,7 @@ container->get(\Doctrine\DBAL\Connection::class); - $elementId = $conn->fetchColumn('SELECT id FROM s_core_config_elements WHERE name LIKE "firstRunWizardEnabled"'); - $valueid = $conn->fetchColumn('SELECT id FROM s_core_config_values WHERE element_id = :elementId', ['elementId' => $elementId]); + $conn = $this->container->get(Connection::class); + $elementId = (int) $conn->fetchOne('SELECT id FROM s_core_config_elements WHERE name LIKE "firstRunWizardEnabled"'); + $valueId = (int) $conn->fetchOne('SELECT id FROM s_core_config_values WHERE element_id = :elementId', ['elementId' => $elementId]); $data = [ 'element_id' => $elementId, @@ -54,18 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output) 'value' => serialize(false), ]; - if ($valueid) { + if ($valueId) { $conn->update( 's_core_config_values', $data, - ['id' => $valueid] + ['id' => $valueId] ); } else { $conn->insert('s_core_config_values', $data); } - /** @var \Shopware\Components\CacheManager $cacheManager */ - $cacheManager = $this->container->get(\Shopware\Components\CacheManager::class); + $cacheManager = $this->container->get(CacheManager::class); $cacheManager->clearConfigCache(); $output->writeln('First Run Wizard disabled'); diff --git a/engine/Shopware/Commands/FirstRunWizardEnableCommand.php b/engine/Shopware/Commands/FirstRunWizardEnableCommand.php index 4a35ce47ebc..ee96fd0d47f 100644 --- a/engine/Shopware/Commands/FirstRunWizardEnableCommand.php +++ b/engine/Shopware/Commands/FirstRunWizardEnableCommand.php @@ -1,4 +1,7 @@ container->get(\Doctrine\DBAL\Connection::class); - $elementId = $conn->fetchColumn('SELECT id FROM s_core_config_elements WHERE name LIKE "firstRunWizardEnabled"'); - $valueid = $conn->fetchColumn('SELECT id FROM s_core_config_values WHERE element_id = :elementId', ['elementId' => $elementId]); + $conn = $this->container->get(Connection::class); + $elementId = (int) $conn->fetchOne('SELECT id FROM s_core_config_elements WHERE name LIKE "firstRunWizardEnabled"'); + $valueId = (int) $conn->fetchOne('SELECT id FROM s_core_config_values WHERE element_id = :elementId', ['elementId' => $elementId]); $data = [ 'element_id' => $elementId, @@ -54,18 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output) 'value' => serialize(true), ]; - if ($valueid) { + if ($valueId) { $conn->update( 's_core_config_values', $data, - ['id' => $valueid] + ['id' => $valueId] ); } else { $conn->insert('s_core_config_values', $data); } - /** @var \Shopware\Components\CacheManager $cacheManager */ - $cacheManager = $this->container->get(\Shopware\Components\CacheManager::class); + $cacheManager = $this->container->get(CacheManager::class); $cacheManager->clearConfigCache(); $output->writeln('First Run Wizard enabled'); diff --git a/engine/Shopware/Components/AddLinkHeaderSubscriber.php b/engine/Shopware/Components/AddLinkHeaderSubscriber.php index 41d4c7c4085..e15625308a0 100644 --- a/engine/Shopware/Components/AddLinkHeaderSubscriber.php +++ b/engine/Shopware/Components/AddLinkHeaderSubscriber.php @@ -1,4 +1,7 @@ get('request'); + if (!$request instanceof Enlight_Controller_Request_Request) { + return; + } // Only use Server Push if it is enabled in the settings and the current module is "frontend" if (!$this->pushEnabled @@ -79,20 +73,13 @@ public function onDispatchLoopShutdown(Enlight_Event_EventArgs $args): void return; } - /** @var Enlight_Controller_Response_Response $response */ $response = $args->get('response'); - - $linkProvider = $this->webLinkManager->getLinkProvider(); - if (!$linkProvider instanceof LinkProviderInterface) { - return; - } - - $links = $linkProvider->getLinks(); - if (is_countable($links) && \count($links) === 0) { + if (!$response instanceof Response) { return; } - if ($links instanceof Traversable && iterator_count($links) === 0) { + $links = $this->webLinkManager->getLinkProvider()->getLinks(); + if (empty($links)) { return; } diff --git a/engine/Shopware/Components/Cart/ConditionalLineItemService.php b/engine/Shopware/Components/Cart/ConditionalLineItemService.php index 8d9212415a3..ef05333fffc 100644 --- a/engine/Shopware/Components/Cart/ConditionalLineItemService.php +++ b/engine/Shopware/Components/Cart/ConditionalLineItemService.php @@ -31,33 +31,22 @@ class ConditionalLineItemService implements ConditionalLineItemServiceInterface { - /** - * @var System - */ - private $system; + private System $system; - /** - * @var Session - */ - private $session; + private Session $session; - /** - * @var Config - */ - private $config; + private Config $config; - /** - * @var BasketHelperInterface - */ - private $basketHelper; + private BasketHelperInterface $basketHelper; - /** - * @var Connection - */ - private $connection; + private Connection $connection; public function __construct( - System $sSystem, Session $session, Config $config, BasketHelperInterface $basketHelper, Connection $connection + System $sSystem, + Session $session, + Config $config, + BasketHelperInterface $basketHelper, + Connection $connection ) { $this->system = $sSystem; $this->session = $session; @@ -68,9 +57,9 @@ public function __construct( public function addConditionalLineItem(string $name, string $orderNumber, float $price, float $tax, int $mode): void { - $currencyFactor = empty($this->system->sCurrency['factor']) ? 1 : $this->system->sCurrency['factor']; + $currencyFactor = (float) (empty($this->system->sCurrency['factor']) ? 1 : $this->system->sCurrency['factor']); $taxFree = empty($this->system->sUSERGROUPDATA['tax']) && !empty($this->system->sUSERGROUPDATA['id']); - $sessionId = $this->session->get('sessionId'); + $sessionId = (string) $this->session->get('sessionId'); if ($taxFree) { $netPrice = $price; @@ -109,7 +98,7 @@ public function addConditionalLineItem(string $name, string $orderNumber, float ] ); - $this->connection->insert('s_order_basket_attributes', ['basketID' => $this->connection->lastInsertId()]); + $this->connection->insert('s_order_basket_attributes', ['basketID' => (int) $this->connection->lastInsertId()]); } } } diff --git a/engine/Shopware/Components/Plugin/CronjobSynchronizer.php b/engine/Shopware/Components/Plugin/CronjobSynchronizer.php index f5fff249b95..b8ba5b2b3e6 100644 --- a/engine/Shopware/Components/Plugin/CronjobSynchronizer.php +++ b/engine/Shopware/Components/Plugin/CronjobSynchronizer.php @@ -1,4 +1,7 @@ > $cronjobs + * * @throws InvalidArgumentException + * + * @return void */ public function synchronize(Plugin $plugin, array $cronjobs) { @@ -53,9 +57,9 @@ public function synchronize(Plugin $plugin, array $cronjobs) } /** - * @param array $cronjob + * @param array $cronjob */ - private function addCronjob(Plugin $plugin, $cronjob) + private function addCronjob(Plugin $plugin, array $cronjob): void { $cronjob['pluginID'] = $plugin->getId(); @@ -72,16 +76,16 @@ private function addCronjob(Plugin $plugin, $cronjob) $plugin->getId(), ]; - $id = $this->connection->fetchColumn($selectStatement, $params); + $id = (int) $this->connection->fetchOne($selectStatement, $params); /* * Check if this cronjob's action is named without a preceding 'Shopware_CronJob_', * which is valid but after first run, every cronjob gets prefixed with that, so we might not have gotten * the id because we were asking for the wrong action. */ - if (!$id && strpos($action, 'Shopware_CronJob_') !== 0) { + if (!$id && !str_starts_with($action, 'Shopware_CronJob_')) { $params[0] = 'Shopware_CronJob_' . $action; - $id = $this->connection->fetchColumn($selectStatement, $params); + $id = (int) $this->connection->fetchOne($selectStatement, $params); } if ($id) { @@ -97,9 +101,9 @@ private function addCronjob(Plugin $plugin, $cronjob) } /** - * @param int $pluginId + * @param list $cronjobActions */ - private function removeNotExistingEntries($pluginId, array $cronjobActions) + private function removeNotExistingEntries(int $pluginId, array $cronjobActions): void { $builder = $this->connection->createQueryBuilder(); $builder->delete('s_crontab'); diff --git a/engine/Shopware/Controllers/Frontend/Forms.php b/engine/Shopware/Controllers/Frontend/Forms.php index de339b9ad1f..bc317bb1894 100644 --- a/engine/Shopware/Controllers/Frontend/Forms.php +++ b/engine/Shopware/Controllers/Frontend/Forms.php @@ -636,7 +636,7 @@ protected function _validateInput(array $inputs, array $elements) $valid = false; break; } - $host = trim(substr($value, strpos($value, '@') + 1)); + $host = trim(substr($value, strpos($value, '@') + 1) ?: ''); if (empty($host) || !gethostbyname($host)) { unset($value); $valid = false; diff --git a/engine/Shopware/Plugins/Default/Backend/SwagUpdate/Controllers/Backend/SwagUpdate.php b/engine/Shopware/Plugins/Default/Backend/SwagUpdate/Controllers/Backend/SwagUpdate.php index 0b8cd0321d3..c302dca602f 100644 --- a/engine/Shopware/Plugins/Default/Backend/SwagUpdate/Controllers/Backend/SwagUpdate.php +++ b/engine/Shopware/Plugins/Default/Backend/SwagUpdate/Controllers/Backend/SwagUpdate.php @@ -446,9 +446,7 @@ private function createDestinationFromVersion(Version $version): string */ private function mapResult($result): array { - $mapper = new ExtJsResultMapper(); - - return $mapper->toExtJs($result); + return (new ExtJsResultMapper())->toExtJs($result); } private function getUserLanguage(stdClass $user): string @@ -456,7 +454,7 @@ private function getUserLanguage(stdClass $user): string $locale = $user->locale; $locale = strtolower($locale->getLocale()); - return substr($locale, 0, 2); + return substr($locale, 0, 2) ?: 'en'; } private function checkSecurityPlugin(): bool diff --git a/tests/Functional/Bundle/StoreFrontBundle/ListProductTest.php b/tests/Functional/Bundle/StoreFrontBundle/ListProductTest.php index 1f7930888a8..835f7c0e2d9 100644 --- a/tests/Functional/Bundle/StoreFrontBundle/ListProductTest.php +++ b/tests/Functional/Bundle/StoreFrontBundle/ListProductTest.php @@ -57,9 +57,7 @@ public function testProductRequirements(): void static::assertNotEmpty($product->getVariantId()); static::assertNotEmpty($product->getName()); static::assertNotEmpty($product->getNumber()); - static::assertNotEmpty($product->getManufacturer()); static::assertNotEmpty($product->getTax()); - static::assertNotEmpty($product->getUnit()); static::assertInstanceOf(Unit::class, $product->getUnit()); static::assertInstanceOf(Manufacturer::class, $product->getManufacturer()); @@ -67,14 +65,11 @@ public function testProductRequirements(): void static::assertNotEmpty($product->getPrices()); static::assertNotEmpty($product->getPriceRules()); foreach ($product->getPrices() as $price) { - static::assertInstanceOf(Price::class, $price); static::assertInstanceOf(Unit::class, $price->getUnit()); static::assertGreaterThanOrEqual(1, $price->getUnit()->getMinPurchase()); } - foreach ($product->getPriceRules() as $price) { - static::assertInstanceOf(PriceRule::class, $price); - } + static::assertCount(3, $product->getPriceRules()); static::assertInstanceOf(Price::class, $product->getCheapestPrice()); static::assertInstanceOf(PriceRule::class, $product->getCheapestPriceRule()); diff --git a/tests/Functional/Components/Privacy/CookieRemoveSubscriberTest.php b/tests/Functional/Components/Privacy/CookieRemoveSubscriberTest.php index 9615290f9a1..813c82bf4c5 100644 --- a/tests/Functional/Components/Privacy/CookieRemoveSubscriberTest.php +++ b/tests/Functional/Components/Privacy/CookieRemoveSubscriberTest.php @@ -61,7 +61,7 @@ public function testPostDispatchDoesNothingRemovalInactive(): void $cookieRemoveSubscriber->onPostDispatch($this->getEventArgs($controller)); // More code than allowed got executed if this fails - static::assertNotEmpty($controller->Response()->getCookies()); + static::assertCount(2, $controller->Response()->getCookies()); } public function testPostDispatchDoesNothingAllowAllModeCookieSet(): void diff --git a/tests/Unit/Bundle/SitemapBundle/SitemapListenerTest.php b/tests/Unit/Bundle/SitemapBundle/SitemapListenerTest.php index 88c08155fc8..d17607f2c8d 100644 --- a/tests/Unit/Bundle/SitemapBundle/SitemapListenerTest.php +++ b/tests/Unit/Bundle/SitemapBundle/SitemapListenerTest.php @@ -30,7 +30,6 @@ use Shopware\Bundle\MediaBundle\Adapters\LocalAdapterFactory; use Shopware\Bundle\SitemapBundle\Service\SitemapLister; use Shopware\Bundle\SitemapBundle\Service\SitemapNameGenerator; -use Shopware\Bundle\SitemapBundle\Struct\Sitemap; use Shopware\Components\DependencyInjection\Container; use Shopware\Components\Filesystem\PublicUrlGenerator; @@ -78,7 +77,7 @@ public function testListWithSitemap(): void $sitemaps = $this->listener->getSitemaps(1); static::assertNotEmpty($sitemaps); - static::assertInstanceOf(Sitemap::class, $sitemaps[0]); + static::assertStringStartsWith('foo/', $sitemaps[0]->getFilename()); // Subshop specific sitemaps static::assertEmpty($this->listener->getSitemaps(2));