From cbf41e5e6e2d8a00072c4d5b9884255c381c489e Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Sun, 3 May 2020 14:57:23 +0200 Subject: [PATCH 1/4] Updating some ECS settings --- easy-coding-standard.yml | 6 ++ .../Backend/ExtensionsController.php | 4 +- src/Entity/Field.php | 12 +--- src/Entity/FieldTranslation.php | 4 +- src/Entity/Log.php | 36 +++-------- src/Entity/Media.php | 64 +++++-------------- src/Entity/Relation.php | 8 +-- src/Entity/Taxonomy.php | 8 +-- src/Entity/User.php | 16 ++--- src/Entity/UserAuthToken.php | 12 +--- src/Extension/ExtensionRegistry.php | 4 +- 11 files changed, 50 insertions(+), 124 deletions(-) diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index 6e0ef2655..1dd7b5b2d 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -79,6 +79,8 @@ services: PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer: ~ PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer: ~ PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer: ~ + PhpCsFixer\Fixer\Phpdoc\PhpdocLineSpanFixer: + property: single #please yoda no SlevomatCodingStandard\Sniffs\ControlStructures\DisallowYodaComparisonSniff: ~ @@ -98,3 +100,7 @@ parameters: SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff: ~ Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff: ~ #to be removed before beta release Symplify\CodingStandard\Sniffs\Debug\DebugFunctionCallSniff: ~ #to be removed before beta release + + # Deprecated. Todo: Find replacement + Symplify\CodingStandard\Fixer\ControlStructure\RequireFollowedByAbsolutePathFixer: ~ + Symplify\CodingStandard\Fixer\Property\ArrayPropertyDefaultValueFixer: ~ \ No newline at end of file diff --git a/src/Controller/Backend/ExtensionsController.php b/src/Controller/Backend/ExtensionsController.php index 41deabc54..81536928d 100644 --- a/src/Controller/Backend/ExtensionsController.php +++ b/src/Controller/Backend/ExtensionsController.php @@ -21,9 +21,7 @@ class ExtensionsController extends AbstractController implements BackendZoneInte /** @var ExtensionRegistry */ private $extensionRegistry; - /** - * @var Dependencies - */ + /** @var Dependencies */ private $dependenciesManager; public function __construct(ExtensionRegistry $extensionRegistry) diff --git a/src/Entity/Field.php b/src/Entity/Field.php index efe0dfdc9..40fdf0bca 100644 --- a/src/Entity/Field.php +++ b/src/Entity/Field.php @@ -54,14 +54,10 @@ class Field implements FieldInterface, TranslatableInterface */ public $name; - /** - * @ORM\Column(type="integer") - */ + /** @ORM\Column(type="integer") */ private $sortorder = 0; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $version; /** @@ -76,9 +72,7 @@ class Field implements FieldInterface, TranslatableInterface */ private $parent; - /** - * @var ?FieldType - */ + /** @var ?FieldType */ private $fieldTypeDefinition; public function __toString(): string diff --git a/src/Entity/FieldTranslation.php b/src/Entity/FieldTranslation.php index c8b75c751..dc7aad5e6 100644 --- a/src/Entity/FieldTranslation.php +++ b/src/Entity/FieldTranslation.php @@ -21,9 +21,7 @@ class FieldTranslation implements TranslationInterface */ private $id; - /** - * @ORM\Column(type="json") - */ + /** @ORM\Column(type="json") */ protected $value = []; public function getId(): ?int diff --git a/src/Entity/Log.php b/src/Entity/Log.php index a5ff9f15b..e8957797c 100644 --- a/src/Entity/Log.php +++ b/src/Entity/Log.php @@ -20,49 +20,31 @@ class Log */ private $id; - /** - * @ORM\Column(name="message", type="text") - */ + /** @ORM\Column(name="message", type="text") */ private $message; - /** - * @ORM\Column(name="context", type="array", nullable=true) - */ + /** @ORM\Column(name="context", type="array", nullable=true) */ private $context; - /** - * @ORM\Column(name="level", type="smallint") - */ + /** @ORM\Column(name="level", type="smallint") */ private $level; - /** - * @ORM\Column(name="level_name", type="string", length=50) - */ + /** @ORM\Column(name="level_name", type="string", length=50) */ private $levelName; - /** - * @ORM\Column(name="created_at", type="datetime") - */ + /** @ORM\Column(name="created_at", type="datetime") */ private $createdAt; - /** - * @ORM\Column(name="extra", type="array", nullable=true) - */ + /** @ORM\Column(name="extra", type="array", nullable=true) */ private $extra; - /** - * @ORM\Column(name="user", type="array", nullable=true) - */ + /** @ORM\Column(name="user", type="array", nullable=true) */ private $user; - /** - * @ORM\Column(type="content", type="integer", nullable=true) - */ + /** @ORM\Column(type="content", type="integer", nullable=true) */ private $content; - /** - * @ORM\Column(name="location", type="array", nullable=true) - */ + /** @ORM\Column(name="location", type="array", nullable=true) */ private $location; /** diff --git a/src/Entity/Media.php b/src/Entity/Media.php index a68426632..c7cab03ce 100644 --- a/src/Entity/Media.php +++ b/src/Entity/Media.php @@ -19,54 +19,34 @@ class Media */ private $id; - /** - * @ORM\Column(type="string", length=191) - */ + /** @ORM\Column(type="string", length=191) */ private $location; - /** - * @ORM\Column(type="text", length=1000) - */ + /** @ORM\Column(type="text", length=1000) */ private $path; - /** - * @ORM\Column(type="string", length=191) - */ + /** @ORM\Column(type="string", length=191) */ private $filename; - /** - * @ORM\Column(type="string", length=191) - */ + /** @ORM\Column(type="string", length=191) */ private $type; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $width; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $height; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $filesize; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $cropX; - /** - * @ORM\Column(type="integer", nullable=true) - */ + /** @ORM\Column(type="integer", nullable=true) */ private $cropY; - /** - * @ORM\Column(type="float", nullable=true) - */ + /** @ORM\Column(type="float", nullable=true) */ private $cropZoom; /** @@ -77,34 +57,22 @@ class Media */ private $author; - /** - * @ORM\Column(type="datetime") - */ + /** @ORM\Column(type="datetime") */ private $createdAt; - /** - * @ORM\Column(type="datetime") - */ + /** @ORM\Column(type="datetime") */ private $modifiedAt; - /** - * @ORM\Column(type="string", length=191, nullable=true) - */ + /** @ORM\Column(type="string", length=191, nullable=true) */ private $title; - /** - * @ORM\Column(type="string", length=1000, nullable=true) - */ + /** @ORM\Column(type="string", length=1000, nullable=true) */ private $description; - /** - * @ORM\Column(type="string", length=1000, nullable=true) - */ + /** @ORM\Column(type="string", length=1000, nullable=true) */ private $originalFilename; - /** - * @ORM\Column(type="string", length=191, nullable=true) - */ + /** @ORM\Column(type="string", length=191, nullable=true) */ private $copyright; public function __construct() diff --git a/src/Entity/Relation.php b/src/Entity/Relation.php index fa936a976..84efd9442 100644 --- a/src/Entity/Relation.php +++ b/src/Entity/Relation.php @@ -57,14 +57,10 @@ class Relation */ private $toContent; - /** - * @ORM\Column(type="integer") - */ + /** @ORM\Column(type="integer") */ private $position = 0; - /** - * @ORM\Column(name="`group`", type="string", length=191) - */ + /** @ORM\Column(name="`group`", type="string", length=191) */ private $group; /** diff --git a/src/Entity/Taxonomy.php b/src/Entity/Taxonomy.php index 261c09825..78e9ce91f 100644 --- a/src/Entity/Taxonomy.php +++ b/src/Entity/Taxonomy.php @@ -23,9 +23,7 @@ class Taxonomy */ private $id; - /** - * @ORM\ManyToMany(targetEntity="Bolt\Entity\Content", inversedBy="taxonomies") - */ + /** @ORM\ManyToMany(targetEntity="Bolt\Entity\Content", inversedBy="taxonomies") */ private $content; /** @@ -52,9 +50,7 @@ class Taxonomy */ private $sortorder = 0; - /** - * @var string - */ + /** @var string */ private $link; public function __construct() diff --git a/src/Entity/User.php b/src/Entity/User.php index a24a64a33..2afa517bb 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -86,9 +86,7 @@ class User implements UserInterface, \Serializable */ private $lastseenAt; - /** - * @ORM\Column(type="string", length=100, nullable=true) - */ + /** @ORM\Column(type="string", length=100, nullable=true) */ private $lastIp; /** @@ -97,19 +95,13 @@ class User implements UserInterface, \Serializable */ private $locale; - /** - * @ORM\Column(type="string", length=191, nullable=true) - */ + /** @ORM\Column(type="string", length=191, nullable=true) */ private $backendTheme; - /** - * @ORM\Column(type="boolean", options={"default" : false}, nullable=false) - */ + /** @ORM\Column(type="boolean", options={"default" : false}, nullable=false) */ private $disabled = false; - /** - * @ORM\OneToOne(targetEntity="Bolt\Entity\UserAuthToken", mappedBy="user", cascade={"persist", "remove"}) - */ + /** @ORM\OneToOne(targetEntity="Bolt\Entity\UserAuthToken", mappedBy="user", cascade={"persist", "remove"}) */ private $userAuthToken; public function __construct() diff --git a/src/Entity/UserAuthToken.php b/src/Entity/UserAuthToken.php index cb93b7358..946adea4b 100644 --- a/src/Entity/UserAuthToken.php +++ b/src/Entity/UserAuthToken.php @@ -18,19 +18,13 @@ class UserAuthToken */ private $id; - /** - * @ORM\OneToOne(targetEntity="Bolt\Entity\User", inversedBy="userAuthToken", cascade={"persist"}) - */ + /** @ORM\OneToOne(targetEntity="Bolt\Entity\User", inversedBy="userAuthToken", cascade={"persist"}) */ private $user; - /** - * @ORM\Column(type="string", length=255) - */ + /** @ORM\Column(type="string", length=255) */ private $useragent; - /** - * @ORM\Column(type="datetime") - */ + /** @ORM\Column(type="datetime") */ private $validity; public function getId(): ?int diff --git a/src/Extension/ExtensionRegistry.php b/src/Extension/ExtensionRegistry.php index 4ab66cfeb..31a02209b 100644 --- a/src/Extension/ExtensionRegistry.php +++ b/src/Extension/ExtensionRegistry.php @@ -51,7 +51,9 @@ private function getExtensionClasses(): array return array_unique($this->extensionClasses); } - /** @return ExtensionInterface[] */ + /** + * @return ExtensionInterface[] + */ public function getExtensions(): array { return $this->extensions; From 5dcd29d1737086465655c5a365a0572795e62a7f Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Sun, 3 May 2020 15:00:18 +0200 Subject: [PATCH 2/4] Adding `ConcatSpaceFixer` --- easy-coding-standard.yml | 3 ++- src/Command/CopyAssetsCommand.php | 4 ++-- src/Command/CopyThemesCommand.php | 4 ++-- src/DataFixtures/BaseFixture.php | 2 +- src/Doctrine/TablePrefix.php | 4 ++-- src/Entity/Field/FileExtrasTrait.php | 2 +- src/Factory/MediaFactory.php | 2 +- src/Repository/ContentRepository.php | 4 ++-- src/Security/LoginFormAuthenticator.php | 4 ++-- src/Storage/Directive/OrderDirective.php | 4 ++-- src/Twig/ContentExtension.php | 2 +- src/Widget/BaseWidget.php | 2 +- src/Widget/Injector/HtmlInjector.php | 12 ++++++------ 13 files changed, 25 insertions(+), 24 deletions(-) diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index 1dd7b5b2d..0e887a7b7 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -22,6 +22,8 @@ services: # Spaces Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer: ~ + PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: + spacing: one # Comments Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousDocBlockWhitespaceFixer: ~ @@ -91,7 +93,6 @@ parameters: PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: ~ PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer: ~ PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer: ~ - PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: ~ PhpCsFixer\Fixer\Operator\IncrementStyleFixer: ~ PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer: ~ diff --git a/src/Command/CopyAssetsCommand.php b/src/Command/CopyAssetsCommand.php index 1da74acac..ee4a38d20 100644 --- a/src/Command/CopyAssetsCommand.php +++ b/src/Command/CopyAssetsCommand.php @@ -52,13 +52,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (file_exists(dirname(dirname(dirname(__DIR__))) . '/assets')) { $baseDir = dirname(dirname(dirname(__DIR__))) . '/assets'; $dirs = [ - $baseDir . '/assets' => $publicDir .'/assets/', + $baseDir . '/assets' => $publicDir . '/assets/', // $baseDir . '/translations' => $projectDir . '/translations/', ]; } else { $baseDir = dirname(dirname(__DIR__)); $dirs = [ - $baseDir . '/public/assets' => $publicDir .'/assets/', + $baseDir . '/public/assets' => $publicDir . '/assets/', // $baseDir . '/translations' => $projectDir . '/translations/', ]; } diff --git a/src/Command/CopyThemesCommand.php b/src/Command/CopyThemesCommand.php index 3fccf1877..ce5eb8101 100644 --- a/src/Command/CopyThemesCommand.php +++ b/src/Command/CopyThemesCommand.php @@ -55,8 +55,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int if (file_exists(dirname(dirname(dirname(__DIR__))) . '/themes')) { $baseDir = dirname(dirname(dirname(__DIR__))) . '/themes'; $dirs = [ - $baseDir . '/base-2018' => $publicDir .'/theme/base-2018', - $baseDir . '/skeleton' => $publicDir .'/theme/skeleton', + $baseDir . '/base-2018' => $publicDir . '/theme/base-2018', + $baseDir . '/skeleton' => $publicDir . '/theme/skeleton', ]; } else { if (Version::installType() === 'Git clone') { diff --git a/src/DataFixtures/BaseFixture.php b/src/DataFixtures/BaseFixture.php index d22291e2a..0c4947579 100644 --- a/src/DataFixtures/BaseFixture.php +++ b/src/DataFixtures/BaseFixture.php @@ -29,7 +29,7 @@ protected function getRandomReference(string $entityName) $this->referencesIndex[$entityName] = []; foreach (array_keys($this->referenceRepository->getReferences()) as $key) { - if (mb_strpos($key, $entityName.'_') === 0) { + if (mb_strpos($key, $entityName . '_') === 0) { $this->referencesIndex[$entityName][] = $key; } } diff --git a/src/Doctrine/TablePrefix.php b/src/Doctrine/TablePrefix.php index e3f9d82da..c3cf28b47 100644 --- a/src/Doctrine/TablePrefix.php +++ b/src/Doctrine/TablePrefix.php @@ -26,7 +26,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void || $classMetadata->getName() === $classMetadata->rootEntityName) { $classMetadata->setPrimaryTable( [ - 'name' => $tablePrefix.$classMetadata->getTableName(), + 'name' => $tablePrefix . $classMetadata->getTableName(), ] ); } @@ -34,7 +34,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) { $mappedTableName = $mapping['joinTable']['name']; - $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $tablePrefix.$mappedTableName; + $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $tablePrefix . $mappedTableName; } } } diff --git a/src/Entity/Field/FileExtrasTrait.php b/src/Entity/Field/FileExtrasTrait.php index c40924f40..08434ec29 100644 --- a/src/Entity/Field/FileExtrasTrait.php +++ b/src/Entity/Field/FileExtrasTrait.php @@ -39,6 +39,6 @@ private function getHost(Request $request) return $host; } - return $host . ':'.$port; + return $host . ':' . $port; } } diff --git a/src/Factory/MediaFactory.php b/src/Factory/MediaFactory.php index 4ad2fa9d0..bc32f0378 100644 --- a/src/Factory/MediaFactory.php +++ b/src/Factory/MediaFactory.php @@ -50,7 +50,7 @@ public function __construct(Config $config, FileLocations $fileLocations, MediaR public function createOrUpdateMedia(SplFileInfo $file, string $fileLocation, ?string $title = null): Media { - $path = Path::makeRelative($file->getPath(). '/', $this->fileLocations->get($fileLocation)->getBasepath()); + $path = Path::makeRelative($file->getPath() . '/', $this->fileLocations->get($fileLocation)->getBasepath()); $media = $this->mediaRepository->findOneBy([ 'location' => $fileLocation, diff --git a/src/Repository/ContentRepository.php b/src/Repository/ContentRepository.php index 5d2bed96d..ea378cdd0 100644 --- a/src/Repository/ContentRepository.php +++ b/src/Repository/ContentRepository.php @@ -190,10 +190,10 @@ public function findAdjacentBy(string $column, string $direction, int $currentVa { if ($direction === 'next') { $order = 'ASC'; - $whereClause = 'content.' . $column .' > :value'; + $whereClause = 'content.' . $column . ' > :value'; } else { $order = 'DESC'; - $whereClause = 'content.' . $column .' < :value'; + $whereClause = 'content.' . $column . ' < :value'; } $qb = $this->getQueryBuilder() diff --git a/src/Security/LoginFormAuthenticator.php b/src/Security/LoginFormAuthenticator.php index f3527ddc5..e0156fd87 100644 --- a/src/Security/LoginFormAuthenticator.php +++ b/src/Security/LoginFormAuthenticator.php @@ -117,7 +117,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, $uaParser = Parser::create(); $parsedUserAgent = $uaParser->parse($request->headers->get('User-Agent'))->toString(); $sessionLifetime = $request->getSession()->getMetadataBag()->getLifetime(); - $expirationTime = (new \DateTime())->modify('+'.$sessionLifetime.' second'); + $expirationTime = (new \DateTime())->modify('+' . $sessionLifetime . ' second'); $userAuthToken = UserAuthTokenRepository::factory($user, $parsedUserAgent, $expirationTime); $user->setUserAuthToken($userAuthToken); @@ -131,7 +131,7 @@ public function onAuthenticationSuccess(Request $request, TokenInterface $token, $this->logger->notice('User \'{username}\' logged in (manually)', $userArr); return new RedirectResponse($request->getSession()->get( - '_security.'.$providerKey.'.target_path', + '_security.' . $providerKey . '.target_path', $this->router->generate('bolt_dashboard') )); } diff --git a/src/Storage/Directive/OrderDirective.php b/src/Storage/Directive/OrderDirective.php index 36239a346..f23a00f03 100644 --- a/src/Storage/Directive/OrderDirective.php +++ b/src/Storage/Directive/OrderDirective.php @@ -38,7 +38,7 @@ public function __invoke(QueryInterface $query, string $order): void if (! $this->isActualField($query, $order)) { dump("A query with ordering on a Field (`${order}`) that's not defined, will yield unexpected results. Update your `{% setcontent %}`-statement"); } - $fieldsAlias = 'fields_order_' . $query->getIndex(); + $fieldsAlias = 'fields_order_' . $query->getIndex(); $fieldAlias = 'order_' . $query->getIndex(); $translationsAlias = 'translations_order_' . $query->getIndex(); @@ -49,7 +49,7 @@ public function __invoke(QueryInterface $query, string $order): void ->leftJoin('content.fields', $fieldsAlias) ->leftJoin($fieldsAlias . '.translations', $translationsAlias) ->andWhere($fieldsAlias . '.name = :' . $fieldAlias) - ->addOrderBy('lower('.$translationsAlias . '.value)', $direction) + ->addOrderBy('lower(' . $translationsAlias . '.value)', $direction) ->setParameter($fieldAlias, $order); $query->incrementIndex(); diff --git a/src/Twig/ContentExtension.php b/src/Twig/ContentExtension.php index 11695b33b..d7a5be53d 100644 --- a/src/Twig/ContentExtension.php +++ b/src/Twig/ContentExtension.php @@ -432,7 +432,7 @@ private function generateLink(string $route, array $params, $canonical = false): $canonical ? UrlGeneratorInterface::ABSOLUTE_URL : UrlGeneratorInterface::ABSOLUTE_PATH ); } catch (InvalidParameterException $e) { - $this->logger->notice('Could not create URL for route \'' . $route .'\'. Perhaps the ContentType was changed or removed. Try clearing the cache'); + $this->logger->notice('Could not create URL for route \'' . $route . '\'. Perhaps the ContentType was changed or removed. Try clearing the cache'); $link = ''; } diff --git a/src/Widget/BaseWidget.php b/src/Widget/BaseWidget.php index 38612c56d..cf96de594 100644 --- a/src/Widget/BaseWidget.php +++ b/src/Widget/BaseWidget.php @@ -57,7 +57,7 @@ public function setName(string $name): self public function getName(): string { if ($this->name === null) { - throw new WidgetException('Widget of class '.self::class.' does not have a name!'); + throw new WidgetException('Widget of class ' . self::class . ' does not have a name!'); } return $this->name; } diff --git a/src/Widget/Injector/HtmlInjector.php b/src/Widget/Injector/HtmlInjector.php index 091722fe4..53e4f52da 100644 --- a/src/Widget/Injector/HtmlInjector.php +++ b/src/Widget/Injector/HtmlInjector.php @@ -222,7 +222,7 @@ protected function jsTagsAfter(string $snippet, string $rawHtml): string private static function findTagStart(string $rawHtml, string $htmlTag): ?string { - preg_match('~(<'.$htmlTag.'[^>]*?>)~mi', $rawHtml, $matches); + preg_match('~(<' . $htmlTag . '[^>]*?>)~mi', $rawHtml, $matches); if (empty($matches)) { return null; @@ -232,7 +232,7 @@ private static function findTagStart(string $rawHtml, string $htmlTag): ?string private static function findTagEnd(string $rawHtml, string $htmlTag): ?string { - preg_match_all('~((<'.$htmlTag.'(\s[^>]*)?>)|())~mi', $rawHtml, $allMatches); + preg_match_all('~((<' . $htmlTag . '(\s[^>]*)?>)|())~mi', $rawHtml, $allMatches); if (empty($allMatches)) { return null; @@ -253,7 +253,7 @@ public static function injectBeforeTagStart(string $rawHtml, string $htmlTag, st return static::nowhere($injection, $rawHtml); } - return Str::replaceFirst($rawHtml, $match, $injection.$match, true); + return Str::replaceFirst($rawHtml, $match, $injection . $match, true); } public static function injectAfterTagStart(string $rawHtml, string $htmlTag, string $injection): string @@ -263,7 +263,7 @@ public static function injectAfterTagStart(string $rawHtml, string $htmlTag, str return static::nowhere($injection, $rawHtml); } - return Str::replaceFirst($rawHtml, $match, $match.$injection, true); + return Str::replaceFirst($rawHtml, $match, $match . $injection, true); } public static function injectBeforeTagEnd(string $rawHtml, string $htmlTag, string $injection): string @@ -273,7 +273,7 @@ public static function injectBeforeTagEnd(string $rawHtml, string $htmlTag, stri return static::nowhere($injection, $rawHtml); } - return Str::replaceLast($rawHtml, $match, $injection.$match, true); + return Str::replaceLast($rawHtml, $match, $injection . $match, true); } public static function injectAfterTagEnd(string $rawHtml, string $htmlTag, string $injection): string @@ -283,6 +283,6 @@ public static function injectAfterTagEnd(string $rawHtml, string $htmlTag, strin return static::nowhere($injection, $rawHtml); } - return Str::replaceLast($rawHtml, $match, $match.$injection, true); + return Str::replaceLast($rawHtml, $match, $match . $injection, true); } } From 912e578391bcc62143a81a93fb8b85362231c11e Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Sun, 3 May 2020 15:04:06 +0200 Subject: [PATCH 3/4] Tweak, tweak --- easy-coding-standard.yml | 2 -- src/Event/Subscriber/MaintenanceModeSubscriber.php | 1 + src/Twig/WidgetExtension.php | 1 + tests/php/Configuration/Parser/ParserTestBase.php | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index 0e887a7b7..47ed907b7 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -90,11 +90,9 @@ services: parameters: cache_directory: var/cache/ecs skip: - PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: ~ PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer: ~ PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer: ~ PhpCsFixer\Fixer\Operator\IncrementStyleFixer: ~ - PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer: ~ PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer: ~ diff --git a/src/Event/Subscriber/MaintenanceModeSubscriber.php b/src/Event/Subscriber/MaintenanceModeSubscriber.php index b2ac8a000..95dcb98ae 100644 --- a/src/Event/Subscriber/MaintenanceModeSubscriber.php +++ b/src/Event/Subscriber/MaintenanceModeSubscriber.php @@ -20,6 +20,7 @@ public function __construct(Config $config) { $this->config = $config; } + public function onKernelController(ControllerEvent $event): void { $controller = $event->getController(); diff --git a/src/Twig/WidgetExtension.php b/src/Twig/WidgetExtension.php index bd436eadb..006056abb 100644 --- a/src/Twig/WidgetExtension.php +++ b/src/Twig/WidgetExtension.php @@ -20,6 +20,7 @@ public function __construct(Widgets $widgetRenderer) { $this->widgetRenderer = $widgetRenderer; } + /** * {@inheritdoc} */ diff --git a/tests/php/Configuration/Parser/ParserTestBase.php b/tests/php/Configuration/Parser/ParserTestBase.php index 72cbbc023..c17382d6d 100644 --- a/tests/php/Configuration/Parser/ParserTestBase.php +++ b/tests/php/Configuration/Parser/ParserTestBase.php @@ -12,6 +12,7 @@ public function getProjectDir() { return dirname(dirname(dirname(dirname(__DIR__)))); } + public static function getBasePath(): string { return dirname(dirname(dirname(__DIR__))) . '/fixtures/config/'; From f8f5751972ef64399c0fcc8bf1d341e9bc33d753 Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Sun, 3 May 2020 15:06:04 +0200 Subject: [PATCH 4/4] Updating CS --- easy-coding-standard.yml | 2 -- src/Command/AddUserCommand.php | 5 +++++ src/Command/CopyThemesCommand.php | 2 ++ src/Command/DeleteUserCommand.php | 1 + src/Command/ExtensionsShowCommand.php | 1 + src/Command/ImageTrait.php | 1 + src/Command/ResetSecretCommand.php | 1 + src/Configuration/Parser/ContentTypesParser.php | 4 ++++ src/Configuration/Parser/GeneralParser.php | 1 + src/Configuration/PathResolver.php | 1 + src/Controller/Backend/Async/UploadController.php | 1 + src/Controller/Backend/BulkOperationsController.php | 2 ++ src/Controller/Backend/ContentEditController.php | 2 ++ src/Controller/Backend/FileEditController.php | 3 +++ src/Controller/Backend/FilemanagerController.php | 1 + src/Controller/Backend/UserEditController.php | 1 + src/Controller/TwigAwareController.php | 1 + src/DataFixtures/ContentFixtures.php | 12 ++++++++++++ src/Entity/Content.php | 2 ++ src/Entity/Field/EmbedField.php | 1 + src/Entity/Log.php | 10 ++++++++++ src/Entity/User.php | 1 + src/Extension/ExtensionRegistry.php | 2 ++ src/Menu/CachedBackendMenuBuilder.php | 1 + src/Repository/ContentRepository.php | 1 + src/Repository/LogRepository.php | 1 + src/Repository/UserRepository.php | 2 ++ src/Storage/ContentQueryParser.php | 1 + src/Twig/ArrayExtension.php | 2 ++ src/Twig/ContentExtension.php | 2 ++ src/Twig/RelatedExtension.php | 1 + src/Utils/ComposeValueHelper.php | 1 + src/Utils/Html.php | 1 + src/Utils/LocaleHelper.php | 1 + src/Widget/BaseWidget.php | 6 ++++++ src/Widget/CacheTrait.php | 1 + src/Widget/Injector/HtmlInjector.php | 1 + src/Widget/RequestTrait.php | 1 + src/Widget/ResponseTrait.php | 1 + src/Widget/TwigTrait.php | 1 + 40 files changed, 81 insertions(+), 2 deletions(-) diff --git a/easy-coding-standard.yml b/easy-coding-standard.yml index 47ed907b7..1a2ec8ec0 100644 --- a/easy-coding-standard.yml +++ b/easy-coding-standard.yml @@ -95,8 +95,6 @@ parameters: PhpCsFixer\Fixer\Operator\IncrementStyleFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer: ~ PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer: ~ - PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer: ~ - SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff: ~ Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff: ~ #to be removed before beta release Symplify\CodingStandard\Sniffs\Debug\DebugFunctionCallSniff: ~ #to be removed before beta release diff --git a/src/Command/AddUserCommand.php b/src/Command/AddUserCommand.php index 1ab712f18..0c5a2b4e5 100644 --- a/src/Command/AddUserCommand.php +++ b/src/Command/AddUserCommand.php @@ -135,6 +135,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi if ($errors->count() > 0) { throw new InvalidArgumentException($errors->get(0)->getMessage()); } + return $username; }); $input->setArgument('username', $username); @@ -152,6 +153,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi if ($errors->count() > 0) { throw new InvalidArgumentException($errors->get(0)->getMessage()); } + return $password; }); @@ -169,6 +171,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi if ($errors->count() > 0) { throw new InvalidArgumentException($errors->get(0)->getMessage()); } + return $email; }); $input->setArgument('email', $email); @@ -184,6 +187,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi if ($errors->count() > 0) { throw new InvalidArgumentException($errors->get(0)->getMessage()); } + return $displayName; }); $input->setArgument('display-name', $displayName); @@ -219,6 +223,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($errors as $error) { $errorMessages[] = $error->getMessage(); } + throw new RuntimeException(implode(', ', $errorMessages)); } diff --git a/src/Command/CopyThemesCommand.php b/src/Command/CopyThemesCommand.php index ce5eb8101..234605e66 100644 --- a/src/Command/CopyThemesCommand.php +++ b/src/Command/CopyThemesCommand.php @@ -61,9 +61,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int } else { if (Version::installType() === 'Git clone') { $io->error('This command only works with the \'Composer install\' install type.'); + return 1; } $io->error('Run \'composer require bolt/themes\' before using this command.'); + return 1; } diff --git a/src/Command/DeleteUserCommand.php b/src/Command/DeleteUserCommand.php index b24335acc..381b82085 100644 --- a/src/Command/DeleteUserCommand.php +++ b/src/Command/DeleteUserCommand.php @@ -104,6 +104,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi if ($errors->count() > 0) { throw new InvalidArgumentException($errors->get(0)->getMessage()); } + return $username; }); $input->setArgument('username', $username); diff --git a/src/Command/ExtensionsShowCommand.php b/src/Command/ExtensionsShowCommand.php index 73537e36d..dfd4aec63 100644 --- a/src/Command/ExtensionsShowCommand.php +++ b/src/Command/ExtensionsShowCommand.php @@ -49,6 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int if (! $extension instanceof ExtensionInterface) { $io->caution('No such extension.'); + return 0; } diff --git a/src/Command/ImageTrait.php b/src/Command/ImageTrait.php index cb1827414..1bdf6fa6f 100644 --- a/src/Command/ImageTrait.php +++ b/src/Command/ImageTrait.php @@ -12,6 +12,7 @@ public function outputImage(SymfonyStyle $io): void { if (getenv('TERM_PROGRAM') !== 'iTerm.app') { $io->title('⚙️ Bolt'); + return; } diff --git a/src/Command/ResetSecretCommand.php b/src/Command/ResetSecretCommand.php index d57bdebe0..32e1c2fd1 100644 --- a/src/Command/ResetSecretCommand.php +++ b/src/Command/ResetSecretCommand.php @@ -61,6 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $io->success('Secret replaced successfully!'); + return null; } } diff --git a/src/Configuration/Parser/ContentTypesParser.php b/src/Configuration/Parser/ContentTypesParser.php index f529f6fa6..f58de6cc6 100644 --- a/src/Configuration/Parser/ContentTypesParser.php +++ b/src/Configuration/Parser/ContentTypesParser.php @@ -67,16 +67,19 @@ protected function parseContentType($key, array $contentType): ?ContentType // neither 'singular_name' nor 'singular_slug' is set. if (! isset($contentType['name']) && ! isset($contentType['slug'])) { $error = sprintf("In content type %s, neither 'name' nor 'slug' is set. Please edit contenttypes.yml, and correct this.", $key); + throw new ConfigurationException($error); } if (! isset($contentType['singular_name']) && ! isset($contentType['singular_slug'])) { $error = sprintf("In content type %s, neither 'singular_name' nor 'singular_slug' is set. Please edit contenttypes.yml, and correct this.", $key); + throw new ConfigurationException($error); } // Content types without fields make no sense. if (! isset($contentType['fields'])) { $error = sprintf("In content type %s, no 'fields' are set. Please edit contenttypes.yml, and correct this.", $key); + throw new ConfigurationException($error); } @@ -155,6 +158,7 @@ protected function parseContentType($key, array $contentType): ?ContentType $forbidden = array_diff((array) $contentType['locales'], $this->localeCodes); if (! empty($this->localeCodes) && ! empty($forbidden)) { $error = sprintf('The %s locale was requested, but permitted locales are %s. Please check your services.yaml app_locales setting.', implode(', ', $forbidden), implode(', ', $this->localeCodes)); + throw new ConfigurationException($error); } diff --git a/src/Configuration/Parser/GeneralParser.php b/src/Configuration/Parser/GeneralParser.php index 8dc14a9b1..ef2c48869 100644 --- a/src/Configuration/Parser/GeneralParser.php +++ b/src/Configuration/Parser/GeneralParser.php @@ -240,6 +240,7 @@ protected function parseConnectionParams($params, ?Collection $defaults = null): 'servicename', 'service', 'pooled', 'instancename', 'server', // Oracle 'persistent', // SQL Anywhere ]; + return $params->intersectByKeys($validKeys); } diff --git a/src/Configuration/PathResolver.php b/src/Configuration/PathResolver.php index 6fd7da7b1..e3e51e225 100644 --- a/src/Configuration/PathResolver.php +++ b/src/Configuration/PathResolver.php @@ -116,6 +116,7 @@ public function resolve(string $path, bool $absolute = true, $additional = null) } $this->resolving[$alias] = true; + try { return $this->resolve($alias, $absolute); } finally { diff --git a/src/Controller/Backend/Async/UploadController.php b/src/Controller/Backend/Async/UploadController.php index c8dce473c..1c0d52b02 100644 --- a/src/Controller/Backend/Async/UploadController.php +++ b/src/Controller/Backend/Async/UploadController.php @@ -101,6 +101,7 @@ public function handleUpload(Request $request): JsonResponse } catch (\Throwable $e) { // something wrong happened, we don't need the uploaded files anymore $result->clear(); + throw $e; } } diff --git a/src/Controller/Backend/BulkOperationsController.php b/src/Controller/Backend/BulkOperationsController.php index 038fb7a83..f3dec8cd5 100644 --- a/src/Controller/Backend/BulkOperationsController.php +++ b/src/Controller/Backend/BulkOperationsController.php @@ -57,6 +57,7 @@ public function status(Request $request, string $status): Response $this->addFlash('success', 'content.status_changed_successfully'); $url = $request->headers->get('referer'); + return new RedirectResponse($url); } @@ -79,6 +80,7 @@ public function delete(Request $request): Response $this->addFlash('success', 'content.deleted_successfully'); $url = $request->headers->get('referer'); + return new RedirectResponse($url); } diff --git a/src/Controller/Backend/ContentEditController.php b/src/Controller/Backend/ContentEditController.php index 36425b8b6..47ae5ba32 100644 --- a/src/Controller/Backend/ContentEditController.php +++ b/src/Controller/Backend/ContentEditController.php @@ -227,6 +227,7 @@ public function status(Request $request, Content $content): Response { if (! $this->isCsrfTokenValid('status', $request->get('token'))) { $url = $this->urlGenerator->generate('bolt_dashboard'); + return new RedirectResponse($url); } @@ -253,6 +254,7 @@ public function delete(Request $request, Content $content): Response { if (! $this->isCsrfTokenValid('delete', $request->get('token'))) { $url = $this->urlGenerator->generate('bolt_dashboard'); + return new RedirectResponse($url); } diff --git a/src/Controller/Backend/FileEditController.php b/src/Controller/Backend/FileEditController.php index c22f7e9f0..5d2b815b7 100644 --- a/src/Controller/Backend/FileEditController.php +++ b/src/Controller/Backend/FileEditController.php @@ -148,6 +148,7 @@ public function handleDelete(Request $request): Response } $this->addFlash('success', 'file.delete_success'); + return $this->redirectToRoute('bolt_filemanager', ['location' => $locationName]); } @@ -181,6 +182,7 @@ public function handleDuplicate(Request $request): Response } $this->addFlash('success', 'file.delete_success'); + return $this->redirectToRoute('bolt_filemanager', ['location' => $locationName]); } @@ -205,6 +207,7 @@ private function getCopyFilepath(string $path): string private function verifyYaml(string $yaml): bool { $yamlParser = new Parser(); + try { $yamlParser->parse($yaml); } catch (ParseException $e) { diff --git a/src/Controller/Backend/FilemanagerController.php b/src/Controller/Backend/FilemanagerController.php index ae4f3377c..304e999c2 100644 --- a/src/Controller/Backend/FilemanagerController.php +++ b/src/Controller/Backend/FilemanagerController.php @@ -107,6 +107,7 @@ private function buildIndex(string $base) private function getFileSummary($contents) { $contents = str_replace(['urlGenerator->generate('bolt_users'); $this->addFlash('success', 'user.updated_profile'); + return new RedirectResponse($url); } diff --git a/src/Controller/TwigAwareController.php b/src/Controller/TwigAwareController.php index 40bedb14e..a54246bd9 100644 --- a/src/Controller/TwigAwareController.php +++ b/src/Controller/TwigAwareController.php @@ -67,6 +67,7 @@ protected function renderTemplate($template, array $parameters = [], ?Response $ if ($element instanceof TemplateselectField) { return $element->__toString(); } + return $element; }) ->filter() diff --git a/src/DataFixtures/ContentFixtures.php b/src/DataFixtures/ContentFixtures.php index 9ed975c4f..33ad72046 100644 --- a/src/DataFixtures/ContentFixtures.php +++ b/src/DataFixtures/ContentFixtures.php @@ -206,12 +206,15 @@ private function getValuesforFieldType(string $name, DeepCollection $field, bool switch ($field['type']) { case 'html': $data = [FakeContent::generateHTML($nb)]; + break; case 'markdown': $data = [FakeContent::generateMarkdown($nb)]; + break; case 'textarea': $data = [$this->faker->paragraphs(3, true)]; + break; case 'image': case 'file': @@ -221,32 +224,40 @@ private function getValuesforFieldType(string $name, DeepCollection $field, bool 'alt' => $this->faker->sentence(4, true), 'media' => '', ]; + break; case 'slug': $data = $this->lastTitle ?? [$this->faker->sentence(3, true)]; + break; case 'text': $words = isset($field['slug']) && in_array($field['slug'], ['title', 'heading'], true) ? 3 : 7; $data = [$this->faker->sentence($words, true)]; + break; case 'email': $data = [$this->faker->email]; + break; case 'templateselect': $data = []; + break; case 'date': case 'datetime': $data = [$this->faker->dateTime()->format('c')]; + break; case 'number': $data = [$this->faker->numberBetween(-100, 1000)]; + break; case 'data': $data = []; for ($i = 1; $i < 5; $i++) { $data[$this->faker->sentence(1)] = $this->faker->sentence(4, true); } + break; case 'imagelist': case 'filelist': @@ -259,6 +270,7 @@ private function getValuesforFieldType(string $name, DeepCollection $field, bool 'media' => '', ]; } + break; default: $data = [$this->faker->sentence(6, true)]; diff --git a/src/Entity/Content.php b/src/Entity/Content.php index 6c1fd956a..6e33636d2 100644 --- a/src/Entity/Content.php +++ b/src/Entity/Content.php @@ -157,6 +157,7 @@ public function __toString(): string if ($this->getId()) { return sprintf('%s #%d', $contentName, $this->getId()); } + return sprintf('New %s', $contentName); } @@ -551,6 +552,7 @@ public function getAuthorName(): ?string if ($this->getAuthor() !== null) { return $this->getAuthor()->getDisplayName(); } + return null; } diff --git a/src/Entity/Field/EmbedField.php b/src/Entity/Field/EmbedField.php index 13692b191..1e5cdeb24 100644 --- a/src/Entity/Field/EmbedField.php +++ b/src/Entity/Field/EmbedField.php @@ -34,6 +34,7 @@ private function getResponsive(): string $html = preg_replace("/width=(['\"])([0-9]+)(['\"])/i", '', $html); $html = preg_replace("/height=(['\"])([0-9]+)(['\"])/i", '', $html); + return '
' . $html . '
'; } diff --git a/src/Entity/Log.php b/src/Entity/Log.php index e8957797c..b209a76b6 100644 --- a/src/Entity/Log.php +++ b/src/Entity/Log.php @@ -67,6 +67,7 @@ public function getId(): int public function setId(int $id): self { $this->id = $id; + return $this; } @@ -78,6 +79,7 @@ public function getMessage(): string public function setMessage(string $message): self { $this->message = $message; + return $this; } @@ -89,6 +91,7 @@ public function getContext(): ?array public function setContext(?array $context): self { $this->context = $context; + return $this; } @@ -100,6 +103,7 @@ public function getLevel(): int public function setLevel(int $level): self { $this->level = $level; + return $this; } @@ -111,6 +115,7 @@ public function getLevelName(): string public function setLevelName(string $levelName): self { $this->levelName = $levelName; + return $this; } @@ -122,6 +127,7 @@ public function getExtra(): ?array public function setExtra(?array $extra): self { $this->extra = $extra; + return $this; } @@ -133,6 +139,7 @@ public function getCreatedAt(): \DateTime public function setCreatedAt(\DateTime $createdAt): self { $this->createdAt = $createdAt; + return $this; } @@ -144,6 +151,7 @@ public function getLocation(): ?array public function setLocation(?array $location): self { $this->location = $location; + return $this; } @@ -155,6 +163,7 @@ public function getUser(): ?array public function setUser(?array $user): self { $this->user = $user; + return $this; } @@ -166,6 +175,7 @@ public function getContent(): ?int public function setContent(int $content): self { $this->content = $content; + return $this; } } diff --git a/src/Entity/User.php b/src/Entity/User.php index 2afa517bb..24b7ea30a 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -168,6 +168,7 @@ public function getPlainPassword(): ?string public function setPlainPassword(string $plainPassword): self { $this->plainPassword = $plainPassword; + return $this; } diff --git a/src/Extension/ExtensionRegistry.php b/src/Extension/ExtensionRegistry.php index 31a02209b..ce9b4b5f7 100644 --- a/src/Extension/ExtensionRegistry.php +++ b/src/Extension/ExtensionRegistry.php @@ -34,11 +34,13 @@ private function addComposerPackages(): void if (! array_key_exists('entrypoint', $extra)) { $message = sprintf("The extension \"%s\" has no 'extra/entrypoint' defined in its 'composer.json' file.", $package->getName()); + throw new \Exception($message); } if (! class_exists($extra['entrypoint'])) { $message = sprintf("The extension \"%s\" has its 'extra/entrypoint' set to \"%s\", but that class does not exist", $package->getName(), $extra['entrypoint']); + throw new \Exception($message); } diff --git a/src/Menu/CachedBackendMenuBuilder.php b/src/Menu/CachedBackendMenuBuilder.php index 7ab6e388c..c2515d523 100644 --- a/src/Menu/CachedBackendMenuBuilder.php +++ b/src/Menu/CachedBackendMenuBuilder.php @@ -31,6 +31,7 @@ public function buildAdminMenu(): array { $locale = $this->requestStack->getCurrentRequest()->getLocale(); $cacheKey = 'backendmenu_' . $locale; + return $this->cache->get($cacheKey, function (ItemInterface $item) { $item->tag('backendmenu'); diff --git a/src/Repository/ContentRepository.php b/src/Repository/ContentRepository.php index ea378cdd0..6dd61ed66 100644 --- a/src/Repository/ContentRepository.php +++ b/src/Repository/ContentRepository.php @@ -183,6 +183,7 @@ private function createPaginator(Query $query, int $page, int $amountPerPage): P $paginator = new Pagerfanta(new DoctrineORMAdapter($query, true, true)); $paginator->setMaxPerPage($amountPerPage); $paginator->setCurrentPage($page); + return $paginator; } diff --git a/src/Repository/LogRepository.php b/src/Repository/LogRepository.php index a1302e3c0..b47a4582a 100644 --- a/src/Repository/LogRepository.php +++ b/src/Repository/LogRepository.php @@ -44,6 +44,7 @@ private function createPaginator(Query $query, int $page, int $amountPerPage): P $paginator = new Pagerfanta(new DoctrineORMAdapter($query, true, true)); $paginator->setMaxPerPage($amountPerPage); $paginator->setCurrentPage($page); + return $paginator; } } diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 085da1e96..a0696beb6 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -18,6 +18,7 @@ public function __construct(ManagerRegistry $registry) public function findOneByUsername(string $username): ?User { $user = $this->findOneBy(['username' => $username]); + return $user instanceof User ? $user : null; } @@ -41,6 +42,7 @@ public function findOneByCredentials(string $username): ?User } $qb->setParameter('username', $username); $user = $qb->getQuery()->getOneOrNullResult(); + return $user instanceof User ? $user : null; } diff --git a/src/Storage/ContentQueryParser.php b/src/Storage/ContentQueryParser.php index 88adcf387..157e8f729 100644 --- a/src/Storage/ContentQueryParser.php +++ b/src/Storage/ContentQueryParser.php @@ -271,6 +271,7 @@ public function setContentTypes(array $contentTypes): void if (! $configCT) { $message = sprintf("Tried to get content from ContentType '%s', but no ContentType by that name/slug exists.", $value); + throw new \Exception($message); } diff --git a/src/Twig/ArrayExtension.php b/src/Twig/ArrayExtension.php index 6bd6a2117..5fbed0603 100644 --- a/src/Twig/ArrayExtension.php +++ b/src/Twig/ArrayExtension.php @@ -54,6 +54,7 @@ public static function order(array $array, string $on = '-datepublish', ?string if ($check !== 0 || $orderOnSecondary !== '') { return $check; } + return self::orderHelper($a, $b, $orderOnSecondary, $orderAscendingSecondary); }); @@ -97,6 +98,7 @@ private static function orderHelper(Content $a, Content $b, string $orderOn, boo if ($orderAscending) { return $aVal <=> $bVal; } + return $bVal <=> $aVal; } } diff --git a/src/Twig/ContentExtension.php b/src/Twig/ContentExtension.php index d7a5be53d..e6b4db84d 100644 --- a/src/Twig/ContentExtension.php +++ b/src/Twig/ContentExtension.php @@ -205,6 +205,7 @@ public function guessTitleFields(Content $content): array $name )); } + return $content->hasField($name); }); @@ -297,6 +298,7 @@ public function getExcerpt($content, int $length = 280, bool $includeTitle = fal // add comma add end of string if it doesn't have sentence end $part .= '.'; } + return $excerpt . $part . ' '; }, ''); diff --git a/src/Twig/RelatedExtension.php b/src/Twig/RelatedExtension.php index 4bd5ab735..083213ca3 100644 --- a/src/Twig/RelatedExtension.php +++ b/src/Twig/RelatedExtension.php @@ -77,6 +77,7 @@ public function getRelatedContentByType(Content $content, bool $bidirectional = } $result[$relation->getName()][] = $relatedContent; } + return $result; }, []); } diff --git a/src/Utils/ComposeValueHelper.php b/src/Utils/ComposeValueHelper.php index 290917ecd..0f0f7ce1e 100644 --- a/src/Utils/ComposeValueHelper.php +++ b/src/Utils/ComposeValueHelper.php @@ -35,6 +35,7 @@ function ($match) use ($record, $locale) { if ($field->isTranslatable()) { $field->setLocale($locale); } + return $field; } diff --git a/src/Utils/Html.php b/src/Utils/Html.php index 3abe8951a..e7d3c4201 100644 --- a/src/Utils/Html.php +++ b/src/Utils/Html.php @@ -61,6 +61,7 @@ public static function trimText(string $str, int $desiredLength, bool $hellip = public static function decorateTT($str): string { $str = htmlspecialchars($str, ENT_QUOTES); + return preg_replace('/`([^`]*)`/', '\\1', $str); } diff --git a/src/Utils/LocaleHelper.php b/src/Utils/LocaleHelper.php index 620cb941e..b0b6aaae2 100644 --- a/src/Utils/LocaleHelper.php +++ b/src/Utils/LocaleHelper.php @@ -124,6 +124,7 @@ private function getLink(string $route, array $routeParams, Collection $locale): case 'search_locale': case 'taxonomy_locale': $routeParams['_locale'] = $locale->get('code'); + break; default: $routeParams['edit_locale'] = $locale->get('code'); diff --git a/src/Widget/BaseWidget.php b/src/Widget/BaseWidget.php index cf96de594..8cccecade 100644 --- a/src/Widget/BaseWidget.php +++ b/src/Widget/BaseWidget.php @@ -59,6 +59,7 @@ public function getName(): string if ($this->name === null) { throw new WidgetException('Widget of class ' . self::class . ' does not have a name!'); } + return $this->name; } @@ -74,6 +75,7 @@ public function getTarget(): string if ($this->target === null) { throw new WidgetException("Widget {$this->getName()} does not have Target set"); } + return $this->target; } @@ -89,6 +91,7 @@ public function getPriority(): int if ($this->priority === null) { throw new WidgetException("Widget {$this->getName()} does not have priority set"); } + return $this->priority; } @@ -127,6 +130,7 @@ protected function run(array $params = []): ?string if ($this instanceof TwigAwareInterface) { $this->addTwigLoader(); + try { $output = $this->getTwig()->render($this->getTemplate(), $params); } catch (LoaderError $e) { @@ -159,6 +163,7 @@ public function getTemplate(): string if ($this->template === null) { throw new WidgetException("Widget {$this->getName()} does not have template set"); } + return $this->template; } @@ -204,6 +209,7 @@ public function getZone(): string if ($this->zone === null) { throw new WidgetException("Widget {$this->getName()} does not have Zone set"); } + return $this->zone; } diff --git a/src/Widget/CacheTrait.php b/src/Widget/CacheTrait.php index 28e4fd145..fc056d655 100644 --- a/src/Widget/CacheTrait.php +++ b/src/Widget/CacheTrait.php @@ -32,6 +32,7 @@ public function __invoke(array $params = []): ?string $this->key, function (ItemInterface $item) use ($params) { $item->expiresAfter($this->getCacheDuration()); + return $this->run($params); } ); diff --git a/src/Widget/Injector/HtmlInjector.php b/src/Widget/Injector/HtmlInjector.php index 53e4f52da..db0199b06 100644 --- a/src/Widget/Injector/HtmlInjector.php +++ b/src/Widget/Injector/HtmlInjector.php @@ -227,6 +227,7 @@ private static function findTagStart(string $rawHtml, string $htmlTag): ?string if (empty($matches)) { return null; } + return $matches[1]; } diff --git a/src/Widget/RequestTrait.php b/src/Widget/RequestTrait.php index 87613385c..bd4cb1210 100644 --- a/src/Widget/RequestTrait.php +++ b/src/Widget/RequestTrait.php @@ -24,6 +24,7 @@ public function getRequest(): Request if ($this->request === null) { throw new WidgetException("Widget {$this->getName()} does not have Request set"); } + return $this->request; } } diff --git a/src/Widget/ResponseTrait.php b/src/Widget/ResponseTrait.php index 46aa9e6c5..128aed1af 100644 --- a/src/Widget/ResponseTrait.php +++ b/src/Widget/ResponseTrait.php @@ -24,6 +24,7 @@ public function getResponse(): Response if ($this->response === null) { throw new WidgetException("Widget {$this->getName()} does not have Response set"); } + return $this->response; } } diff --git a/src/Widget/TwigTrait.php b/src/Widget/TwigTrait.php index 2e9f1a2a4..ccf436f1a 100644 --- a/src/Widget/TwigTrait.php +++ b/src/Widget/TwigTrait.php @@ -24,6 +24,7 @@ public function getTwig(): Environment if ($this->twig === null) { throw new WidgetException("Widget {$this->getName()} does not have Twig set"); } + return $this->twig; } }