diff --git a/composer.json b/composer.json index ad2f2c680..6e9c121a2 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "jasny/twig-extensions": "^1.3", "knplabs/doctrine-behaviors": "^2.1", "knplabs/knp-menu-bundle": "^3.1", - "league/glide-symfony": "^1.0", + "league/glide-symfony": "^1.0.4", "miljar/php-exif": "^0.6.4", "nelexa/zip": "^3.3 || ^4.0", "nelmio/cors-bundle": "^2.1", @@ -103,9 +103,9 @@ "php-translation/loco-adapter": "^0.11", "phpspec/phpspec": "^6.3.1", "phpspec/prophecy": "^1.14", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-doctrine": "^0.12", - "phpstan/phpstan-symfony": "^0.12", + "phpstan/phpstan": "^1.2.0", + "phpstan/phpstan-doctrine": "^1.0", + "phpstan/phpstan-symfony": "^1.0.1", "phpunit/phpunit": "^8.5", "se/selenium-server-standalone": "^3.141", "symfony/browser-kit": "^5.3", diff --git a/phpstan.neon b/phpstan.neon index d40e0dbc7..0d9048055 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -33,13 +33,13 @@ parameters: # false positive: An item to the Logger's Record added by us isn't recognized - - message: "#Offset 'location' does not exist on array#" + message: "#Offset '.*' ([a-z ]*)on array#" path: %currentWorkingDirectory%/src/Log/LogHandler.php - # false positive: UserPasswordHasherInterface::isPasswordValid() given UserInterface + # False positive: `id` on Entities - - message: '#UserPasswordHasherInterface::isPasswordValid\(\)#' - path: %currentWorkingDirectory%/src/Security/LoginFormAuthenticator.php + message: '#Property Bolt\\Entity\\(.*)::\$id is never written, only read#' + path: %currentWorkingDirectory%/src/Entity/* includes: - vendor/phpstan/phpstan-symfony/extension.neon diff --git a/src/Api/Extensions/ContentExtension.php b/src/Api/Extensions/ContentExtension.php index 31b168666..abb51291b 100644 --- a/src/Api/Extensions/ContentExtension.php +++ b/src/Api/Extensions/ContentExtension.php @@ -69,7 +69,7 @@ private function filterUnpublishedViewlessContent(QueryBuilder $queryBuilder): v $queryBuilder->setParameter('status', Statuses::PUBLISHED); //todo: Fix this when https://github.com/doctrine/orm/issues/3835 closed. - if (! empty($this->viewlessContentTypes)) { + if ($this->viewlessContentTypes->isNotEmpty()) { $queryBuilder->andWhere(sprintf('%s.contentType NOT IN (:cts)', $rootAlias)); $queryBuilder->setParameter('cts', $this->viewlessContentTypes); } @@ -82,7 +82,7 @@ private function filterUnpublishedViewlessFields(QueryBuilder $queryBuilder): vo $queryBuilder->setParameter('status', Statuses::PUBLISHED); //todo: Fix this when https://github.com/doctrine/orm/issues/3835 closed. - if (! empty($this->viewlessContentTypes)) { + if ($this->viewlessContentTypes->isNotEmpty()) { $queryBuilder->andWhere('c.contentType NOT IN (:cts)'); $queryBuilder->setParameter('cts', $this->viewlessContentTypes); } diff --git a/src/Cache/CachingTrait.php b/src/Cache/CachingTrait.php index 45bdb7cf2..95f515118 100644 --- a/src/Cache/CachingTrait.php +++ b/src/Cache/CachingTrait.php @@ -48,7 +48,7 @@ public function setCacheKey(array $tokens): void public function getCacheKey(): string { - return $this->cacheKey ?? ''; + return $this->cacheKey; } public function setCacheTags(array $tags): void diff --git a/src/Command/CopyAssetsCommand.php b/src/Command/CopyAssetsCommand.php index 364f31fc3..ddfefe225 100644 --- a/src/Command/CopyAssetsCommand.php +++ b/src/Command/CopyAssetsCommand.php @@ -77,7 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int try { $this->filesystem->remove($targetDir); $this->hardCopy($originDir, $targetDir); - $rows[] = [sprintf('%s', "\xE2\x9C\x94"), $message, 'copied']; } catch (\Throwable $e) { $exitCode = 1; @@ -85,14 +84,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - if (! empty($rows)) { - $io->table(['', 'Folder', 'Method / Error'], $rows); - } + $io->table(['', 'Folder', 'Method / Error'], $rows); if ($exitCode !== 0) { $io->error('Some errors occurred while installing assets.'); } else { - $io->success(! empty($rows) ? 'All assets were successfully installed.' : 'No assets were provided by any bundle.'); + $io->success('All assets were successfully installed.'); } return $exitCode; diff --git a/src/Configuration/Content/FieldType.php b/src/Configuration/Content/FieldType.php index f543ee3ba..f8b856152 100644 --- a/src/Configuration/Content/FieldType.php +++ b/src/Configuration/Content/FieldType.php @@ -22,7 +22,7 @@ public function __construct($items, ?string $slug = null) ); } - private static function defaults(): Collection + protected static function defaults(): Collection { return new Collection([ 'slug' => '', diff --git a/src/DataFixtures/ContentFixtures.php b/src/DataFixtures/ContentFixtures.php index e5eff73e5..f05936640 100644 --- a/src/DataFixtures/ContentFixtures.php +++ b/src/DataFixtures/ContentFixtures.php @@ -247,7 +247,7 @@ function ($match) { try { return $this->faker->{$match}; - } catch (\Throwable $e) { + } finally { } return '(unknown)'; diff --git a/src/Doctrine/TablePrefixTrait.php b/src/Doctrine/TablePrefixTrait.php index d4966a75a..ae49fb4c2 100644 --- a/src/Doctrine/TablePrefixTrait.php +++ b/src/Doctrine/TablePrefixTrait.php @@ -54,6 +54,6 @@ protected function setTablePrefixes($tablePrefixes, ManagerRegistry $managerRegi */ protected function getTablePrefix(): string { - return current($this->tablePrefixes) ?? ''; + return current($this->tablePrefixes); } } diff --git a/src/Entity/Content.php b/src/Entity/Content.php index 5ed36877d..d775d77eb 100644 --- a/src/Entity/Content.php +++ b/src/Entity/Content.php @@ -246,7 +246,6 @@ public function getSlug($locale = null): ?string return (string) $this->getId(); } - $slug = null; if ($locale === null) { // get slug with locale the slug already has $slug = $this->getFieldValue('slug'); @@ -263,7 +262,7 @@ public function getSlug($locale = null): ?string } // if no slug exists for the current/requested locale, default fallback - if (! $slug && $this->hasField('slug')) { + if ($slug === '') { $field = $this->getField('slug'); // @todo: Refactor this. Field.php should be able to get locale diff --git a/src/Entity/Field/CollectionField.php b/src/Entity/Field/CollectionField.php index 7c0ff9e56..ca2a5f6ac 100644 --- a/src/Entity/Field/CollectionField.php +++ b/src/Entity/Field/CollectionField.php @@ -56,7 +56,7 @@ public function getApiValue() } /** - * @var FieldInterface[] + * @param FieldInterface[] $fields */ public function setValue($fields): Field { diff --git a/src/Entity/Relation.php b/src/Entity/Relation.php index 37972790e..668ff733a 100644 --- a/src/Entity/Relation.php +++ b/src/Entity/Relation.php @@ -116,7 +116,7 @@ public function setToContent($content): void public function getDefinition(): array { - if (empty($this->definition) === true && empty($this->fromContent) === false) { + if (empty($this->definition) && $this->fromContent instanceof Content) { $this->setDefinitionFromContentDefinition(); } diff --git a/src/Event/Listener/ContentFillListener.php b/src/Event/Listener/ContentFillListener.php index 1ca872dec..8a5579c9a 100644 --- a/src/Event/Listener/ContentFillListener.php +++ b/src/Event/Listener/ContentFillListener.php @@ -82,7 +82,7 @@ private function guesstimateAuthor(): User return $this->users->getFirstAdminUser(); } - private function guaranteeUniqueSLug(Content $content): void + private function guaranteeUniqueSlug(Content $content): void { $slug = $content->getSlug(); @@ -137,7 +137,7 @@ private function guaranteeUniqueSLug(Content $content): void if (! $safe) { $newSlug = $this->getSafeSlug($slug); $content->setFieldValue('slug', $newSlug); - $this->guaranteeUniqueSLug($content); + $this->guaranteeUniqueSlug($content); } } diff --git a/src/Log/RequestProcessor.php b/src/Log/RequestProcessor.php index 2b2e55df8..fd1e38b41 100644 --- a/src/Log/RequestProcessor.php +++ b/src/Log/RequestProcessor.php @@ -47,7 +47,7 @@ public function processRecord(array $record): array ]; } - if (! empty($user)) { + if ($user instanceof User) { $record['user'] = [ 'id' => $user->getId(), 'username' => $user->getUsername(), diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index 5870a8ef9..71c5aa7ce 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -111,11 +111,11 @@ public function getUser($credentials, UserProviderInterface $userProvider): ?Use return $this->userRepository->findOneByCredentials($credentials['username']); } - /** - * @var PasswordAuthenticatedUserInterface $user - */ public function checkCredentials($credentials, UserInterface $user): bool { + /** + * @var PasswordAuthenticatedUserInterface $user + */ return empty($credentials['password']) ? false : $this->passwordHasher->isPasswordValid($user, $credentials['password']); } diff --git a/src/Security/LogoutListener.php b/src/Security/LogoutListener.php index 24f384a2c..de488d813 100644 --- a/src/Security/LogoutListener.php +++ b/src/Security/LogoutListener.php @@ -18,15 +18,11 @@ class LogoutListener implements LogoutHandlerInterface { use LoggerTrait; - /** @var EntityManagerInterface */ - private $em; - /** @var SessionInterface */ private $session; - public function __construct(EntityManagerInterface $em, SessionInterface $session) + public function __construct(SessionInterface $session) { - $this->em = $em; $this->session = $session; } diff --git a/src/Twig/FieldExtension.php b/src/Twig/FieldExtension.php index 80a59a706..60ea08483 100644 --- a/src/Twig/FieldExtension.php +++ b/src/Twig/FieldExtension.php @@ -109,7 +109,7 @@ public function getLabel(Field $field): string public function getType(Field $field): string { - return $field->getType() ?? $field->getDefinition()->get('type'); + return $field->getType(); } /** @@ -119,7 +119,7 @@ public function getSelected(Field\SelectField $field, $returnsingle = false, $re { $definition = $field->getDefinition(); - if ($definition->get('type') !== 'select' || ! $field->isContentSelect() || ($field->isContentSelect() && $definition->get('mode') === 'format')) { + if ($definition->get('type') !== 'select' || ! $field->isContentSelect() || $definition->get('mode') === 'format') { return $this->notifications->warning( 'Incorrect usage of `selected`-filter', 'The `selected`-filter can only be applied to a field of `type: select`, and it must be used as a selector for other content, and without `mode: format`.' diff --git a/src/Twig/RelatedExtension.php b/src/Twig/RelatedExtension.php index f267e2ddd..17ffafa41 100644 --- a/src/Twig/RelatedExtension.php +++ b/src/Twig/RelatedExtension.php @@ -8,8 +8,6 @@ use Bolt\Entity\Content; use Bolt\Entity\Relation; use Bolt\Repository\RelationRepository; -use Bolt\Storage\Query; -use Bolt\Utils\ContentHelper; use Bolt\Utils\RelatedOptionsUtility; use Tightenco\Collect\Support\Collection; use Twig\Extension\AbstractExtension; @@ -24,12 +22,6 @@ class RelatedExtension extends AbstractExtension /** @var Config */ private $config; - /** @var Query */ - private $query; - - /** @var ContentHelper */ - private $contentHelper; - /** @var Notifications */ private $notifications; @@ -39,15 +31,11 @@ class RelatedExtension extends AbstractExtension public function __construct( RelationRepository $relationRepository, Config $config, - Query $query, - ContentHelper $contentHelper, Notifications $notifications, RelatedOptionsUtility $optionsUtility) { $this->relationRepository = $relationRepository; $this->config = $config; - $this->query = $query; - $this->contentHelper = $contentHelper; $this->notifications = $notifications; $this->optionsUtility = $optionsUtility; } diff --git a/src/Twig/TextExtension.php b/src/Twig/TextExtension.php index 1f2df8389..830307831 100644 --- a/src/Twig/TextExtension.php +++ b/src/Twig/TextExtension.php @@ -97,9 +97,7 @@ public function urlDecode(string $string) foreach (explode('&', $string) as $chunk) { $param = explode('=', $chunk); - if (! empty($param)) { - $params[urldecode($param[0])] = urldecode($param[1]); - } + $params[urldecode($param[0])] = urldecode($param[1]); } return $params; diff --git a/src/Utils/Excerpt.php b/src/Utils/Excerpt.php index 3d9d9061a..51dc71806 100644 --- a/src/Utils/Excerpt.php +++ b/src/Utils/Excerpt.php @@ -24,7 +24,7 @@ public static function getExcerpt(string $text, int $length = 200, $focus = null * Nothing exciting here. The array_unique is required, unless you decide * to make the words unique before passing in. */ - private static function extractLocations(array $words, string $fulltext): array + protected static function extractLocations(array $words, string $fulltext): array { $locations = []; foreach ($words as $word) { @@ -49,7 +49,7 @@ private static function extractLocations(array $words, string $fulltext): array * The only exception is where we have only two matches in which case we just take the * first as will be equally distant. */ - private static function determineSnipLocation(array $locations, int $prevCount): int + protected static function determineSnipLocation(array $locations, int $prevCount): int { // If we only have 1 match we don't actually do the for loop so set to the first $startPos = (int) reset($locations); @@ -84,7 +84,7 @@ private static function determineSnipLocation(array $locations, int $prevCount): * * @param string|array $words */ - private static function extractRelevant($words, string $fulltext, int $relLength = 300): string + protected static function extractRelevant($words, string $fulltext, int $relLength = 300): string { $fulltext = strip_tags($fulltext); diff --git a/src/Utils/LocaleHelper.php b/src/Utils/LocaleHelper.php index 32d069aed..654d09a76 100644 --- a/src/Utils/LocaleHelper.php +++ b/src/Utils/LocaleHelper.php @@ -56,7 +56,7 @@ public function getCurrentLocale(Environment $twig): ?Collection { // Getting the currentLocale is surprisingly inefficient, so we do it once per Request // See https://github.com/bolt/core/pull/2597 - if (! isset($this->currentLocale)) { + if (! $this->currentLocale instanceof Collection) { $this->currentLocale = $this->getLocales($twig)->firstWhere('current', true); } diff --git a/src/Utils/MomentFormatConverter.php b/src/Utils/MomentFormatConverter.php index 7336b1fc4..1a6f0dbba 100644 --- a/src/Utils/MomentFormatConverter.php +++ b/src/Utils/MomentFormatConverter.php @@ -18,7 +18,7 @@ class MomentFormatConverter * * @var array */ - private static $formatConvertRules = [ + protected static $formatConvertRules = [ // year 'yyyy' => 'YYYY', 'yy' => 'YY', diff --git a/src/Widget/BaseWidget.php b/src/Widget/BaseWidget.php index acd9303c7..7d87a6df6 100644 --- a/src/Widget/BaseWidget.php +++ b/src/Widget/BaseWidget.php @@ -82,7 +82,7 @@ public function getTargets(): array } /** - * @var string[] + * @param string[] $targets */ public function setTargets(array $targets): WidgetInterface { diff --git a/src/Widget/Injector/HtmlInjector.php b/src/Widget/Injector/HtmlInjector.php index 6c7201246..a5ca00766 100644 --- a/src/Widget/Injector/HtmlInjector.php +++ b/src/Widget/Injector/HtmlInjector.php @@ -80,7 +80,7 @@ public function inject(WidgetInterface $widget, Response $response): void $snippet = $widget() . "\n"; // If the widget doesn't produce output, there's no need to inject it. - if (empty($snippet)) { + if (mb_strlen($snippet) === 0) { return; } @@ -240,7 +240,7 @@ protected function jsTagsAfter(string $snippet, string $rawHtml): string return $result; } - private static function findTagStart(string $rawHtml, string $htmlTag): ?string + protected static function findTagStart(string $rawHtml, string $htmlTag): ?string { preg_match('~(<' . $htmlTag . '[^>]*?>)~mi', $rawHtml, $matches); @@ -251,7 +251,7 @@ private static function findTagStart(string $rawHtml, string $htmlTag): ?string return $matches[1]; } - private static function findTagEnd(string $rawHtml, string $htmlTag): ?string + protected static function findTagEnd(string $rawHtml, string $htmlTag): ?string { preg_match_all('~((<' . $htmlTag . '(\s[^>]*)?>)|())~mi', $rawHtml, $allMatches); diff --git a/src/Widget/Injector/RequestZone.php b/src/Widget/Injector/RequestZone.php index 858c8e656..c3a932144 100644 --- a/src/Widget/Injector/RequestZone.php +++ b/src/Widget/Injector/RequestZone.php @@ -12,7 +12,7 @@ */ class RequestZone { - private const KEY = 'zone'; + protected const KEY = 'zone'; public const FRONTEND = 'frontend'; public const BACKEND = 'backend';