diff --git a/.phpstan-baseline.neon b/.phpstan-baseline.neon index 2a5abc566c1..5a3f5be69ae 100644 --- a/.phpstan-baseline.neon +++ b/.phpstan-baseline.neon @@ -1380,41 +1380,11 @@ parameters: count: 1 path: engine/Library/Enlight/Components/Auth/Adapter/DbTable.php - - - message: "#^Method Enlight_Components_Cron_Adapter\\:\\:startJob\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter.php - - message: "#^Argument \\#0 expects a constant string, got string$#" count: 4 path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - - message: "#^Method Enlight_Components_Cron_Adapter_DBAL\\:\\:isJobStillOverdue\\(\\) has parameter \\$jobId with no type specified\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - - - message: "#^Method Enlight_Components_Cron_Adapter_DBAL\\:\\:startJob\\(\\) has no return type specified\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - - - message: "#^Method Enlight_Components_Cron_Adapter_DBAL\\:\\:updateJob\\(\\) should return Enlight_Components_Cron_Manager but return statement is missing\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - - - message: "#^Negated boolean expression is always false\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - - - message: "#^Parameter \\#2 \\$value of method Enlight_Components_Cron_Adapter_DBAL\\:\\:getJobByColumn\\(\\) expects string, int given\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Adapter/DBAL.php - - message: "#^Method Enlight_Components_Cron_Job\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" count: 1 @@ -1500,11 +1470,6 @@ parameters: count: 1 path: engine/Library/Enlight/Components/Cron/Job.php - - - message: "#^Method Enlight_Components_Cron_Manager\\:\\:disableJob\\(\\) should return Enlight_Components_Cron_Adapter but returns Enlight_Components_Cron_Manager\\.$#" - count: 1 - path: engine/Library/Enlight/Components/Cron/Manager.php - - message: "#^Method Enlight_Components_Cron_Manager\\:\\:endJob\\(\\) has no return type specified\\.$#" count: 1 diff --git a/engine/Library/Enlight/.php-cs-fixer.php b/engine/Library/Enlight/.php-cs-fixer.php index b1884f9327a..e6c560fc12e 100644 --- a/engine/Library/Enlight/.php-cs-fixer.php +++ b/engine/Library/Enlight/.php-cs-fixer.php @@ -18,6 +18,7 @@ */ use PhpCsFixer\Config; +use PhpCsFixer\Runner\Parallel\ParallelConfigFactory; use PhpCsFixerCustomFixers\Fixer\NoSuperfluousConcatenationFixer; use PhpCsFixerCustomFixers\Fixer\NoUselessCommentFixer; use PhpCsFixerCustomFixers\Fixer\NoUselessDirnameCallFixer; @@ -56,6 +57,7 @@ ->registerCustomFixers(new Fixers()) ->setRiskyAllowed(true) ->setCacheFile('var/cache/php-cs-fixer-enlight') + ->setParallelConfig(ParallelConfigFactory::detect()) ->setRules([ '@PSR12' => true, '@Symfony' => true, diff --git a/engine/Library/Enlight/Components/Cron/Adapter.php b/engine/Library/Enlight/Components/Cron/Adapter.php index a7af2fea858..3a984c5d135 100644 --- a/engine/Library/Enlight/Components/Cron/Adapter.php +++ b/engine/Library/Enlight/Components/Cron/Adapter.php @@ -33,16 +33,19 @@ interface Enlight_Components_Cron_Adapter /** * Updates a cron job in the cron tab * - * @return Enlight_Components_Cron_Manager + * @return void */ public function updateJob(Enlight_Components_Cron_Job $job); + /** + * @return bool + */ public function startJob(Enlight_Components_Cron_Job $job); /** * Returns an array of Enlight_Components_Cron_Job from the crontab * - * @return Enlight_Components_Cron_Job[] + * @return array */ public function getAllJobs(); diff --git a/engine/Library/Enlight/Components/Cron/Adapter/DBAL.php b/engine/Library/Enlight/Components/Cron/Adapter/DBAL.php index 819397c7d37..70ea1d77828 100644 --- a/engine/Library/Enlight/Components/Cron/Adapter/DBAL.php +++ b/engine/Library/Enlight/Components/Cron/Adapter/DBAL.php @@ -1,4 +1,6 @@ |null */ - private $allJobsList; + private ?array $allJobsList = null; /** - * @var Enlight_Components_Cron_Job[]|null + * @var array|null */ - private $overdueJobsList; + private ?array $overdueJobsList = null; public function __construct(Connection $connection) { @@ -106,17 +105,12 @@ public function getAllJobs() $qb->select('*') ->from($this->tableName, 'c'); - $ignoreActive = true; - if (!$ignoreActive) { - $qb->andWhere('c.active = true'); - } - - $rows = $qb->execute()->fetchAll(); + $rows = $qb->execute()->fetchAllAssociative(); $jobs = []; foreach ($rows as $row) { $row['data'] = unserialize($row['data'], ['allowed_classes' => false]); - $jobs[$row['id']] = new Enlight_Components_Cron_Job($row); + $jobs[(int) $row['id']] = new Enlight_Components_Cron_Job($row); } return $jobs; @@ -140,7 +134,7 @@ public function getNextJob($force = false) } while (($nextJob = array_pop($this->overdueJobsList)) !== null) { - if ($this->isJobStillOverdue($nextJob->getId())) { + if ($this->isJobStillOverdue((int) $nextJob->getId())) { return $nextJob; } } @@ -194,12 +188,9 @@ public function deleteJob(Enlight_Components_Cron_Job $job) /** * Internal helper method to grep data based on a given column name. * - * @param string $column - * @param string $value - * - * @return Enlight_Components_Cron_Job|null + * @param string|int $value */ - private function getJobByColumn($column, $value) + private function getJobByColumn(string $column, $value): ?Enlight_Components_Cron_Job { $qb = $this->connection->createQueryBuilder(); @@ -222,9 +213,9 @@ private function getJobByColumn($column, $value) } /** - * @return Enlight_Components_Cron_Job[] + * @return array */ - private function getOverdueJobs() + private function getOverdueJobs(): array { $qb = $this->connection->createQueryBuilder(); @@ -241,16 +232,13 @@ private function getOverdueJobs() $overdueJobsList = []; foreach ($rows as $row) { $row['data'] = unserialize($row['data'], ['allowed_classes' => false]); - $overdueJobsList[$row['id']] = new Enlight_Components_Cron_Job($row); + $overdueJobsList[(int) $row['id']] = new Enlight_Components_Cron_Job($row); } return $overdueJobsList; } - /** - * @return bool - */ - private function isJobStillOverdue($jobId) + private function isJobStillOverdue(int $jobId): bool { $qb = $this->connection->createQueryBuilder(); $qb->select('*') diff --git a/engine/Library/Enlight/Components/Cron/Manager.php b/engine/Library/Enlight/Components/Cron/Manager.php index bbe7f336a16..d9568503807 100644 --- a/engine/Library/Enlight/Components/Cron/Manager.php +++ b/engine/Library/Enlight/Components/Cron/Manager.php @@ -104,13 +104,13 @@ public function getEventManager() /** * Deactivate a given Cron Job in the crontab * - * @return Enlight_Components_Cron_Adapter + * @return void */ public function disableJob(Enlight_Components_Cron_Job $job) { $job->setActive(false); - return $this->adapter->updateJob($job); + $this->adapter->updateJob($job); } /** diff --git a/engine/Shopware/Components/Log/Parser/LogfileParser.php b/engine/Shopware/Components/Log/Parser/LogfileParser.php index 956abea3996..6e54ec6eda9 100644 --- a/engine/Shopware/Components/Log/Parser/LogfileParser.php +++ b/engine/Shopware/Components/Log/Parser/LogfileParser.php @@ -29,6 +29,9 @@ use LimitIterator; use SplFileObject; +/** + * @phpstan-type Log array{date?: string, channel?: string, level?: string, message?: string, context?: string, extra?: string, raw: string} + */ class LogfileParser { /** @@ -37,7 +40,7 @@ class LogfileParser * @param int|null $limit * @param bool $reverse * - * @return array + * @return list */ public function parseLogFile($file, $offset = null, $limit = null, $reverse = false) { @@ -78,7 +81,7 @@ public function countLogFile($filePath) } /** - * @return array{data?: string, channel?: string, level?: string, message?: string, context?: string, extra?: string, raw: string} + * @return Log */ private function parseLine(string $log): array { @@ -93,12 +96,12 @@ private function parseLine(string $log): array } return [ - 'date' => (string) $data['date'], - 'channel' => (string) $data['channel'], - 'level' => (string) $data['level'], - 'message' => (string) $data['message'], - 'context' => json_decode($data['context'], true), - 'extra' => json_decode($data['extra'], true), + 'date' => $data['date'], + 'channel' => $data['channel'] ?? '', + 'level' => $data['level'] ?? '', + 'message' => $data['message'] ?? '', + 'context' => json_decode($data['context'] ?? '', true), + 'extra' => json_decode($data['extra'] ?? '', true), 'raw' => $log, ]; }