From 02ad15f97fcb05b136b3724b010691c3d66e035f Mon Sep 17 00:00:00 2001 From: SonataCI Date: Sun, 5 Mar 2023 12:13:16 +0000 Subject: [PATCH 1/9] DevKit updates --- .github/workflows/lint.yaml | 2 +- .github/workflows/qa.yaml | 8 ++++---- .github/workflows/symfony-lint.yaml | 8 ++++---- .github/workflows/test.yaml | 19 ++++--------------- Makefile | 2 +- rector.php | 2 +- 6 files changed, 15 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index c22069576..c11c66203 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -54,7 +54,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2, composer-normalize:2 env: diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 4e09b36d0..bf2b3b2c5 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -29,7 +29,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 @@ -54,7 +54,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 @@ -65,7 +65,7 @@ jobs: composer-options: --prefer-dist --prefer-stable - name: Psalm - run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.1 + run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.2 rector: name: Rector @@ -79,7 +79,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 diff --git a/.github/workflows/symfony-lint.yaml b/.github/workflows/symfony-lint.yaml index 9d6e7cc62..8f5d23d79 100644 --- a/.github/workflows/symfony-lint.yaml +++ b/.github/workflows/symfony-lint.yaml @@ -29,7 +29,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 @@ -54,7 +54,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 @@ -79,7 +79,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 @@ -104,7 +104,7 @@ jobs: - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none tools: composer:v2 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 4d7c0eb08..cedccfb0d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,7 +30,6 @@ jobs: strategy: matrix: php-version: - - '7.4' - '8.0' - '8.1' - '8.2' @@ -39,31 +38,21 @@ jobs: symfony-require: [''] variant: [normal] include: - - php-version: '7.4' + - php-version: '8.0' dependencies: lowest allowed-to-fail: false variant: normal - - php-version: '8.1' + - php-version: '8.2' dependencies: highest allowed-to-fail: false symfony-require: 4.4.* variant: symfony/symfony:"4.4.*" - - php-version: '8.1' + - php-version: '8.2' dependencies: highest allowed-to-fail: false symfony-require: 5.4.* variant: symfony/symfony:"5.4.*" - - php-version: '8.1' - dependencies: highest - allowed-to-fail: false - symfony-require: 6.0.* - variant: symfony/symfony:"6.0.*" - - php-version: '8.1' - dependencies: highest - allowed-to-fail: false - symfony-require: 6.1.* - variant: symfony/symfony:"6.1.*" - - php-version: '8.1' + - php-version: '8.2' dependencies: highest allowed-to-fail: false symfony-require: 6.2.* diff --git a/Makefile b/Makefile index 6f553c20b..420682c4d 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ phpstan: .PHONY: phpstan psalm: - vendor/bin/psalm --php-version=8.1 + vendor/bin/psalm --php-version=8.2 .PHONY: psalm rector: diff --git a/rector.php b/rector.php index 50dc51733..6454e91a6 100644 --- a/rector.php +++ b/rector.php @@ -29,7 +29,7 @@ ]); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_74, + LevelSetList::UP_TO_PHP_80, ]); $rectorConfig->importNames(); From 85dea58e8dba4e9aeaa8c3db8cde29e70e78edac Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 17:23:53 +0000 Subject: [PATCH 2/9] Fix builds --- composer.json | 53 +++++++++---------- phpstan-baseline.neon | 16 ++++++ psalm.xml | 2 +- src/Admin/BaseBlockAdmin.php | 8 +-- src/Admin/BlockAdmin.php | 18 ++----- .../CreateSnapshotAdminExtension.php | 5 +- src/Admin/PageAdmin.php | 13 ++--- src/Admin/SiteAdmin.php | 6 +-- src/Admin/SnapshotAdmin.php | 16 ++---- src/Block/BreadcrumbBlockService.php | 6 +-- src/Block/ChildrenPagesBlockService.php | 21 ++------ src/Block/ContainerBlockService.php | 2 +- src/Block/PageListBlockService.php | 6 +-- src/Block/SharedBlockBlockService.php | 17 +----- src/CmsManager/CmsManagerSelector.php | 28 ++-------- src/CmsManager/CmsPageManager.php | 18 +++---- src/CmsManager/CmsSnapshotManager.php | 14 ++--- src/CmsManager/DecoratorStrategy.php | 26 ++------- src/Command/CleanupSnapshotsCommand.php | 11 +--- src/Command/CloneSiteCommand.php | 16 ++---- src/Command/CreateBlockContainerCommand.php | 13 ++--- src/Command/CreateSiteCommand.php | 6 +-- src/Command/CreateSnapshotsCommand.php | 13 ++--- src/Command/UpdateCoreRoutesCommand.php | 11 +--- src/Controller/BlockAdminController.php | 4 +- src/Controller/PageAdminController.php | 2 +- src/Controller/PageController.php | 15 ++---- src/Entity/BlockInteractor.php | 12 ++--- src/Entity/PageManager.php | 24 ++------- src/Entity/SnapshotManager.php | 6 +-- src/Entity/Transformer.php | 23 ++------ src/Form/Type/PageSelectorType.php | 19 +++++-- src/Form/Type/PageTypeChoiceType.php | 7 ++- src/Form/Type/TemplateChoiceType.php | 7 ++- src/Listener/ExceptionListener.php | 47 ++++------------ src/Listener/RequestListener.php | 17 ++---- src/Listener/ResponseListener.php | 25 ++------- src/Model/Page.php | 16 +++--- src/Model/PageInterface.php | 5 +- src/Model/Site.php | 2 +- src/Model/Snapshot.php | 2 +- src/Model/SnapshotChildrenCollection.php | 12 ++--- src/Model/SnapshotPageProxy.php | 19 ++----- src/Model/SnapshotPageProxyFactory.php | 8 +-- src/Model/Template.php | 14 ++--- src/Page/Service/BasePageService.php | 8 +-- src/Page/Service/DefaultPageService.php | 11 +--- src/Page/TemplateManager.php | 15 ++---- src/Request/SiteRequestContext.php | 6 +-- src/Route/CmsPageRouter.php | 29 +++------- src/Route/RoutePageGenerator.php | 22 ++------ src/Service/CleanupSnapshotService.php | 12 ++--- src/Service/CreateSnapshotService.php | 15 ++---- src/Site/BaseSiteSelector.php | 15 ++---- src/Twig/Extension/PageExtension.php | 41 ++++---------- src/Twig/GlobalVariables.php | 20 ++----- src/Validator/UniqueUrlValidator.php | 5 +- tests/App/AppKernel.php | 5 +- tests/App/Entity/SonataPageBlock.php | 25 ++++----- tests/App/Entity/SonataPagePage.php | 25 ++++----- tests/App/Entity/SonataPageSite.php | 25 ++++----- tests/App/Entity/SonataPageSnapshot.php | 22 +++----- tests/App/config/config_symfony_v6.yaml | 3 ++ tests/App/config/doctrine.yaml | 2 +- .../Snapshot/SnapshotManagerTest.php | 1 - tests/Page/Service/DefaultPageServiceTest.php | 8 +-- 66 files changed, 279 insertions(+), 667 deletions(-) create mode 100644 tests/App/config/config_symfony_v6.yaml diff --git a/composer.json b/composer.json index 255fc936c..ccb8989aa 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ ], "homepage": "https://docs.sonata-project.org/projects/SonataPageBundle", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "cocur/slugify": "^4.0", - "doctrine/doctrine-bundle": "^2.5", - "doctrine/persistence": "^2.1 || ^3.0", + "doctrine/doctrine-bundle": "^2.7", + "doctrine/persistence": "^3.0", "sonata-project/admin-bundle": "^4.19", "sonata-project/block-bundle": "^4.18", "sonata-project/doctrine-extensions": "^1.18 || ^2.1", @@ -33,27 +33,26 @@ "sonata-project/seo-bundle": "^3.4", "sonata-project/twig-extensions": "^1.3 || ^2.0", "symfony-cmf/routing-bundle": "^2.1 || ^3.0", - "symfony/config": "^4.4 || ^5.4 || ^6.0", - "symfony/console": "^4.4 || ^5.4 || ^6.0", - "symfony/dependency-injection": "^4.4.3 || ^5.4 || ^6.0", - "symfony/form": "^4.4 || ^5.4 || ^6.0", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", - "symfony/http-foundation": "^4.4 || ^5.4 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", - "symfony/intl": "^4.4 || ^5.4 || ^6.0", - "symfony/options-resolver": "^4.4 || ^5.4 || ^6.0", - "symfony/process": "^4.4 || ^5.4 || ^6.0", - "symfony/routing": "^4.4 || ^5.4 || ^6.0", - "symfony/security-core": "^4.4 || ^5.4 || ^6.0", - "symfony/security-http": "^4.4 || ^5.4 || ^6.0", - "symfony/serializer": "^4.4 || ^5.4 || ^6.0", - "symfony/validator": "^4.4 || ^5.4 || ^6.0", + "symfony/config": "^4.4 || ^5.4 || ^6.2", + "symfony/console": "^4.4 || ^5.4 || ^6.2", + "symfony/dependency-injection": "^4.4.3 || ^5.4 || ^6.2", + "symfony/form": "^4.4 || ^5.4 || ^6.2", + "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2", + "symfony/http-foundation": "^4.4 || ^5.4 || ^6.2", + "symfony/http-kernel": "^4.4 || ^5.4 || ^6.2", + "symfony/intl": "^4.4 || ^5.4 || ^6.2", + "symfony/options-resolver": "^4.4 || ^5.4 || ^6.2", + "symfony/process": "^4.4 || ^5.4 || ^6.2", + "symfony/routing": "^4.4 || ^5.4 || ^6.2", + "symfony/security-core": "^4.4 || ^5.4 || ^6.2", + "symfony/security-http": "^4.4 || ^5.4 || ^6.2", + "symfony/serializer": "^4.4 || ^5.4 || ^6.2", + "symfony/validator": "^4.4 || ^5.4 || ^6.2", "twig/string-extra": "^3.0", "twig/twig": "^2.12.1 || ^3.0" }, "require-dev": { "dama/doctrine-test-bundle": "^6.7", - "doctrine/annotations": "^1.13.3", "friendsofphp/php-cs-fixer": "^3.4", "masterminds/html5": "^2.7", "matthiasnoback/symfony-dependency-injection-test": "^4.1.1", @@ -63,18 +62,18 @@ "phpstan/phpstan-strict-rules": "^1.3", "phpstan/phpstan-symfony": "^1.0", "phpunit/phpunit": "^9.5", - "psalm/plugin-phpunit": "^0.17", - "psalm/plugin-symfony": "^3.0", + "psalm/plugin-phpunit": "^0.18", + "psalm/plugin-symfony": "^4.0 || ^5.0", "rector/rector": "^0.15", - "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", - "symfony/css-selector": "^4.4 || ^5.4 || ^6.0", - "symfony/filesystem": "^4.4 || ^5.4 || ^6.0", + "symfony/browser-kit": "^4.4 || ^5.4 || ^6.2", + "symfony/css-selector": "^4.4 || ^5.4 || ^6.2", + "symfony/filesystem": "^4.4 || ^5.4 || ^6.2", "symfony/panther": "^1.0 || ^2.0", - "symfony/phpunit-bridge": "^6.1", - "vimeo/psalm": "^4.7.2" + "symfony/phpunit-bridge": "^6.2", + "vimeo/psalm": "^4.7.2 || ^5.0" }, "conflict": { - "doctrine/orm": "<2.10" + "doctrine/orm": "<2.14" }, "suggest": { "twig/extra-bundle": "Auto configures the Twig Intl extension" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cbfe1ac29..bdff63a9f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -6,3 +6,19 @@ parameters: - # https://github.com/phpstan/phpstan-strict-rules/issues/130 message: '#^Call to static method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#' path: tests/ + - # https://github.com/phpstan/phpstan-symfony/issues/322 + message: "#^Cannot call method getId\\(\\) on array\\\\|Sonata\\\\PageBundle\\\\Model\\\\PageInterface\\|Sonata\\\\PageBundle\\\\Model\\\\SiteInterface\\.$#" + count: 1 + path: src/Form/Type/PageSelectorType.php + - # https://github.com/phpstan/phpstan-symfony/issues/322 + message: "#^Only booleans are allowed in &&, array\\\\|Sonata\\\\PageBundle\\\\Model\\\\PageInterface\\|Sonata\\\\PageBundle\\\\Model\\\\SiteInterface\\|null given on the right side\\.$#" + count: 1 + path: src/Form/Type/PageSelectorType.php + - # https://github.com/phpstan/phpstan-symfony/issues/322 + message: "#^Parameter \\#2 \\$currentPage of method Sonata\\\\PageBundle\\\\Form\\\\Type\\\\PageSelectorType\\:\\:childWalker\\(\\) expects Sonata\\\\PageBundle\\\\Model\\\\PageInterface\\|null, array\\\\|Sonata\\\\PageBundle\\\\Model\\\\PageInterface\\|Sonata\\\\PageBundle\\\\Model\\\\SiteInterface\\|null given\\.$#" + count: 1 + path: src/Form/Type/PageSelectorType.php + - # https://github.com/phpstan/phpstan-symfony/issues/322 + message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, array\\\\|Sonata\\\\PageBundle\\\\Model\\\\PageInterface\\|Sonata\\\\PageBundle\\\\Model\\\\SiteInterface\\|null given\\.$#" + count: 1 + path: src/Form/Type/PageSelectorType.php diff --git a/psalm.xml b/psalm.xml index 0d58b13e2..abaf586a3 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,5 +1,5 @@ - + diff --git a/src/Admin/BaseBlockAdmin.php b/src/Admin/BaseBlockAdmin.php index a372f96b1..14e3958b7 100644 --- a/src/Admin/BaseBlockAdmin.php +++ b/src/Admin/BaseBlockAdmin.php @@ -31,8 +31,6 @@ */ abstract class BaseBlockAdmin extends AbstractAdmin { - protected BlockServiceManagerInterface $blockManager; - protected bool $inValidate = false; /** @@ -40,11 +38,9 @@ abstract class BaseBlockAdmin extends AbstractAdmin */ protected array $containerBlockTypes = []; - public function __construct(BlockServiceManagerInterface $blockManager) + public function __construct(protected BlockServiceManagerInterface $blockManager) { parent::__construct(); - - $this->blockManager = $blockManager; } /** @@ -143,7 +139,7 @@ private function loadBlockDefaults(PageBlockInterface $block): PageBlockInterfac try { $block->setSettings($resolver->resolve($block->getSettings())); - } catch (InvalidOptionsException $e) { + } catch (InvalidOptionsException) { // @TODO : add a logging error or a flash message } diff --git a/src/Admin/BlockAdmin.php b/src/Admin/BlockAdmin.php index ac2f94e86..11688f101 100644 --- a/src/Admin/BlockAdmin.php +++ b/src/Admin/BlockAdmin.php @@ -37,16 +37,6 @@ final class BlockAdmin extends BaseBlockAdmin { protected $classnameLabel = 'Block'; - /** - * @var array, - * }> - */ - private array $blocks; - /** * @param array, * }> $blocks */ - public function __construct(BlockServiceManagerInterface $blockManager, array $blocks = []) - { + public function __construct( + BlockServiceManagerInterface $blockManager, + private array $blocks = [] + ) { parent::__construct($blockManager); - - $this->blocks = $blocks; } protected function getAccessMapping(): array diff --git a/src/Admin/Extension/CreateSnapshotAdminExtension.php b/src/Admin/Extension/CreateSnapshotAdminExtension.php index 1faabf00d..c3262605f 100644 --- a/src/Admin/Extension/CreateSnapshotAdminExtension.php +++ b/src/Admin/Extension/CreateSnapshotAdminExtension.php @@ -24,11 +24,8 @@ */ final class CreateSnapshotAdminExtension extends AbstractAdminExtension { - private CreateSnapshotByPageInterface $createSnapshotByPage; - - public function __construct(CreateSnapshotByPageInterface $createSnapshotByPage) + public function __construct(private CreateSnapshotByPageInterface $createSnapshotByPage) { - $this->createSnapshotByPage = $createSnapshotByPage; } public function postUpdate(AdminInterface $admin, object $object): void diff --git a/src/Admin/PageAdmin.php b/src/Admin/PageAdmin.php index 75573818b..8cc6c48f3 100644 --- a/src/Admin/PageAdmin.php +++ b/src/Admin/PageAdmin.php @@ -45,18 +45,11 @@ final class PageAdmin extends AbstractAdmin { protected $classnameLabel = 'Page'; - private PageManagerInterface $pageManager; - - private SiteManagerInterface $siteManager; - public function __construct( - PageManagerInterface $pageManager, - SiteManagerInterface $siteManager + private PageManagerInterface $pageManager, + private SiteManagerInterface $siteManager ) { parent::__construct(); - - $this->pageManager = $pageManager; - $this->siteManager = $siteManager; } protected function configureRoutes(RouteCollectionInterface $collection): void @@ -380,7 +373,7 @@ protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminI 'path' => $path, ]), ]); - } catch (\Exception $e) { + } catch (\Exception) { // avoid crashing the admin if the route is not setup correctly // throw $e; } diff --git a/src/Admin/SiteAdmin.php b/src/Admin/SiteAdmin.php index e68c2d7c9..50efa3ac7 100644 --- a/src/Admin/SiteAdmin.php +++ b/src/Admin/SiteAdmin.php @@ -34,13 +34,9 @@ final class SiteAdmin extends AbstractAdmin { protected $classnameLabel = 'Site'; - private RoutePageGenerator $routePageGenerator; - - public function __construct(RoutePageGenerator $routePageGenerator) + public function __construct(private RoutePageGenerator $routePageGenerator) { parent::__construct(); - - $this->routePageGenerator = $routePageGenerator; } protected function postPersist(object $object): void diff --git a/src/Admin/SnapshotAdmin.php b/src/Admin/SnapshotAdmin.php index 82a8b5c6b..64003ef56 100644 --- a/src/Admin/SnapshotAdmin.php +++ b/src/Admin/SnapshotAdmin.php @@ -36,22 +36,12 @@ final class SnapshotAdmin extends AbstractAdmin { protected $classnameLabel = 'Snapshot'; - private TransformerInterface $transformer; - - private PageManagerInterface $pageManager; - - private SnapshotManagerInterface $snapshotManager; - public function __construct( - TransformerInterface $transformer, - PageManagerInterface $pageManager, - SnapshotManagerInterface $snapshotManager + private TransformerInterface $transformer, + private PageManagerInterface $pageManager, + private SnapshotManagerInterface $snapshotManager ) { parent::__construct(); - - $this->transformer = $transformer; - $this->pageManager = $pageManager; - $this->snapshotManager = $snapshotManager; } protected function getAccessMapping(): array diff --git a/src/Block/BreadcrumbBlockService.php b/src/Block/BreadcrumbBlockService.php index 97ac734d8..152d24174 100644 --- a/src/Block/BreadcrumbBlockService.php +++ b/src/Block/BreadcrumbBlockService.php @@ -32,16 +32,12 @@ */ final class BreadcrumbBlockService extends BaseBreadcrumbMenuBlockService implements EditableBlockService { - private CmsManagerSelectorInterface $cmsSelector; - public function __construct( Environment $twig, FactoryInterface $factory, - CmsManagerSelectorInterface $cmsSelector + private CmsManagerSelectorInterface $cmsSelector ) { parent::__construct($twig, $factory); - - $this->cmsSelector = $cmsSelector; } public function validate(ErrorElement $errorElement, BlockInterface $block): void diff --git a/src/Block/ChildrenPagesBlockService.php b/src/Block/ChildrenPagesBlockService.php index 162d92dfd..67782901c 100755 --- a/src/Block/ChildrenPagesBlockService.php +++ b/src/Block/ChildrenPagesBlockService.php @@ -45,29 +45,16 @@ */ final class ChildrenPagesBlockService extends AbstractBlockService implements EditableBlockService { - private SiteSelectorInterface $siteSelector; - - private CmsManagerSelectorInterface $cmsManagerSelector; - - /** - * @var AdminInterface - */ - private AdminInterface $pageAdmin; - /** * @param AdminInterface $pageAdmin */ public function __construct( Environment $twig, - SiteSelectorInterface $siteSelector, - CmsManagerSelectorInterface $cmsManagerSelector, - AdminInterface $pageAdmin + private SiteSelectorInterface $siteSelector, + private CmsManagerSelectorInterface $cmsManagerSelector, + private AdminInterface $pageAdmin ) { parent::__construct($twig); - - $this->siteSelector = $siteSelector; - $this->cmsManagerSelector = $cmsManagerSelector; - $this->pageAdmin = $pageAdmin; } public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response @@ -87,7 +74,7 @@ public function execute(BlockContextInterface $blockContext, ?Response $response if (null !== $site) { $page = $cmsManager->getPage($site, '/'); } - } catch (PageNotFoundException $e) { + } catch (PageNotFoundException) { } } diff --git a/src/Block/ContainerBlockService.php b/src/Block/ContainerBlockService.php index 48b31d714..ecb884407 100644 --- a/src/Block/ContainerBlockService.php +++ b/src/Block/ContainerBlockService.php @@ -118,7 +118,7 @@ public function getMetadata(): MetadataInterface private function getDecorator(string $layout): array { $key = '{{ CONTENT }}'; - if (false === strpos($layout, $key)) { + if (!str_contains($layout, $key)) { return []; } diff --git a/src/Block/PageListBlockService.php b/src/Block/PageListBlockService.php index 7ccc272f3..0c7dc3cd5 100755 --- a/src/Block/PageListBlockService.php +++ b/src/Block/PageListBlockService.php @@ -32,15 +32,11 @@ final class PageListBlockService extends AbstractBlockService implements EditableBlockService { - private PageManagerInterface $pageManager; - public function __construct( Environment $twig, - PageManagerInterface $pageManager + private PageManagerInterface $pageManager ) { parent::__construct($twig); - - $this->pageManager = $pageManager; } public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response diff --git a/src/Block/SharedBlockBlockService.php b/src/Block/SharedBlockBlockService.php index 707bb4aa7..b5f19f894 100755 --- a/src/Block/SharedBlockBlockService.php +++ b/src/Block/SharedBlockBlockService.php @@ -39,29 +39,16 @@ */ final class SharedBlockBlockService extends AbstractBlockService implements EditableBlockService { - /** - * @var ManagerInterface - */ - private ManagerInterface $blockManager; - - /** - * @var AdminInterface - */ - private AdminInterface $sharedBlockAdmin; - /** * @param ManagerInterface $blockManager * @param AdminInterface $sharedBlockAdmin */ public function __construct( Environment $twig, - ManagerInterface $blockManager, - AdminInterface $sharedBlockAdmin + private ManagerInterface $blockManager, + private AdminInterface $sharedBlockAdmin ) { parent::__construct($twig); - - $this->blockManager = $blockManager; - $this->sharedBlockAdmin = $sharedBlockAdmin; } public function execute(BlockContextInterface $blockContext, ?Response $response = null): Response diff --git a/src/CmsManager/CmsManagerSelector.php b/src/CmsManager/CmsManagerSelector.php index 63ae64a33..ea7875980 100644 --- a/src/CmsManager/CmsManagerSelector.php +++ b/src/CmsManager/CmsManagerSelector.php @@ -32,34 +32,16 @@ */ final class CmsManagerSelector implements CmsManagerSelectorInterface, BCLogoutHandlerInterface { - private CmsPageManager $cmsPageManager; - - private CmsSnapshotManager $cmsSnapshotManager; - - /** - * @var AdminInterface - */ - private AdminInterface $pageAdmin; - - private TokenStorageInterface $tokenStorage; - - private RequestStack $requestStack; - /** * @param AdminInterface $pageAdmin */ public function __construct( - CmsPageManager $cmsPageManager, - CmsSnapshotManager $cmsSnapshotManager, - AdminInterface $pageAdmin, - TokenStorageInterface $tokenStorage, - RequestStack $requestStack + private CmsPageManager $cmsPageManager, + private CmsSnapshotManager $cmsSnapshotManager, + private AdminInterface $pageAdmin, + private TokenStorageInterface $tokenStorage, + private RequestStack $requestStack ) { - $this->cmsPageManager = $cmsPageManager; - $this->cmsSnapshotManager = $cmsSnapshotManager; - $this->pageAdmin = $pageAdmin; - $this->tokenStorage = $tokenStorage; - $this->requestStack = $requestStack; } public function retrieve(): CmsManagerInterface diff --git a/src/CmsManager/CmsPageManager.php b/src/CmsManager/CmsPageManager.php index 22a8f9f77..0850f761a 100644 --- a/src/CmsManager/CmsPageManager.php +++ b/src/CmsManager/CmsPageManager.php @@ -25,10 +25,6 @@ */ final class CmsPageManager extends BaseCmsPageManager { - private BlockInteractorInterface $blockInteractor; - - private PageManagerInterface $pageManager; - /** * @var array{ * url: array, @@ -49,15 +45,15 @@ final class CmsPageManager extends BaseCmsPageManager */ private array $pages = []; - public function __construct(PageManagerInterface $pageManager, BlockInteractorInterface $blockInteractor) - { - $this->pageManager = $pageManager; - $this->blockInteractor = $blockInteractor; + public function __construct( + private PageManagerInterface $pageManager, + private BlockInteractorInterface $blockInteractor + ) { } public function getPage(SiteInterface $site, $page): PageInterface { - if (\is_string($page) && '/' === substr($page, 0, 1)) { + if (\is_string($page) && str_starts_with($page, '/')) { $page = $this->getPageByUrl($site, $page); } elseif (\is_string($page)) { // page is a slug, load the related page $page = $this->getPageByRouteName($site, $page); @@ -76,7 +72,7 @@ public function getPage(SiteInterface $site, $page): PageInterface public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface { - if ('error' === substr($routeName, 0, 5)) { + if (str_starts_with($routeName, 'error')) { throw new \RuntimeException(sprintf('Illegal internal route name : %s, an internal page cannot start with `error`', $routeName)); } @@ -84,7 +80,7 @@ public function getInternalRoute(SiteInterface $site, string $routeName): PageIn try { $page = $this->getPageByRouteName($site, $routeName); - } catch (PageNotFoundException $e) { + } catch (PageNotFoundException) { $page = $this->pageManager->createWithDefaults([ 'url' => null, 'routeName' => $routeName, diff --git a/src/CmsManager/CmsSnapshotManager.php b/src/CmsManager/CmsSnapshotManager.php index e26d2425d..8df9c1d79 100644 --- a/src/CmsManager/CmsSnapshotManager.php +++ b/src/CmsManager/CmsSnapshotManager.php @@ -26,10 +26,6 @@ */ final class CmsSnapshotManager extends BaseCmsPageManager { - private SnapshotManagerInterface $snapshotManager; - - private TransformerInterface $transformer; - /** * @var array{ * url: array, @@ -52,15 +48,15 @@ final class CmsSnapshotManager extends BaseCmsPageManager */ private array $pages = []; - public function __construct(SnapshotManagerInterface $snapshotManager, TransformerInterface $transformer) - { - $this->snapshotManager = $snapshotManager; - $this->transformer = $transformer; + public function __construct( + private SnapshotManagerInterface $snapshotManager, + private TransformerInterface $transformer + ) { } public function getPage(SiteInterface $site, $page): PageInterface { - if (\is_string($page) && '/' === substr($page, 0, 1)) { + if (\is_string($page) && str_starts_with($page, '/')) { $page = $this->getPageByUrl($site, $page); } elseif (\is_string($page)) { // page is a slug, load the related page $page = $this->getPageByRouteName($site, $page); diff --git a/src/CmsManager/DecoratorStrategy.php b/src/CmsManager/DecoratorStrategy.php index 39f755808..3aa949d22 100644 --- a/src/CmsManager/DecoratorStrategy.php +++ b/src/CmsManager/DecoratorStrategy.php @@ -22,34 +22,16 @@ */ final class DecoratorStrategy implements DecoratorStrategyInterface { - /** - * @var array - */ - private array $ignoreRoutes; - - /** - * @var array - */ - private array $ignoreRoutePatterns; - - /** - * @var array - */ - private array $ignoreUriPatterns; - /** * @param array $ignoreRoutes * @param array $ignoreRoutePatterns * @param array $ignoreUriPatterns */ public function __construct( - array $ignoreRoutes, - array $ignoreRoutePatterns, - array $ignoreUriPatterns + private array $ignoreRoutes, + private array $ignoreRoutePatterns, + private array $ignoreUriPatterns ) { - $this->ignoreRoutes = $ignoreRoutes; - $this->ignoreRoutePatterns = $ignoreRoutePatterns; - $this->ignoreUriPatterns = $ignoreUriPatterns; } public function isDecorable(Request $request, int $requestType, Response $response): bool @@ -61,7 +43,7 @@ public function isDecorable(Request $request, int $requestType, Response $respon return false; } - if ('text/html' !== substr($response->headers->get('Content-Type') ?? 'text/html', 0, 9)) { + if (!str_starts_with($response->headers->get('Content-Type') ?? 'text/html', 'text/html')) { return false; } diff --git a/src/Command/CleanupSnapshotsCommand.php b/src/Command/CleanupSnapshotsCommand.php index 5bd0f53f8..735ec37ed 100644 --- a/src/Command/CleanupSnapshotsCommand.php +++ b/src/Command/CleanupSnapshotsCommand.php @@ -29,18 +29,11 @@ final class CleanupSnapshotsCommand extends Command protected static $defaultName = 'sonata:page:cleanup-snapshots'; protected static $defaultDescription = 'Cleanups the deprecated snapshots by a given site'; - private CleanupSnapshotBySiteInterface $cleanupSnapshotBySite; - - private SiteManagerInterface $siteManager; - public function __construct( - CleanupSnapshotBySiteInterface $cleanupSnapshotBySite, - SiteManagerInterface $siteManager + private CleanupSnapshotBySiteInterface $cleanupSnapshotBySite, + private SiteManagerInterface $siteManager ) { parent::__construct(); - - $this->cleanupSnapshotBySite = $cleanupSnapshotBySite; - $this->siteManager = $siteManager; } public function configure(): void diff --git a/src/Command/CloneSiteCommand.php b/src/Command/CloneSiteCommand.php index e82f96405..19053bbe0 100644 --- a/src/Command/CloneSiteCommand.php +++ b/src/Command/CloneSiteCommand.php @@ -35,22 +35,12 @@ final class CloneSiteCommand extends Command protected static $defaultName = 'sonata:page:clone-site'; protected static $defaultDescription = 'Clone a complete site including all their pages'; - private SiteManagerInterface $siteManager; - - private PageManagerInterface $pageManager; - - private BlockManagerInterface $blockManager; - public function __construct( - SiteManagerInterface $siteManager, - PageManagerInterface $pageManager, - BlockManagerInterface $blockManager + private SiteManagerInterface $siteManager, + private PageManagerInterface $pageManager, + private BlockManagerInterface $blockManager ) { parent::__construct(); - - $this->siteManager = $siteManager; - $this->pageManager = $pageManager; - $this->blockManager = $blockManager; } public function configure(): void diff --git a/src/Command/CreateBlockContainerCommand.php b/src/Command/CreateBlockContainerCommand.php index c15e4e4e2..4194b37aa 100644 --- a/src/Command/CreateBlockContainerCommand.php +++ b/src/Command/CreateBlockContainerCommand.php @@ -33,16 +33,11 @@ final class CreateBlockContainerCommand extends Command protected static $defaultName = 'sonata:page:create-block-container'; protected static $defaultDescription = 'Creates a block container in all pages for specified template code'; - private PageManagerInterface $pageManager; - - private BlockInteractorInterface $blockInteractor; - - public function __construct(PageManagerInterface $pageManager, BlockInteractorInterface $blockInteractor) - { + public function __construct( + private PageManagerInterface $pageManager, + private BlockInteractorInterface $blockInteractor + ) { parent::__construct(); - - $this->pageManager = $pageManager; - $this->blockInteractor = $blockInteractor; } protected function configure(): void diff --git a/src/Command/CreateSiteCommand.php b/src/Command/CreateSiteCommand.php index c832f44f7..7beca497a 100644 --- a/src/Command/CreateSiteCommand.php +++ b/src/Command/CreateSiteCommand.php @@ -34,13 +34,9 @@ final class CreateSiteCommand extends Command protected static $defaultName = 'sonata:page:create-site'; protected static $defaultDescription = 'Create a site'; - private SiteManagerInterface $siteManager; - - public function __construct(SiteManagerInterface $siteManager) + public function __construct(private SiteManagerInterface $siteManager) { parent::__construct(); - - $this->siteManager = $siteManager; } public function configure(): void diff --git a/src/Command/CreateSnapshotsCommand.php b/src/Command/CreateSnapshotsCommand.php index 36708b3e3..9a5da1934 100644 --- a/src/Command/CreateSnapshotsCommand.php +++ b/src/Command/CreateSnapshotsCommand.php @@ -34,16 +34,11 @@ final class CreateSnapshotsCommand extends Command protected static $defaultName = 'sonata:page:create-snapshots'; protected static $defaultDescription = 'Create a snapshots of all pages available'; - private CreateSnapshotBySiteInterface $createSnapshot; - - private SiteManagerInterface $siteManager; - - public function __construct(CreateSnapshotBySiteInterface $createSnapshot, SiteManagerInterface $siteManager) - { + public function __construct( + private CreateSnapshotBySiteInterface $createSnapshot, + private SiteManagerInterface $siteManager + ) { parent::__construct(); - - $this->createSnapshot = $createSnapshot; - $this->siteManager = $siteManager; } public function configure(): void diff --git a/src/Command/UpdateCoreRoutesCommand.php b/src/Command/UpdateCoreRoutesCommand.php index 6dd426c92..b2e6125fc 100644 --- a/src/Command/UpdateCoreRoutesCommand.php +++ b/src/Command/UpdateCoreRoutesCommand.php @@ -34,18 +34,11 @@ final class UpdateCoreRoutesCommand extends Command protected static $defaultName = 'sonata:page:update-core-routes'; protected static $defaultDescription = 'Update core routes, from routing files to page manager'; - private SiteManagerInterface $siteManager; - - private RoutePageGenerator $pageGenerator; - public function __construct( - SiteManagerInterface $siteManager, - RoutePageGenerator $pageGenerator + private SiteManagerInterface $siteManager, + private RoutePageGenerator $pageGenerator ) { parent::__construct(); - - $this->siteManager = $siteManager; - $this->pageGenerator = $pageGenerator; } public function configure(): void diff --git a/src/Controller/BlockAdminController.php b/src/Controller/BlockAdminController.php index ef6679b8f..c5401f4df 100644 --- a/src/Controller/BlockAdminController.php +++ b/src/Controller/BlockAdminController.php @@ -64,14 +64,14 @@ public function savePositionAction(Request $request): Response } catch (HttpException $e) { $status = $e->getStatusCode(); $result = [ - 'exception' => \get_class($e), + 'exception' => $e::class, 'message' => $e->getMessage(), 'code' => $e->getCode(), ]; } catch (\Exception $e) { $status = 500; $result = [ - 'exception' => \get_class($e), + 'exception' => $e::class, 'message' => $e->getMessage(), 'code' => $e->getCode(), ]; diff --git a/src/Controller/PageAdminController.php b/src/Controller/PageAdminController.php index 591995720..c8b48ef5a 100644 --- a/src/Controller/PageAdminController.php +++ b/src/Controller/PageAdminController.php @@ -149,7 +149,7 @@ public function createAction(Request $request): Response $siteSelector = $this->container->get('sonata.page.site.selector'); \assert($siteSelector instanceof SiteSelectorInterface); $current = $siteSelector->retrieve(); - } catch (\RuntimeException $e) { + } catch (\RuntimeException) { $current = false; } diff --git a/src/Controller/PageController.php b/src/Controller/PageController.php index f8383fd48..a82b76b87 100644 --- a/src/Controller/PageController.php +++ b/src/Controller/PageController.php @@ -28,20 +28,11 @@ */ final class PageController extends AbstractController { - private ExceptionListener $exceptionListener; - - private PageServiceManagerInterface $pageServiceManager; - - private CmsManagerSelectorInterface $cmsSelector; - public function __construct( - ExceptionListener $exceptionListener, - PageServiceManagerInterface $pageServiceManager, - CmsManagerSelectorInterface $cmsSelector + private ExceptionListener $exceptionListener, + private PageServiceManagerInterface $pageServiceManager, + private CmsManagerSelectorInterface $cmsSelector ) { - $this->exceptionListener = $exceptionListener; - $this->pageServiceManager = $pageServiceManager; - $this->cmsSelector = $cmsSelector; } /** diff --git a/src/Entity/BlockInteractor.php b/src/Entity/BlockInteractor.php index 88775716f..1f3295545 100644 --- a/src/Entity/BlockInteractor.php +++ b/src/Entity/BlockInteractor.php @@ -30,14 +30,10 @@ final class BlockInteractor implements BlockInteractorInterface */ private array $pageBlocksLoaded = []; - private ManagerRegistry $registry; - - private BlockManagerInterface $blockManager; - - public function __construct(ManagerRegistry $registry, BlockManagerInterface $blockManager) - { - $this->blockManager = $blockManager; - $this->registry = $registry; + public function __construct( + private ManagerRegistry $registry, + private BlockManagerInterface $blockManager + ) { } public function getBlock($id): ?PageBlockInterface diff --git a/src/Entity/PageManager.php b/src/Entity/PageManager.php index 59550f596..80b98124f 100644 --- a/src/Entity/PageManager.php +++ b/src/Entity/PageManager.php @@ -27,18 +27,6 @@ */ final class PageManager extends BaseEntityManager implements PageManagerInterface { - private SlugifyInterface $slugify; - - /** - * @var array - */ - private array $pageDefaults; - - /** - * @var array - */ - private array $defaults; - /** * @param class-string $class * @param array $defaults @@ -47,15 +35,11 @@ final class PageManager extends BaseEntityManager implements PageManagerInterfac public function __construct( string $class, ManagerRegistry $registry, - SlugifyInterface $slugify, - array $defaults = [], - array $pageDefaults = [] + private SlugifyInterface $slugify, + private array $defaults = [], + private array $pageDefaults = [] ) { parent::__construct($class, $registry); - - $this->slugify = $slugify; - $this->defaults = $defaults; - $this->pageDefaults = $pageDefaults; } public function getPageByUrl(SiteInterface $site, string $url): ?PageInterface @@ -112,7 +96,7 @@ public function fixUrl(PageInterface $page): void if ('/' === $parentUrl) { $base = '/'; - } elseif ('/' !== substr($parentUrl ?? '', -1)) { + } elseif (!str_ends_with($parentUrl ?? '', '/')) { $base = $parentUrl.'/'; } else { $base = $parentUrl; diff --git a/src/Entity/SnapshotManager.php b/src/Entity/SnapshotManager.php index d77c951e4..089099ca0 100644 --- a/src/Entity/SnapshotManager.php +++ b/src/Entity/SnapshotManager.php @@ -30,19 +30,15 @@ */ final class SnapshotManager extends BaseEntityManager implements SnapshotManagerInterface { - private SnapshotPageProxyFactoryInterface $snapshotPageProxyFactory; - /** * @param class-string $class */ public function __construct( string $class, ManagerRegistry $registry, - SnapshotPageProxyFactoryInterface $snapshotPageProxyFactory + private SnapshotPageProxyFactoryInterface $snapshotPageProxyFactory ) { parent::__construct($class, $registry); - - $this->snapshotPageProxyFactory = $snapshotPageProxyFactory; } public function enableSnapshots(array $snapshots, ?\DateTimeInterface $date = null): void diff --git a/src/Entity/Transformer.php b/src/Entity/Transformer.php index b671545a4..b304279d5 100644 --- a/src/Entity/Transformer.php +++ b/src/Entity/Transformer.php @@ -34,35 +34,20 @@ */ final class Transformer implements TransformerInterface { - private SnapshotManagerInterface $snapshotManager; - - private PageManagerInterface $pageManager; - - /** - * @var ManagerInterface - */ - private ManagerInterface $blockManager; - /** * @var array> */ private array $children = []; - private ManagerRegistry $registry; - /** * @param ManagerInterface $blockManager */ public function __construct( - SnapshotManagerInterface $snapshotManager, - PageManagerInterface $pageManager, - ManagerInterface $blockManager, - ManagerRegistry $registry + private SnapshotManagerInterface $snapshotManager, + private PageManagerInterface $pageManager, + private ManagerInterface $blockManager, + private ManagerRegistry $registry ) { - $this->snapshotManager = $snapshotManager; - $this->pageManager = $pageManager; - $this->blockManager = $blockManager; - $this->registry = $registry; } public function create(PageInterface $page, ?SnapshotInterface $snapshot = null): SnapshotInterface diff --git a/src/Form/Type/PageSelectorType.php b/src/Form/Type/PageSelectorType.php index df25a3382..f8025fd62 100644 --- a/src/Form/Type/PageSelectorType.php +++ b/src/Form/Type/PageSelectorType.php @@ -23,14 +23,13 @@ /** * @author Thomas Rabaix + * + * @psalm-suppress MissingTemplateParam */ final class PageSelectorType extends AbstractType { - private PageManagerInterface $manager; - - public function __construct(PageManagerInterface $manager) + public function __construct(private PageManagerInterface $manager) { - $this->manager = $manager; } public function configureOptions(OptionsResolver $resolver): void @@ -63,6 +62,18 @@ public function getBlockPrefix(): string /** * @return array + * + * @phpstan-param Options $options + * @psalm-param Options $options */ private function getChoices(Options $options): array { diff --git a/src/Form/Type/PageTypeChoiceType.php b/src/Form/Type/PageTypeChoiceType.php index b92dc43b5..4de2f5dfc 100644 --- a/src/Form/Type/PageTypeChoiceType.php +++ b/src/Form/Type/PageTypeChoiceType.php @@ -20,14 +20,13 @@ /** * @author Olivier Paradis + * + * @psalm-suppress MissingTemplateParam */ final class PageTypeChoiceType extends AbstractType { - private PageServiceManagerInterface $manager; - - public function __construct(PageServiceManagerInterface $manager) + public function __construct(private PageServiceManagerInterface $manager) { - $this->manager = $manager; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Form/Type/TemplateChoiceType.php b/src/Form/Type/TemplateChoiceType.php index a5b7e48be..b1ddf9748 100644 --- a/src/Form/Type/TemplateChoiceType.php +++ b/src/Form/Type/TemplateChoiceType.php @@ -20,14 +20,13 @@ /** * @author Thomas Rabaix + * + * @psalm-suppress MissingTemplateParam */ final class TemplateChoiceType extends AbstractType { - private TemplateManagerInterface $manager; - - public function __construct(TemplateManagerInterface $manager) + public function __construct(private TemplateManagerInterface $manager) { - $this->manager = $manager; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Listener/ExceptionListener.php b/src/Listener/ExceptionListener.php index 6a3a0db00..71775d78d 100644 --- a/src/Listener/ExceptionListener.php +++ b/src/Listener/ExceptionListener.php @@ -32,50 +32,23 @@ */ final class ExceptionListener { - private SiteSelectorInterface $siteSelector; - - private CmsManagerSelectorInterface $cmsManagerSelector; - - private bool $debug; - - private Environment $twig; - - private PageServiceManagerInterface $pageServiceManager; - - private DecoratorStrategyInterface $decoratorStrategy; - - /** - * @var array - */ - private array $httpErrorCodes; - private LoggerInterface $logger; - private bool $status; - /** * @param array $httpErrorCodes An array of http error code routes */ public function __construct( - SiteSelectorInterface $siteSelector, - CmsManagerSelectorInterface $cmsManagerSelector, - bool $debug, - Environment $twig, - PageServiceManagerInterface $pageServiceManager, - DecoratorStrategyInterface $decoratorStrategy, - array $httpErrorCodes, + private SiteSelectorInterface $siteSelector, + private CmsManagerSelectorInterface $cmsManagerSelector, + private bool $debug, + private Environment $twig, + private PageServiceManagerInterface $pageServiceManager, + private DecoratorStrategyInterface $decoratorStrategy, + private array $httpErrorCodes, ?LoggerInterface $logger = null, - bool $status = false + private bool $status = false ) { - $this->siteSelector = $siteSelector; - $this->cmsManagerSelector = $cmsManagerSelector; - $this->debug = $debug; - $this->twig = $twig; - $this->pageServiceManager = $pageServiceManager; - $this->decoratorStrategy = $decoratorStrategy; - $this->httpErrorCodes = $httpErrorCodes; $this->logger = $logger ?? new NullLogger(); - $this->status = $status; } /** @@ -189,7 +162,7 @@ private function handleNativeError(ExceptionEvent $event): void return; } - $message = sprintf('%s: %s (uncaught exception) at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()); + $message = sprintf('%s: %s (uncaught exception) at %s line %s', $exception::class, $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->logException($exception, $exception, $message); @@ -228,7 +201,7 @@ private function handleNativeError(ExceptionEvent $event): void private function logException(\Throwable $originalException, \Throwable $generatedException, ?string $message = null): void { if (null === $message) { - $message = sprintf('Exception thrown when handling an exception (%s: %s)', \get_class($generatedException), $generatedException->getMessage()); + $message = sprintf('Exception thrown when handling an exception (%s: %s)', $generatedException::class, $generatedException->getMessage()); } if (!$originalException instanceof HttpExceptionInterface || $originalException->getStatusCode() >= 500) { diff --git a/src/Listener/RequestListener.php b/src/Listener/RequestListener.php index c72a224a3..7f64550e0 100644 --- a/src/Listener/RequestListener.php +++ b/src/Listener/RequestListener.php @@ -29,20 +29,11 @@ */ final class RequestListener { - private CmsManagerSelectorInterface $cmsSelector; - - private SiteSelectorInterface $siteSelector; - - private DecoratorStrategyInterface $decoratorStrategy; - public function __construct( - CmsManagerSelectorInterface $cmsSelector, - SiteSelectorInterface $siteSelector, - DecoratorStrategyInterface $decoratorStrategy + private CmsManagerSelectorInterface $cmsSelector, + private SiteSelectorInterface $siteSelector, + private DecoratorStrategyInterface $decoratorStrategy ) { - $this->cmsSelector = $cmsSelector; - $this->siteSelector = $siteSelector; - $this->decoratorStrategy = $decoratorStrategy; } /** @@ -83,7 +74,7 @@ public function onCoreRequest(RequestEvent $event): void } $cms->setCurrentPage($page); - } catch (PageNotFoundException $e) { + } catch (PageNotFoundException) { return; } } diff --git a/src/Listener/ResponseListener.php b/src/Listener/ResponseListener.php index 0abee0c6a..aea98787b 100644 --- a/src/Listener/ResponseListener.php +++ b/src/Listener/ResponseListener.php @@ -30,28 +30,13 @@ */ final class ResponseListener { - private CmsManagerSelectorInterface $cmsSelector; - - private PageServiceManagerInterface $pageServiceManager; - - private DecoratorStrategyInterface $decoratorStrategy; - - private Environment $twig; - - private bool $skipRedirection; - public function __construct( - CmsManagerSelectorInterface $cmsSelector, - PageServiceManagerInterface $pageServiceManager, - DecoratorStrategyInterface $decoratorStrategy, - Environment $twig, - bool $skipRedirection + private CmsManagerSelectorInterface $cmsSelector, + private PageServiceManagerInterface $pageServiceManager, + private DecoratorStrategyInterface $decoratorStrategy, + private Environment $twig, + private bool $skipRedirection ) { - $this->cmsSelector = $cmsSelector; - $this->pageServiceManager = $pageServiceManager; - $this->decoratorStrategy = $decoratorStrategy; - $this->twig = $twig; - $this->skipRedirection = $skipRedirection; } /** diff --git a/src/Model/Page.php b/src/Model/Page.php index 9dd53f1a8..83de6ec06 100755 --- a/src/Model/Page.php +++ b/src/Model/Page.php @@ -145,7 +145,7 @@ public function getPageAlias(): ?string public function setPageAlias(?string $pageAlias): void { - if ('_page_alias_' !== substr((string) $pageAlias, 0, 12)) { + if (!str_starts_with((string) $pageAlias, '_page_alias_')) { $pageAlias = '_page_alias_'.$pageAlias; } @@ -418,7 +418,7 @@ public function hasRequestMethod(string $method): bool $requestMethod = $this->getRequestMethod(); - return null === $requestMethod || false !== strpos($requestMethod, $method); + return null === $requestMethod || str_contains($requestMethod, $method); } public function getHeaders(): array @@ -442,7 +442,7 @@ public function setHeaders(array $headers = []): void } } - public function addHeader(string $name, $value): void + public function addHeader(string $name, mixed $value): void { $headers = $this->getHeaders(); @@ -507,7 +507,7 @@ public function addSnapshot(SnapshotInterface $snapshot): void public function isError(): bool { - return '_page_internal_error_' === substr($this->getRouteName() ?? '', 0, 21); + return str_starts_with($this->getRouteName() ?? '', '_page_internal_error_'); } public function isHybrid(): bool @@ -517,7 +517,7 @@ public function isHybrid(): bool public function isDynamic(): bool { - return $this->isHybrid() && false !== strpos($this->getUrl() ?? '', '{'); + return $this->isHybrid() && str_contains($this->getUrl() ?? '', '{'); } public function isCms(): bool @@ -527,18 +527,20 @@ public function isCms(): bool public function isInternal(): bool { - return '_page_internal_' === substr($this->getRouteName() ?? '', 0, 15); + return str_starts_with($this->getRouteName() ?? '', '_page_internal_'); } /** * @return array + * + * @psalm-suppress PossiblyUndefinedArrayOffset */ private function getHeadersAsArray(string $rawHeaders): array { $headers = []; foreach (explode("\r\n", $rawHeaders) as $header) { - if (false !== strpos($header, ':')) { + if (str_contains($header, ':')) { [$name, $headerStr] = explode(':', $header, 2); $headers[trim($name)] = trim($headerStr); } diff --git a/src/Model/PageInterface.php b/src/Model/PageInterface.php index 04a502ebf..41f20e766 100644 --- a/src/Model/PageInterface.php +++ b/src/Model/PageInterface.php @@ -172,10 +172,7 @@ public function getHeaders(): array; */ public function setHeaders(array $headers = []): void; - /** - * @param mixed $value - */ - public function addHeader(string $name, $value): void; + public function addHeader(string $name, mixed $value): void; public function getRawHeaders(): ?string; diff --git a/src/Model/Site.php b/src/Model/Site.php index a57cbb4f0..48cf47e1a 100644 --- a/src/Model/Site.php +++ b/src/Model/Site.php @@ -16,7 +16,7 @@ /** * @author Thomas Rabaix */ -abstract class Site implements SiteInterface +abstract class Site implements SiteInterface, \Stringable { /** * @var int|string|null diff --git a/src/Model/Snapshot.php b/src/Model/Snapshot.php index b54e71beb..5044d41f5 100644 --- a/src/Model/Snapshot.php +++ b/src/Model/Snapshot.php @@ -18,7 +18,7 @@ * * @phpstan-import-type PageContent from TransformerInterface */ -abstract class Snapshot implements SnapshotInterface +abstract class Snapshot implements SnapshotInterface, \Stringable { /** * @var int|string|null diff --git a/src/Model/SnapshotChildrenCollection.php b/src/Model/SnapshotChildrenCollection.php index 851831267..cba3aa96f 100644 --- a/src/Model/SnapshotChildrenCollection.php +++ b/src/Model/SnapshotChildrenCollection.php @@ -26,14 +26,10 @@ */ final class SnapshotChildrenCollection extends AbstractLazyCollection { - private TransformerInterface $transformer; - - private PageInterface $page; - - public function __construct(TransformerInterface $transformer, PageInterface $page) - { - $this->transformer = $transformer; - $this->page = $page; + public function __construct( + private TransformerInterface $transformer, + private PageInterface $page + ) { } protected function doInitialize(): void diff --git a/src/Model/SnapshotPageProxy.php b/src/Model/SnapshotPageProxy.php index 4dbc4cbd8..65b6ce9d0 100644 --- a/src/Model/SnapshotPageProxy.php +++ b/src/Model/SnapshotPageProxy.php @@ -20,12 +20,6 @@ */ final class SnapshotPageProxy implements SnapshotPageProxyInterface { - private SnapshotManagerInterface $manager; - - private TransformerInterface $transformer; - - private SnapshotInterface $snapshot; - private ?PageInterface $page = null; /** @@ -34,13 +28,10 @@ final class SnapshotPageProxy implements SnapshotPageProxyInterface private ?array $parents = null; public function __construct( - SnapshotManagerInterface $manager, - TransformerInterface $transformer, - SnapshotInterface $snapshot + private SnapshotManagerInterface $manager, + private TransformerInterface $transformer, + private SnapshotInterface $snapshot ) { - $this->manager = $manager; - $this->snapshot = $snapshot; - $this->transformer = $transformer; } public function __toString(): string @@ -321,7 +312,7 @@ public function getParents(): array $snapshot = $this->snapshot; - while ($snapshot) { + while (true) { $content = $snapshot->getContent(); if (!isset($content['parent_id'])) { @@ -405,7 +396,7 @@ public function setHeaders(array $headers = []): void $this->getPage()->setHeaders($headers); } - public function addHeader(string $name, $value): void + public function addHeader(string $name, mixed $value): void { $this->getPage()->addHeader($name, $value); } diff --git a/src/Model/SnapshotPageProxyFactory.php b/src/Model/SnapshotPageProxyFactory.php index c0e309e83..0da8b1cdd 100644 --- a/src/Model/SnapshotPageProxyFactory.php +++ b/src/Model/SnapshotPageProxyFactory.php @@ -15,17 +15,11 @@ final class SnapshotPageProxyFactory implements SnapshotPageProxyFactoryInterface { - /** - * @var class-string - */ - private string $snapshotPageProxyClass; - /** * @param class-string $snapshotPageProxyClass */ - public function __construct(string $snapshotPageProxyClass) + public function __construct(private string $snapshotPageProxyClass) { - $this->snapshotPageProxyClass = $snapshotPageProxyClass; } public function create( diff --git a/src/Model/Template.php b/src/Model/Template.php index 70afd678d..86fa10eb7 100644 --- a/src/Model/Template.php +++ b/src/Model/Template.php @@ -33,10 +33,6 @@ final class Template public const TYPE_STATIC = 1; public const TYPE_DYNAMIC = 2; - private string $path; - - private string $name; - /** * @var array * @@ -53,11 +49,11 @@ final class Template * shared?: bool * }> $containers */ - public function __construct(string $name, string $path, array $containers = []) - { - $this->name = $name; - $this->path = $path; - + public function __construct( + private string $name, + private string $path, + array $containers = [] + ) { foreach ($containers as $code => $container) { $this->containers[$code] = $this->normalize($container); } diff --git a/src/Page/Service/BasePageService.php b/src/Page/Service/BasePageService.php index 14c22fd58..fab59e9a3 100644 --- a/src/Page/Service/BasePageService.php +++ b/src/Page/Service/BasePageService.php @@ -18,14 +18,8 @@ */ abstract class BasePageService implements PageServiceInterface { - /** - * Page service name used in the admin. - */ - protected string $name; - - public function __construct(string $name) + public function __construct(protected string $name) { - $this->name = $name; } public function getName(): string diff --git a/src/Page/Service/DefaultPageService.php b/src/Page/Service/DefaultPageService.php index a85904987..7d21b2a03 100644 --- a/src/Page/Service/DefaultPageService.php +++ b/src/Page/Service/DefaultPageService.php @@ -24,19 +24,12 @@ */ final class DefaultPageService extends BasePageService { - private TemplateManagerInterface $templateManager; - - private ?SeoPageInterface $seoPage; - public function __construct( string $name, - TemplateManagerInterface $templateManager, - ?SeoPageInterface $seoPage = null + private TemplateManagerInterface $templateManager, + private ?SeoPageInterface $seoPage = null ) { parent::__construct($name); - - $this->templateManager = $templateManager; - $this->seoPage = $seoPage; } public function execute( diff --git a/src/Page/TemplateManager.php b/src/Page/TemplateManager.php index b1a6e4ac3..eaaf61a04 100644 --- a/src/Page/TemplateManager.php +++ b/src/Page/TemplateManager.php @@ -25,13 +25,6 @@ */ final class TemplateManager implements TemplateManagerInterface { - private Environment $twig; - - /** - * @var array - */ - private array $defaultParameters; - /** * @var array */ @@ -44,10 +37,10 @@ final class TemplateManager implements TemplateManagerInterface /** * @param array $defaultParameters */ - public function __construct(Environment $twig, array $defaultParameters = []) - { - $this->twig = $twig; - $this->defaultParameters = $defaultParameters; + public function __construct( + private Environment $twig, + private array $defaultParameters = [] + ) { } public function add(string $code, Template $template): void diff --git a/src/Request/SiteRequestContext.php b/src/Request/SiteRequestContext.php index 2f906ac12..e4131a5d2 100644 --- a/src/Request/SiteRequestContext.php +++ b/src/Request/SiteRequestContext.php @@ -22,12 +22,10 @@ */ final class SiteRequestContext extends RequestContext implements SiteRequestContextInterface { - private SiteSelectorInterface $selector; - private ?SiteInterface $site = null; public function __construct( - SiteSelectorInterface $selector, + private SiteSelectorInterface $selector, string $baseUrl = '', string $method = 'GET', string $host = 'localhost', @@ -35,8 +33,6 @@ public function __construct( int $httpPort = 80, int $httpsPort = 443 ) { - $this->selector = $selector; - parent::__construct($baseUrl, $method, $host, $scheme, $httpPort, $httpsPort); } diff --git a/src/Route/CmsPageRouter.php b/src/Route/CmsPageRouter.php index 36d5cdc1b..120d789b3 100644 --- a/src/Route/CmsPageRouter.php +++ b/src/Route/CmsPageRouter.php @@ -29,24 +29,12 @@ final class CmsPageRouter implements ChainedRouterInterface { - private RequestContext $context; - - private CmsManagerSelectorInterface $cmsSelector; - - private SiteSelectorInterface $siteSelector; - - private RouterInterface $router; - public function __construct( - RequestContext $context, - CmsManagerSelectorInterface $cmsSelector, - SiteSelectorInterface $siteSelector, - RouterInterface $router + private RequestContext $context, + private CmsManagerSelectorInterface $cmsSelector, + private SiteSelectorInterface $siteSelector, + private RouterInterface $router ) { - $this->context = $context; - $this->cmsSelector = $cmsSelector; - $this->siteSelector = $siteSelector; - $this->router = $router; } public function setContext(RequestContext $context): void @@ -64,10 +52,7 @@ public function getRouteCollection(): RouteCollection return new RouteCollection(); } - /** - * @param mixed $name - */ - public function supports($name): bool + public function supports(mixed $name): bool { if (\is_string($name) && !$this->isPageAlias($name) && !$this->isPageSlug($name)) { return false; @@ -105,7 +90,7 @@ public function generate($name, $parameters = [], $referenceType = self::ABSOLUT if (null === $url) { throw new RouteNotFoundException('The Sonata CmsPageRouter cannot find url'); } - } catch (PageNotFoundException $exception) { + } catch (PageNotFoundException) { throw new RouteNotFoundException('The Sonata CmsPageRouter cannot find page'); } @@ -286,7 +271,7 @@ private function getPageByPageAlias(string $alias): ?PageInterface private function isPageAlias(string $name): bool { - return '_page_alias_' === substr($name, 0, 12); + return str_starts_with($name, '_page_alias_'); } private function isPageSlug(string $name): bool diff --git a/src/Route/RoutePageGenerator.php b/src/Route/RoutePageGenerator.php index cda6e6da9..6a99b90ec 100644 --- a/src/Route/RoutePageGenerator.php +++ b/src/Route/RoutePageGenerator.php @@ -26,24 +26,12 @@ */ final class RoutePageGenerator { - private RouterInterface $router; - - private PageManagerInterface $pageManager; - - private DecoratorStrategyInterface $decoratorStrategy; - - private ExceptionListener $exceptionListener; - public function __construct( - RouterInterface $router, - PageManagerInterface $pageManager, - DecoratorStrategyInterface $decoratorStrategy, - ExceptionListener $exceptionListener + private RouterInterface $router, + private PageManagerInterface $pageManager, + private DecoratorStrategyInterface $decoratorStrategy, + private ExceptionListener $exceptionListener ) { - $this->router = $router; - $this->pageManager = $pageManager; - $this->decoratorStrategy = $decoratorStrategy; - $this->exceptionListener = $exceptionListener; } public function update(SiteInterface $site, ?OutputInterface $output = null, bool $clean = false): void @@ -206,7 +194,7 @@ public function update(SiteInterface $site, ?OutputInterface $output = null, boo /** * @param string|iterable $message A string message to output */ - private function writeln(?OutputInterface $output, $message): void + private function writeln(?OutputInterface $output, string|iterable $message): void { if (null !== $output) { $output->writeln($message); diff --git a/src/Service/CleanupSnapshotService.php b/src/Service/CleanupSnapshotService.php index 60043d651..adfd77cb5 100644 --- a/src/Service/CleanupSnapshotService.php +++ b/src/Service/CleanupSnapshotService.php @@ -21,14 +21,10 @@ final class CleanupSnapshotService implements CleanupSnapshotBySiteInterface { - private SnapshotManagerInterface $snapshotManager; - - private PageManagerInterface $pageManager; - - public function __construct(SnapshotManagerInterface $snapshotManager, PageManagerInterface $pageManager) - { - $this->snapshotManager = $snapshotManager; - $this->pageManager = $pageManager; + public function __construct( + private SnapshotManagerInterface $snapshotManager, + private PageManagerInterface $pageManager + ) { } public function cleanupBySite(SiteInterface $site, int $keepSnapshots): void diff --git a/src/Service/CreateSnapshotService.php b/src/Service/CreateSnapshotService.php index 947a35e59..08f4c8379 100644 --- a/src/Service/CreateSnapshotService.php +++ b/src/Service/CreateSnapshotService.php @@ -25,20 +25,11 @@ final class CreateSnapshotService implements CreateSnapshotBySiteInterface, CreateSnapshotByPageInterface { - private SnapshotManagerInterface $snapshotManager; - - private PageManagerInterface $pageManager; - - private TransformerInterface $transformer; - public function __construct( - SnapshotManagerInterface $snapshotManager, - PageManagerInterface $pageManager, - TransformerInterface $transformer + private SnapshotManagerInterface $snapshotManager, + private PageManagerInterface $pageManager, + private TransformerInterface $transformer ) { - $this->snapshotManager = $snapshotManager; - $this->pageManager = $pageManager; - $this->transformer = $transformer; } public function createBySite(SiteInterface $site): void diff --git a/src/Site/BaseSiteSelector.php b/src/Site/BaseSiteSelector.php index 7b2f666bd..1b9d15886 100644 --- a/src/Site/BaseSiteSelector.php +++ b/src/Site/BaseSiteSelector.php @@ -26,22 +26,13 @@ */ abstract class BaseSiteSelector implements SiteSelectorInterface { - protected SiteManagerInterface $siteManager; - - protected DecoratorStrategyInterface $decoratorStrategy; - - protected SeoPageInterface $seoPage; - protected ?SiteInterface $site = null; public function __construct( - SiteManagerInterface $siteManager, - DecoratorStrategyInterface $decoratorStrategy, - SeoPageInterface $seoPage + protected SiteManagerInterface $siteManager, + protected DecoratorStrategyInterface $decoratorStrategy, + protected SeoPageInterface $seoPage ) { - $this->siteManager = $siteManager; - $this->decoratorStrategy = $decoratorStrategy; - $this->seoPage = $seoPage; } public function retrieve(): ?SiteInterface diff --git a/src/Twig/Extension/PageExtension.php b/src/Twig/Extension/PageExtension.php index 17ba93adb..3047ba6c1 100644 --- a/src/Twig/Extension/PageExtension.php +++ b/src/Twig/Extension/PageExtension.php @@ -36,32 +36,14 @@ */ final class PageExtension extends AbstractExtension { - private CmsManagerSelectorInterface $cmsManagerSelector; - - private SiteSelectorInterface $siteSelector; - - private RouterInterface $router; - - private BlockHelper $blockHelper; - - private RequestStack $requestStack; - - private bool $hideDisabledBlocks; - public function __construct( - CmsManagerSelectorInterface $cmsManagerSelector, - SiteSelectorInterface $siteSelector, - RouterInterface $router, - BlockHelper $blockHelper, - RequestStack $requestStack, - bool $hideDisabledBlocks = false + private CmsManagerSelectorInterface $cmsManagerSelector, + private SiteSelectorInterface $siteSelector, + private RouterInterface $router, + private BlockHelper $blockHelper, + private RequestStack $requestStack, + private bool $hideDisabledBlocks = false ) { - $this->cmsManagerSelector = $cmsManagerSelector; - $this->siteSelector = $siteSelector; - $this->router = $router; - $this->blockHelper = $blockHelper; - $this->requestStack = $requestStack; - $this->hideDisabledBlocks = $hideDisabledBlocks; } public function getFunctions(): array @@ -111,7 +93,7 @@ public function breadcrumb(Environment $twig, ?PageInterface $page = null, array if (null !== $site) { $homePage = $this->cmsManagerSelector->retrieve()->getPageByRouteName($site, 'homepage'); } - } catch (PageNotFoundException $e) { + } catch (PageNotFoundException) { } if (null !== $homePage) { @@ -143,10 +125,9 @@ public function ajaxUrl(PageBlockInterface $block, array $parameters = [], int $ } /** - * @param string|PageInterface|null $page - * @param array $options + * @param array $options */ - public function renderContainer(string $name, $page = null, array $options = []): string + public function renderContainer(string $name, string|PageInterface|null $page = null, array $options = []): string { $cms = $this->cmsManagerSelector->retrieve(); $site = $this->siteSelector->retrieve(); @@ -155,12 +136,12 @@ public function renderContainer(string $name, $page = null, array $options = []) try { if (null === $page) { $targetPage = $cms->getCurrentPage(); - } elseif (null !== $site && !$page instanceof PageInterface && \is_string($page)) { + } elseif (null !== $site && !$page instanceof PageInterface) { $targetPage = $cms->getInternalRoute($site, $page); } elseif ($page instanceof PageInterface) { $targetPage = $page; } - } catch (PageNotFoundException $e) { + } catch (PageNotFoundException) { // the snapshot does not exist $targetPage = null; } diff --git a/src/Twig/GlobalVariables.php b/src/Twig/GlobalVariables.php index dc20ef7bc..1f56c0881 100644 --- a/src/Twig/GlobalVariables.php +++ b/src/Twig/GlobalVariables.php @@ -25,24 +25,12 @@ */ final class GlobalVariables { - private SiteManagerInterface $siteManager; - - private CmsManagerSelectorInterface $cmsManagerSelector; - - private SiteSelectorInterface $siteSelector; - - private TemplateManagerInterface $templateManager; - public function __construct( - SiteManagerInterface $siteManager, - CmsManagerSelectorInterface $cmsManagerSelector, - SiteSelectorInterface $siteSelector, - TemplateManagerInterface $templateManager + private SiteManagerInterface $siteManager, + private CmsManagerSelectorInterface $cmsManagerSelector, + private SiteSelectorInterface $siteSelector, + private TemplateManagerInterface $templateManager ) { - $this->siteManager = $siteManager; - $this->cmsManagerSelector = $cmsManagerSelector; - $this->siteSelector = $siteSelector; - $this->templateManager = $templateManager; } /** diff --git a/src/Validator/UniqueUrlValidator.php b/src/Validator/UniqueUrlValidator.php index 9a6227571..3ec477de9 100644 --- a/src/Validator/UniqueUrlValidator.php +++ b/src/Validator/UniqueUrlValidator.php @@ -23,11 +23,8 @@ final class UniqueUrlValidator extends ConstraintValidator { - private PageManagerInterface $manager; - - public function __construct(PageManagerInterface $manager) + public function __construct(private PageManagerInterface $manager) { - $this->manager = $manager; } /** diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 9bf4d4323..f2bbad914 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -34,6 +34,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Security\Http\Attribute\IsGranted; use Symfony\Component\Security\Http\Authentication\AuthenticatorManager; final class AppKernel extends Kernel @@ -97,7 +98,9 @@ protected function configureContainer(ContainerBuilder $container, LoaderInterfa $loader->load($this->getProjectDir().'/config/config.yaml'); - if (class_exists(AuthenticatorManager::class)) { + if (class_exists(IsGranted::class)) { + $loader->load($this->getProjectDir().'/config/config_symfony_v6.yaml'); + } elseif (class_exists(AuthenticatorManager::class)) { $loader->load($this->getProjectDir().'/config/config_symfony_v5.yaml'); } else { $loader->load($this->getProjectDir().'/config/config_symfony_v4.yaml'); diff --git a/tests/App/Entity/SonataPageBlock.php b/tests/App/Entity/SonataPageBlock.php index a51b9dacf..90e259176 100644 --- a/tests/App/Entity/SonataPageBlock.php +++ b/tests/App/Entity/SonataPageBlock.php @@ -13,34 +13,27 @@ namespace Sonata\PageBundle\Tests\App\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Sonata\PageBundle\Entity\BaseBlock; -/** - * @ORM\Entity - * @ORM\Table(name="page__block") - * @ORM\HasLifecycleCallbacks - */ +#[ORM\Entity] +#[ORM\Table(name: 'page__block')] +#[ORM\HasLifecycleCallbacks] class SonataPageBlock extends BaseBlock { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue] protected $id = null; - /** - * @ORM\PrePersist - */ + #[ORM\PrePersist] public function prePersist(): void { parent::prePersist(); } - /** - * @ORM\PreUpdate - */ + #[ORM\PreUpdate] public function preUpdate(): void { parent::preUpdate(); diff --git a/tests/App/Entity/SonataPagePage.php b/tests/App/Entity/SonataPagePage.php index 93830ff84..cd5c242d0 100644 --- a/tests/App/Entity/SonataPagePage.php +++ b/tests/App/Entity/SonataPagePage.php @@ -13,34 +13,27 @@ namespace Sonata\PageBundle\Tests\App\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Sonata\PageBundle\Entity\BasePage; -/** - * @ORM\Entity - * @ORM\Table(name="page__page") - * @ORM\HasLifecycleCallbacks - */ +#[ORM\Entity] +#[ORM\Table(name: 'page__page')] +#[ORM\HasLifecycleCallbacks] class SonataPagePage extends BasePage { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue] protected $id = null; - /** - * @ORM\PrePersist - */ + #[ORM\PrePersist] public function prePersist(): void { parent::prePersist(); } - /** - * @ORM\PreUpdate - */ + #[ORM\PreUpdate] public function preUpdate(): void { parent::preUpdate(); diff --git a/tests/App/Entity/SonataPageSite.php b/tests/App/Entity/SonataPageSite.php index a265a7c9c..367fa31ec 100644 --- a/tests/App/Entity/SonataPageSite.php +++ b/tests/App/Entity/SonataPageSite.php @@ -13,34 +13,27 @@ namespace Sonata\PageBundle\Tests\App\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Sonata\PageBundle\Entity\BaseSite; -/** - * @ORM\Entity - * @ORM\Table(name="page__site") - * @ORM\HasLifecycleCallbacks - */ +#[ORM\Entity] +#[ORM\Table(name: 'page__site')] +#[ORM\HasLifecycleCallbacks] class SonataPageSite extends BaseSite { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue] protected $id = null; - /** - * @ORM\PrePersist - */ + #[ORM\PrePersist] public function prePersist(): void { parent::prePersist(); } - /** - * @ORM\PreUpdate - */ + #[ORM\PreUpdate] public function preUpdate(): void { parent::preUpdate(); diff --git a/tests/App/Entity/SonataPageSnapshot.php b/tests/App/Entity/SonataPageSnapshot.php index 010571852..2b44b93ed 100644 --- a/tests/App/Entity/SonataPageSnapshot.php +++ b/tests/App/Entity/SonataPageSnapshot.php @@ -13,25 +13,19 @@ namespace Sonata\PageBundle\Tests\App\Entity; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; use Sonata\PageBundle\Entity\BaseSnapshot; -/** - * @ORM\Entity - * @ORM\Table(name="page__snapshot", indexes={ - * @ORM\Index( - * name="idx_snapshot_dates_enabled", columns={"publication_date_start", "publication_date_end","enabled"} - * ) - * }) - */ +#[ORM\Entity] +#[ORM\Table(name: 'page__snapshot')] +#[ORM\Index(name: 'idx_snapshot_dates_enabled', columns: ['publication_date_start', 'publication_date_end', 'enabled'])] class SonataPageSnapshot extends BaseSnapshot { - /** - * @ORM\Id - * @ORM\Column(type="integer") - * @ORM\GeneratedValue(strategy="AUTO") - */ - protected $id; + #[ORM\Id] + #[ORM\Column(type: Types::INTEGER)] + #[ORM\GeneratedValue] + protected $id = null; public function setId(int $id): void { diff --git a/tests/App/config/config_symfony_v6.yaml b/tests/App/config/config_symfony_v6.yaml new file mode 100644 index 000000000..bef276931 --- /dev/null +++ b/tests/App/config/config_symfony_v6.yaml @@ -0,0 +1,3 @@ +framework: + session: + storage_factory_id: session.storage.factory.mock_file diff --git a/tests/App/config/doctrine.yaml b/tests/App/config/doctrine.yaml index 36f36adb7..80835b225 100644 --- a/tests/App/config/doctrine.yaml +++ b/tests/App/config/doctrine.yaml @@ -8,7 +8,7 @@ doctrine: mappings: App: is_bundle: false - type: annotation + type: attribute dir: '%kernel.project_dir%/Entity' prefix: 'Sonata\PageBundle\Tests\App\Entity' alias: App diff --git a/tests/Functional/Snapshot/SnapshotManagerTest.php b/tests/Functional/Snapshot/SnapshotManagerTest.php index 1cbc51b0f..11ee86e47 100644 --- a/tests/Functional/Snapshot/SnapshotManagerTest.php +++ b/tests/Functional/Snapshot/SnapshotManagerTest.php @@ -122,7 +122,6 @@ public function testFunctionalEnableSnapshots(): void $snapshotPublicationDateEnd = $snapshot2->getPublicationDateEnd(); - // @phpstan-ignore-next-line https://github.com/phpstan/phpstan/discussions/8586 static::assertNotNull($snapshotPublicationDateEnd); static::assertDateTimeEquals($date, $snapshotPublicationDateEnd); } diff --git a/tests/Page/Service/DefaultPageServiceTest.php b/tests/Page/Service/DefaultPageServiceTest.php index fa86f2c9c..46925b8d6 100644 --- a/tests/Page/Service/DefaultPageServiceTest.php +++ b/tests/Page/Service/DefaultPageServiceTest.php @@ -65,13 +65,7 @@ public function testExecute(): void ->method('setTitle')->with(static::equalTo('page title')); $this->seoPage->expects(static::exactly(3)) - ->method('addMeta') - ->withConsecutive( - ['name', 'description', 'page meta description'], - ['name', 'keywords', 'page meta keywords'], - ['property', 'og:type', 'article'] - ) - ->willReturnOnConsecutiveCalls($this->seoPage, $this->seoPage, $this->seoPage); + ->method('addMeta')->willReturn($this->seoPage); $this->seoPage->expects(static::once()) ->method('addHtmlAttributes')->with(static::equalTo('prefix'), static::equalTo('og: http://ogp.me/ns#')); From cba795ff2de0d984da185cb50b9b3751353fbbad Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 17:25:37 +0000 Subject: [PATCH 3/9] add missing dep --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index ccb8989aa..c66b65538 100644 --- a/composer.json +++ b/composer.json @@ -70,6 +70,7 @@ "symfony/filesystem": "^4.4 || ^5.4 || ^6.2", "symfony/panther": "^1.0 || ^2.0", "symfony/phpunit-bridge": "^6.2", + "symfony/yaml": "^4.4 || ^5.4 || ^6.2", "vimeo/psalm": "^4.7.2 || ^5.0" }, "conflict": { From d0dfabcf2697cd59138a8c100bef78ace08cffee Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 23:07:12 +0100 Subject: [PATCH 4/9] Update TemplateTest.php --- tests/Model/TemplateTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Model/TemplateTest.php b/tests/Model/TemplateTest.php index 89f6b3b9b..b1437c488 100644 --- a/tests/Model/TemplateTest.php +++ b/tests/Model/TemplateTest.php @@ -51,7 +51,7 @@ public function testGetContainer(): void { $template = new Template('page', 'template.twig', ['header' => [ 'name' => 'Header', - 'block' => ['text.block'], + 'blocks' => ['text.block'], ]]); $expected = [ From 123a9948ab26c9a016d394f5d9c42661ebcc59e1 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 23:21:19 +0100 Subject: [PATCH 5/9] Update tests/Model/TemplateTest.php --- tests/Model/TemplateTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Model/TemplateTest.php b/tests/Model/TemplateTest.php index b1437c488..5e79887d2 100644 --- a/tests/Model/TemplateTest.php +++ b/tests/Model/TemplateTest.php @@ -51,7 +51,6 @@ public function testGetContainer(): void { $template = new Template('page', 'template.twig', ['header' => [ 'name' => 'Header', - 'blocks' => ['text.block'], ]]); $expected = [ From fda4807854e4b5abcbf2df603cb9d909672968ba Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 23:28:22 +0100 Subject: [PATCH 6/9] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c66b65538..802ca3e64 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php": "^8.0", "cocur/slugify": "^4.0", "doctrine/doctrine-bundle": "^2.7", - "doctrine/persistence": "^3.0", + "doctrine/persistence": "^3.0.2", "sonata-project/admin-bundle": "^4.19", "sonata-project/block-bundle": "^4.18", "sonata-project/doctrine-extensions": "^1.18 || ^2.1", From 769a103733c5fcb9067498645d5f288f00831474 Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 23:34:06 +0100 Subject: [PATCH 7/9] Update composer.json --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 802ca3e64..9b16f3ce9 100644 --- a/composer.json +++ b/composer.json @@ -74,6 +74,7 @@ "vimeo/psalm": "^4.7.2 || ^5.0" }, "conflict": { + "doctrine/annotations": "<1.13.3", "doctrine/orm": "<2.14" }, "suggest": { From 47003ecbd9c82467309f91091b18041c5504b02a Mon Sep 17 00:00:00 2001 From: Jordi Sala Morales Date: Thu, 9 Mar 2023 23:37:37 +0100 Subject: [PATCH 8/9] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9b16f3ce9..c08a4874f 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "vimeo/psalm": "^4.7.2 || ^5.0" }, "conflict": { - "doctrine/annotations": "<1.13.3", + "doctrine/dbal": "<3.4", "doctrine/orm": "<2.14" }, "suggest": { From dc2d476e86d586243835c4582f34aa94db8b3fc7 Mon Sep 17 00:00:00 2001 From: SonataCI Date: Fri, 10 Mar 2023 12:13:09 +0000 Subject: [PATCH 9/9] 'DevKit updates' --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cedccfb0d..1af5ab267 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -92,6 +92,6 @@ jobs: run: make coverage - name: Send coverage to Codecov - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 with: - file: build/logs/clover.xml + files: build/logs/clover.xml