From cd22ed78012555bf957a0775149c04774c88c7b4 Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 31 Aug 2020 19:54:34 +0200 Subject: [PATCH 1/2] Updating dependencies, Fix CS findings --- composer.json | 32 +++++++++++----------- src/Configuration/Content/FieldType.php | 3 +- src/Event/Listener/ContentFillListener.php | 6 +--- src/Storage/Handler/SelectQueryHandler.php | 2 +- src/Storage/SelectQuery.php | 2 +- src/Twig/ContentExtension.php | 2 +- src/Twig/FieldExtension.php | 3 +- symfony.lock | 9 ++++++ 8 files changed, 33 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 6c90f2950..b1d280bff 100644 --- a/composer.json +++ b/composer.json @@ -9,13 +9,13 @@ "ext-mbstring": "*", "ext-pdo": "*", "api-platform/core": "^2.5", - "babdev/pagerfanta-bundle": "^2.4", - "beberlei/doctrineextensions": "^1.0", + "babdev/pagerfanta-bundle": "^2.5", + "beberlei/doctrineextensions": "^1.2", "bolt/common": "^2.1.6", "cocur/slugify": "^4.0", "composer/composer": "^1.10", - "composer/package-versions-deprecated": "^1.8", - "doctrine/doctrine-bundle": "^2.0", + "composer/package-versions-deprecated": "^1.11", + "doctrine/doctrine-bundle": "^2.1", "doctrine/doctrine-fixtures-bundle": "^3.3", "doctrine/orm": "^2.7", "drupol/composer-packages": "^1.1", @@ -26,15 +26,15 @@ "knplabs/knp-menu-bundle": "^3.0", "league/glide-symfony": "^1.0", "miljar/php-exif": "^0.6.4", - "nelmio/cors-bundle": "^2.0", - "nesbot/carbon": "^2.28", + "nelmio/cors-bundle": "^2.1", + "nesbot/carbon": "^2.39", "peterkahl/country-code-to-emoji-flag": "^1.2", "php-translation/symfony-bundle": "^0.12", "phpdocumentor/reflection-docblock": "^4.3", "psr/event-dispatcher": "^1.0", "psr/simple-cache": "^1.0", "scienta/doctrine-json-functions": "^4.1", - "sensio/framework-extra-bundle": "^5.5", + "sensio/framework-extra-bundle": "^5.6", "sensiolabs/security-checker": "^6.0", "siriusphp/upload": "^3.0.1", "squirrelphp/twig-php-syntax": "^1.5", @@ -44,7 +44,7 @@ "symfony/dependency-injection": "^4.4 | ^5.1", "symfony/dotenv": "^4.4 | ^5.1", "symfony/expression-language": "^4.4 | ^5.1", - "symfony/flex": "^1.6", + "symfony/flex": "^1.9", "symfony/form": "^4.4 | ^5.1", "symfony/framework-bundle": "^4.4 | ^5.1", "symfony/http-client": "^4.4 | ^5.1", @@ -64,10 +64,10 @@ "symfony/web-server-bundle": "^4.4", "symfony/webpack-encore-bundle": "^1.7", "symfony/yaml": "^4.4 | ^5.1", - "tightenco/collect": "^7.4", + "tightenco/collect": "^7.25", "twig/twig": "^3.0", "ua-parser/uap-php": "^3.9", - "webimpress/safe-writer": "^2.0", + "webimpress/safe-writer": "^2.1", "webmozart/path-util": "^2.3", "webonyx/graphql-php": "^0.13", "xemlock/htmlpurifier-html5": "^0.1.11" @@ -78,23 +78,23 @@ "require-dev": { "ext-curl": "*", "ext-pdo_sqlite": "*", - "acmecorp/reference-extension": "^1.0", + "acmecorp/reference-extension": "^1.2", "behat/mink-goutte-driver": "^1.2", "behat/mink-selenium2-driver": "^1.4", - "behatch/contexts": "^3.2", - "bobdenotter/configuration-notices": "^1.0", + "behatch/contexts": "^3.3", + "bobdenotter/configuration-notices": "^1.1", "bobdenotter/weatherwidget": "^1.1", - "bolt/newswidget": "^1.1", + "bolt/newswidget": "^1.2", "coduo/php-matcher": "^4.0", "dama/doctrine-test-bundle": "^6.2.0", - "doctrine/doctrine-migrations-bundle": "^2.1", + "doctrine/doctrine-migrations-bundle": "^2.2", "friends-of-behat/mink": "^1.8", "friends-of-behat/mink-browserkit-driver": "^1.4", "friends-of-behat/symfony-extension": "^2.1", "lakion/mink-debug-extension": "^1.2", "php-http/httplug-pack": "^1.2", "php-translation/loco-adapter": "^0.11", - "phpspec/phpspec": "^6.1.1", + "phpspec/phpspec": "^6.2.1", "phpspec/prophecy": "^1.10", "phpstan/phpstan": "^0.12", "phpstan/phpstan-doctrine": "^0.12", diff --git a/src/Configuration/Content/FieldType.php b/src/Configuration/Content/FieldType.php index a9622dde2..93fbb3ad4 100644 --- a/src/Configuration/Content/FieldType.php +++ b/src/Configuration/Content/FieldType.php @@ -49,7 +49,8 @@ private static function defaults(): Collection 'pattern' => false, 'hidden' => false, 'default_locale' => 'en', - 'height' => '10', // 10 rows by default + // 10 rows by default + 'height' => '10', ]); } diff --git a/src/Event/Listener/ContentFillListener.php b/src/Event/Listener/ContentFillListener.php index 5a90f2ad0..46b838c0d 100644 --- a/src/Event/Listener/ContentFillListener.php +++ b/src/Event/Listener/ContentFillListener.php @@ -25,18 +25,14 @@ class ContentFillListener /** @var UserRepository */ private $users; - /** @var string */ - private $defaultLocale; - /** @var FieldRepository */ private $fieldRepository; - public function __construct(Config $config, ContentExtension $contentExtension, UserRepository $users, string $defaultLocale, FieldRepository $fieldRepository) + public function __construct(Config $config, ContentExtension $contentExtension, UserRepository $users, FieldRepository $fieldRepository) { $this->config = $config; $this->contentExtension = $contentExtension; $this->users = $users; - $this->defaultLocale = $defaultLocale; $this->fieldRepository = $fieldRepository; } diff --git a/src/Storage/Handler/SelectQueryHandler.php b/src/Storage/Handler/SelectQueryHandler.php index aa23f3f6e..51157a996 100644 --- a/src/Storage/Handler/SelectQueryHandler.php +++ b/src/Storage/Handler/SelectQueryHandler.php @@ -71,7 +71,7 @@ public function __invoke(ContentQueryParser $contentQuery) return $this->createPaginator($request, $query, $amountPerPage, $page); } - private function createPaginator(?Request $request, Query $query, int $amountPerPage, int $page = null): Pagerfanta + private function createPaginator(?Request $request, Query $query, int $amountPerPage, ?int $page = null): Pagerfanta { $paginator = new Pagerfanta(new DoctrineORMAdapter($query, true, true)); $paginator->setMaxPerPage($amountPerPage); diff --git a/src/Storage/SelectQuery.php b/src/Storage/SelectQuery.php index adf817aea..e8f48b6c3 100644 --- a/src/Storage/SelectQuery.php +++ b/src/Storage/SelectQuery.php @@ -380,7 +380,7 @@ public function doTaxonomyJoins(): void */ public function doFieldJoins(): void { - foreach ($this->fieldJoins as $key => $filter) { + foreach (array_keys($this->fieldJoins) as $key) { $contentAlias = 'content'; $fieldsAlias = 'fields_' . $key; $translationsAlias = 'translations_' . $key; diff --git a/src/Twig/ContentExtension.php b/src/Twig/ContentExtension.php index 9d06d949a..a8b65d634 100644 --- a/src/Twig/ContentExtension.php +++ b/src/Twig/ContentExtension.php @@ -480,7 +480,7 @@ public function getListTemplates(TemplateselectField $field): LaravelCollection return new LaravelCollection($options); } - public function pager(Environment $twig, Pagerfanta $records = null, string $template = '@bolt/helpers/_pager_basic.html.twig', string $class = 'pagination', int $surround = 3) + public function pager(Environment $twig, ?Pagerfanta $records = null, string $template = '@bolt/helpers/_pager_basic.html.twig', string $class = 'pagination', int $surround = 3) { $params = array_merge( $this->request->get('_route_params'), diff --git a/src/Twig/FieldExtension.php b/src/Twig/FieldExtension.php index a78c35595..8f5bccc9a 100644 --- a/src/Twig/FieldExtension.php +++ b/src/Twig/FieldExtension.php @@ -96,7 +96,8 @@ public function getSelected(Field\SelectField $field, $returnsingle = false, $re } $ids = $field->getValue(); - $records = $this->contentRepository->findBy(['id' => $ids]); // Find records by their respective ids + // Find records by their respective ids + $records = $this->contentRepository->findBy(['id' => $ids]); if ($returnsingle || (! $returnarray && $definition->get('multiple') === false)) { return current($records); diff --git a/symfony.lock b/symfony.lock index 40ef29f48..884bf64fc 100644 --- a/symfony.lock +++ b/symfony.lock @@ -118,6 +118,9 @@ "config/packages/test/dama_doctrine_test_bundle.yaml" ] }, + "dealerdirect/phpcodesniffer-composer-installer": { + "version": "v0.7.0" + }, "doctrine/annotations": { "version": "1.0", "recipe": { @@ -509,6 +512,9 @@ "phpspec/prophecy": { "version": "v1.10.2" }, + "phpstan/phpdoc-parser": { + "version": "0.4.9" + }, "phpstan/phpstan": { "version": "0.12.11" }, @@ -661,6 +667,9 @@ "siriusphp/validation": { "version": "2.3.0" }, + "slevomat/coding-standard": { + "version": "6.4.0" + }, "squirrelphp/twig-php-syntax": { "version": "v1.5" }, From 5901145eb180017b61b5743f77474c4bd8015828 Mon Sep 17 00:00:00 2001 From: Bob den Otter Date: Mon, 31 Aug 2020 19:56:38 +0200 Subject: [PATCH 2/2] Fix widgets: Only setRendered if widget didn't return `null` --- src/Widgets.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Widgets.php b/src/Widgets.php index 9e746fc08..a82f0396b 100644 --- a/src/Widgets.php +++ b/src/Widgets.php @@ -128,13 +128,18 @@ private function invokeWidget(WidgetInterface $widget, array $params = []): ?str } // Call the magic `__invoke` method on the $widget object + // It can return a string (even an empty one) or `null` $output = $widget($params); if ($widget instanceof StopwatchAwareInterface) { $widget->stopStopwatch(); } - $this->setRendered($widget, $output); + // Set the output as rendered for this Request, unless invoking it + // returned `null` + if ($output !== null) { + $this->setRendered($widget, $output); + } return $output; }