diff --git a/src/Admin/BaseBlockAdmin.php b/src/Admin/BaseBlockAdmin.php index 97eb0bd39..bab6e9cd5 100644 --- a/src/Admin/BaseBlockAdmin.php +++ b/src/Admin/BaseBlockAdmin.php @@ -31,20 +31,14 @@ */ abstract class BaseBlockAdmin extends AbstractAdmin { - /** - * @var BlockServiceManagerInterface - */ - protected $blockManager; + protected BlockServiceManagerInterface $blockManager; - /** - * @var bool - */ - protected $inValidate = false; + protected bool $inValidate = false; /** * @var array */ - protected $containerBlockTypes = []; + protected array $containerBlockTypes = []; public function __construct(BlockServiceManagerInterface $blockManager) { diff --git a/src/Admin/BlockAdmin.php b/src/Admin/BlockAdmin.php index e09568236..7dbe5c32c 100644 --- a/src/Admin/BlockAdmin.php +++ b/src/Admin/BlockAdmin.php @@ -198,10 +198,7 @@ protected function configureFormFields(FormMapper $form): void } } - /** - * @return string|null - */ - private function getDefaultTemplate(BlockServiceInterface $blockService) + private function getDefaultTemplate(BlockServiceInterface $blockService): ?string { $resolver = new OptionsResolver(); $blockService->configureSettings($resolver); diff --git a/src/Admin/PageAdmin.php b/src/Admin/PageAdmin.php index b5f8ca252..c401a3a51 100644 --- a/src/Admin/PageAdmin.php +++ b/src/Admin/PageAdmin.php @@ -72,12 +72,12 @@ protected function configureRoutes(RouteCollectionInterface $collection): void $collection->add('tree', 'tree'); } - protected function preUpdate($object): void + protected function preUpdate(object $object): void { $object->setEdited(true); } - protected function prePersist($object): void + protected function prePersist(object $object): void { $object->setEdited(true); } @@ -392,10 +392,8 @@ protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminI /** * @throws \RuntimeException - * - * @return SiteInterface|null */ - private function getSite() + private function getSite(): ?SiteInterface { if (!$this->hasRequest()) { return null; diff --git a/src/Admin/SharedBlockAdmin.php b/src/Admin/SharedBlockAdmin.php index 217dbbf4b..918f201a1 100644 --- a/src/Admin/SharedBlockAdmin.php +++ b/src/Admin/SharedBlockAdmin.php @@ -19,7 +19,6 @@ use Sonata\BlockBundle\Block\Service\EditableBlockService; use Sonata\BlockBundle\Model\BlockInterface; use Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery; -use Sonata\PageBundle\Entity\BaseBlock; use Sonata\PageBundle\Mapper\PageFormMapper; use Sonata\PageBundle\Model\PageBlockInterface; @@ -63,7 +62,6 @@ protected function configureListFields(ListMapper $list): void protected function configureFormFields(FormMapper $form): void { - /** @var BaseBlock $block */ $block = $this->getSubject(); // New block diff --git a/src/Block/BreadcrumbBlockService.php b/src/Block/BreadcrumbBlockService.php index e8d4cfeb9..f0d424fb3 100644 --- a/src/Block/BreadcrumbBlockService.php +++ b/src/Block/BreadcrumbBlockService.php @@ -81,18 +81,12 @@ protected function getMenu(BlockContextInterface $blockContext): ItemInterface return $menu; } - /** - * @return string - */ - private function getName() + private function getName(): string { return 'sonata.page.block.breadcrumb'; } - /** - * @return PageInterface|null - */ - private function getCurrentPage() + private function getCurrentPage(): ?PageInterface { $cms = $this->cmsSelector->retrieve(); diff --git a/src/Block/SharedBlockBlockService.php b/src/Block/SharedBlockBlockService.php index 00a0c5b7f..23f0ea300 100755 --- a/src/Block/SharedBlockBlockService.php +++ b/src/Block/SharedBlockBlockService.php @@ -25,7 +25,6 @@ use Sonata\Doctrine\Model\ManagerInterface; use Sonata\Form\Type\ImmutableArrayType; use Sonata\Form\Validator\ErrorElement; -use Sonata\PageBundle\Model\Block; use Sonata\PageBundle\Model\PageBlockInterface; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\HttpFoundation\Response; @@ -71,7 +70,6 @@ public function execute(BlockContextInterface $blockContext, ?Response $response $this->load($block); } - /** @var Block $sharedBlock */ $sharedBlock = $block->getSetting('blockId'); $template = $blockContext->getTemplate(); diff --git a/src/CmsManager/BaseCmsPageManager.php b/src/CmsManager/BaseCmsPageManager.php index 1e56d7662..789081714 100644 --- a/src/CmsManager/BaseCmsPageManager.php +++ b/src/CmsManager/BaseCmsPageManager.php @@ -22,17 +22,14 @@ */ abstract class BaseCmsPageManager implements CmsManagerInterface { - /** - * @var PageInterface|null - */ - protected $currentPage = null; + protected ?PageInterface $currentPage = null; /** * @var array */ - protected $blocks = []; + protected array $blocks = []; - public function getCurrentPage() + public function getCurrentPage(): ?PageInterface { return $this->currentPage; } @@ -42,43 +39,40 @@ public function setCurrentPage(PageInterface $page): void $this->currentPage = $page; } - public function getBlocks() + public function getBlocks(): array { return $this->blocks; } - public function getPageByUrl(SiteInterface $site, $slug): PageInterface + public function getPageByUrl(SiteInterface $site, string $slug): PageInterface { return $this->getPageBy($site, 'url', $slug); } - public function getPageByRouteName(SiteInterface $site, $routeName) + public function getPageByRouteName(SiteInterface $site, string $routeName): PageInterface { return $this->getPageBy($site, 'routeName', $routeName); } - public function getPageByPageAlias(SiteInterface $site, $pageAlias) + public function getPageByPageAlias(SiteInterface $site, string $pageAlias): PageInterface { return $this->getPageBy($site, 'pageAlias', $pageAlias); } - public function getPageByName(SiteInterface $site, $name) + public function getPageByName(SiteInterface $site, string $name): PageInterface { return $this->getPageBy($site, 'name', $name); } - public function getPageById($id) + public function getPageById($id): PageInterface { return $this->getPageBy(null, 'id', $id); } /** - * @param string $fieldName * @param int|string $value * - * @return PageInterface - * * @phpstan-param 'id'|'url'|'routeName'|'pageAlias'|'name' $fieldName */ - abstract protected function getPageBy(?SiteInterface $site, $fieldName, $value); + abstract protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface; } diff --git a/src/CmsManager/CmsManagerInterface.php b/src/CmsManager/CmsManagerInterface.php index 2c0ea92d8..fa61b4c0f 100644 --- a/src/CmsManager/CmsManagerInterface.php +++ b/src/CmsManager/CmsManagerInterface.php @@ -25,79 +25,39 @@ */ interface CmsManagerInterface { - /** - * @param string $name - * - * @return PageBlockInterface|null - */ - public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null); + public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface; - /** - * @param string $slug - */ - public function getPageByUrl(SiteInterface $site, $slug): PageInterface; + public function getPageByUrl(SiteInterface $site, string $slug): PageInterface; - /** - * @param string $routeName - * - * @return PageInterface - */ - public function getPageByRouteName(SiteInterface $site, $routeName); + public function getPageByRouteName(SiteInterface $site, string $routeName): PageInterface; - /** - * @param string $pageAlias - * - * @return PageInterface - */ - public function getPageByPageAlias(SiteInterface $site, $pageAlias); + public function getPageByPageAlias(SiteInterface $site, string $pageAlias): PageInterface; - /** - * @param string $routeName - * - * @return PageInterface - */ - public function getInternalRoute(SiteInterface $site, $routeName); + public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface; - /** - * @param string $name - * - * @return PageInterface - */ - public function getPageByName(SiteInterface $site, $name); + public function getPageByName(SiteInterface $site, string $name): PageInterface; /** * @param int|string $id - * - * @return PageInterface */ - public function getPageById($id); + public function getPageById($id): PageInterface; /** * @param int|string $id - * - * @return PageBlockInterface|null */ - public function getBlock($id); + public function getBlock($id): ?PageBlockInterface; - /** - * @return PageInterface|null - */ - public function getCurrentPage(); + public function getCurrentPage(): ?PageInterface; - /** - * @return void - */ - public function setCurrentPage(PageInterface $page); + public function setCurrentPage(PageInterface $page): void; /** * @return array */ - public function getBlocks(); + public function getBlocks(): array; /** * @param int|string|null $page - * - * @return PageInterface */ - public function getPage(SiteInterface $site, $page); + public function getPage(SiteInterface $site, $page): PageInterface; } diff --git a/src/CmsManager/CmsManagerSelector.php b/src/CmsManager/CmsManagerSelector.php index ef67a6d48..63ae64a33 100644 --- a/src/CmsManager/CmsManagerSelector.php +++ b/src/CmsManager/CmsManagerSelector.php @@ -33,6 +33,7 @@ final class CmsManagerSelector implements CmsManagerSelectorInterface, BCLogoutHandlerInterface { private CmsPageManager $cmsPageManager; + private CmsSnapshotManager $cmsSnapshotManager; /** @@ -41,6 +42,7 @@ final class CmsManagerSelector implements CmsManagerSelectorInterface, BCLogoutH private AdminInterface $pageAdmin; private TokenStorageInterface $tokenStorage; + private RequestStack $requestStack; /** @@ -60,7 +62,7 @@ public function __construct( $this->requestStack = $requestStack; } - public function retrieve() + public function retrieve(): CmsManagerInterface { return $this->isEditor() ? $this->cmsPageManager : $this->cmsSnapshotManager; } @@ -70,7 +72,7 @@ public function retrieve() * by the router chain, so we need to use another mechanism. It is not perfect * but do the job for now. */ - public function isEditor() + public function isEditor(): bool { $request = $this->requestStack->getCurrentRequest(); diff --git a/src/CmsManager/CmsManagerSelectorInterface.php b/src/CmsManager/CmsManagerSelectorInterface.php index 62a6d3559..8a2c403e4 100644 --- a/src/CmsManager/CmsManagerSelectorInterface.php +++ b/src/CmsManager/CmsManagerSelectorInterface.php @@ -18,13 +18,7 @@ */ interface CmsManagerSelectorInterface { - /** - * @return CmsManagerInterface - */ - public function retrieve(); + public function retrieve(): CmsManagerInterface; - /** - * @return bool - */ - public function isEditor(); + public function isEditor(): bool; } diff --git a/src/CmsManager/CmsPageManager.php b/src/CmsManager/CmsPageManager.php index 3a762623a..22a8f9f77 100644 --- a/src/CmsManager/CmsPageManager.php +++ b/src/CmsManager/CmsPageManager.php @@ -45,7 +45,7 @@ final class CmsPageManager extends BaseCmsPageManager ]; /** - * @var PageInterface[] + * @var array */ private array $pages = []; @@ -55,7 +55,7 @@ public function __construct(PageManagerInterface $pageManager, BlockInteractorIn $this->blockInteractor = $blockInteractor; } - public function getPage(SiteInterface $site, $page) + public function getPage(SiteInterface $site, $page): PageInterface { if (\is_string($page) && '/' === substr($page, 0, 1)) { $page = $this->getPageByUrl($site, $page); @@ -74,7 +74,7 @@ public function getPage(SiteInterface $site, $page) return $page; } - public function getInternalRoute(SiteInterface $site, $routeName) + public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface { if ('error' === substr($routeName, 0, 5)) { throw new \RuntimeException(sprintf('Illegal internal route name : %s, an internal page cannot start with `error`', $routeName)); @@ -100,7 +100,7 @@ public function getInternalRoute(SiteInterface $site, $routeName) return $page; } - public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null) + public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface { $container = null; @@ -134,7 +134,7 @@ public function findContainer($name, PageInterface $page, ?PageBlockInterface $p return $container; } - public function getBlock($id) + public function getBlock($id): ?PageBlockInterface { if (!\array_key_exists($id, $this->blocks)) { $this->blocks[$id] = $this->blockInteractor->getBlock($id); @@ -143,7 +143,7 @@ public function getBlock($id) return $this->blocks[$id]; } - protected function getPageBy(?SiteInterface $site, $fieldName, $value) + protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface { if ('id' === $fieldName) { $id = $value; diff --git a/src/CmsManager/CmsSnapshotManager.php b/src/CmsManager/CmsSnapshotManager.php index 4eb2e23a7..e26d2425d 100644 --- a/src/CmsManager/CmsSnapshotManager.php +++ b/src/CmsManager/CmsSnapshotManager.php @@ -48,7 +48,7 @@ final class CmsSnapshotManager extends BaseCmsPageManager ]; /** - * @var PageInterface[] + * @var array */ private array $pages = []; @@ -58,7 +58,7 @@ public function __construct(SnapshotManagerInterface $snapshotManager, Transform $this->transformer = $transformer; } - public function getPage(SiteInterface $site, $page) + public function getPage(SiteInterface $site, $page): PageInterface { if (\is_string($page) && '/' === substr($page, 0, 1)) { $page = $this->getPageByUrl($site, $page); @@ -77,12 +77,12 @@ public function getPage(SiteInterface $site, $page) return $page; } - public function getInternalRoute(SiteInterface $site, $routeName) + public function getInternalRoute(SiteInterface $site, string $routeName): PageInterface { return $this->getPageByRouteName($site, sprintf('_page_internal_%s', $routeName)); } - public function findContainer($name, PageInterface $page, ?PageBlockInterface $parentContainer = null) + public function findContainer(string $name, PageInterface $page, ?PageBlockInterface $parentContainer = null): ?PageBlockInterface { $container = null; @@ -106,7 +106,7 @@ public function findContainer($name, PageInterface $page, ?PageBlockInterface $p return $container; } - public function getBlock($id) + public function getBlock($id): ?PageBlockInterface { if (isset($this->blocks[$id])) { return $this->blocks[$id]; @@ -115,7 +115,7 @@ public function getBlock($id) return null; } - protected function getPageBy(?SiteInterface $site, $fieldName, $value) + protected function getPageBy(?SiteInterface $site, string $fieldName, $value): PageInterface { if ('id' === $fieldName) { $fieldName = 'pageId'; diff --git a/src/CmsManager/DecoratorStrategy.php b/src/CmsManager/DecoratorStrategy.php index 0299da37d..39f755808 100644 --- a/src/CmsManager/DecoratorStrategy.php +++ b/src/CmsManager/DecoratorStrategy.php @@ -52,7 +52,7 @@ public function __construct( $this->ignoreUriPatterns = $ignoreUriPatterns; } - public function isDecorable(Request $request, $requestType, Response $response) + public function isDecorable(Request $request, int $requestType, Response $response): bool { // TODO: Simplify this when dropping support for Symfony < 5.3 $mainRequestType = \defined(HttpKernelInterface::class.'::MAIN_REQUEST') ? HttpKernelInterface::MAIN_REQUEST : 1; @@ -85,17 +85,15 @@ public function isDecorable(Request $request, $requestType, Response $response) return $this->isRequestDecorable($request); } - public function isRequestDecorable(Request $request) + public function isRequestDecorable(Request $request): bool { - return $this->isRouteNameDecorable($request->get('_route')) && $this->isRouteUriDecorable($request->getPathInfo()); + $route = $request->get('_route'); + + return null !== $route && $this->isRouteNameDecorable($route) && $this->isRouteUriDecorable($request->getPathInfo()); } - public function isRouteNameDecorable($routeName) + public function isRouteNameDecorable(string $routeName): bool { - if (null === $routeName) { - return false; - } - foreach ($this->ignoreRoutes as $route) { if ($routeName === $route) { return false; @@ -111,7 +109,7 @@ public function isRouteNameDecorable($routeName) return true; } - public function isRouteUriDecorable($uri) + public function isRouteUriDecorable(string $uri): bool { foreach ($this->ignoreUriPatterns as $uriPattern) { if (1 === preg_match(sprintf('#%s#', $uriPattern), $uri)) { diff --git a/src/CmsManager/DecoratorStrategyInterface.php b/src/CmsManager/DecoratorStrategyInterface.php index 89656e1a8..668e84115 100644 --- a/src/CmsManager/DecoratorStrategyInterface.php +++ b/src/CmsManager/DecoratorStrategyInterface.php @@ -24,29 +24,11 @@ */ interface DecoratorStrategyInterface { - /** - * @param int $requestType - * - * @return bool - */ - public function isDecorable(Request $request, $requestType, Response $response); - - /** - * @return bool - */ - public function isRequestDecorable(Request $request); - - /** - * @param string $routeName - * - * @return bool - */ - public function isRouteNameDecorable($routeName); - - /** - * @param string $uri - * - * @return bool - */ - public function isRouteUriDecorable($uri); + public function isDecorable(Request $request, int $requestType, Response $response): bool; + + public function isRequestDecorable(Request $request): bool; + + public function isRouteNameDecorable(string $routeName): bool; + + public function isRouteUriDecorable(string $uri): bool; } diff --git a/src/Command/CleanupSnapshotsCommand.php b/src/Command/CleanupSnapshotsCommand.php index b122183b9..5bd0f53f8 100644 --- a/src/Command/CleanupSnapshotsCommand.php +++ b/src/Command/CleanupSnapshotsCommand.php @@ -30,6 +30,7 @@ final class CleanupSnapshotsCommand extends Command protected static $defaultDescription = 'Cleanups the deprecated snapshots by a given site'; private CleanupSnapshotBySiteInterface $cleanupSnapshotBySite; + private SiteManagerInterface $siteManager; public function __construct( diff --git a/src/Command/CloneSiteCommand.php b/src/Command/CloneSiteCommand.php index 540daa3ed..787bae772 100644 --- a/src/Command/CloneSiteCommand.php +++ b/src/Command/CloneSiteCommand.php @@ -14,10 +14,7 @@ namespace Sonata\PageBundle\Command; use Sonata\PageBundle\Model\BlockManagerInterface; -use Sonata\PageBundle\Model\PageBlockInterface; -use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\PageManagerInterface; -use Sonata\PageBundle\Model\SiteInterface; use Sonata\PageBundle\Model\SiteManagerInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -39,7 +36,9 @@ final class CloneSiteCommand extends Command protected static $defaultDescription = 'Clone a complete site including all their pages'; private SiteManagerInterface $siteManager; + private PageManagerInterface $pageManager; + private BlockManagerInterface $blockManager; public function __construct( @@ -95,10 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $hybridOnly = false; } - /** @var SiteInterface $sourceSite */ $sourceSite = $this->siteManager->find($input->getOption('source-id')); - - /** @var SiteInterface $destSite */ $destSite = $this->siteManager->find($input->getOption('dest-id')); $pageClones = []; @@ -106,7 +102,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Cloning pages'); - /** @var PageInterface[] $pages */ $pages = $this->pageManager->findBy(['site' => $sourceSite]); foreach ($pages as $page) { $pageId = $page->getId(); @@ -136,7 +131,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $pageClones[$pageId] = $newPage; - /** @var PageBlockInterface[] $blocks */ $blocks = $this->blockManager->findBy(['page' => $page]); foreach ($blocks as $block) { diff --git a/src/Command/CreateBlockContainerCommand.php b/src/Command/CreateBlockContainerCommand.php index c1b081c6f..c15e4e4e2 100644 --- a/src/Command/CreateBlockContainerCommand.php +++ b/src/Command/CreateBlockContainerCommand.php @@ -14,7 +14,6 @@ namespace Sonata\PageBundle\Command; use Sonata\PageBundle\Model\BlockInteractorInterface; -use Sonata\PageBundle\Model\PageInterface; use Sonata\PageBundle\Model\PageManagerInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -35,6 +34,7 @@ final class CreateBlockContainerCommand extends Command 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) @@ -67,7 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'templateCode' => $input->getArgument('templateCode'), ]); - /** @var PageInterface $page */ foreach ($pages as $page) { $output->writeln(sprintf('Adding to page %s', $page->getName() ?? '')); diff --git a/src/Command/CreateSnapshotsCommand.php b/src/Command/CreateSnapshotsCommand.php index 55d039094..36708b3e3 100644 --- a/src/Command/CreateSnapshotsCommand.php +++ b/src/Command/CreateSnapshotsCommand.php @@ -35,6 +35,7 @@ final class CreateSnapshotsCommand extends Command protected static $defaultDescription = 'Create a snapshots of all pages available'; private CreateSnapshotBySiteInterface $createSnapshot; + private SiteManagerInterface $siteManager; public function __construct(CreateSnapshotBySiteInterface $createSnapshot, SiteManagerInterface $siteManager) diff --git a/src/Command/UpdateCoreRoutesCommand.php b/src/Command/UpdateCoreRoutesCommand.php index 7119f2541..6dd426c92 100644 --- a/src/Command/UpdateCoreRoutesCommand.php +++ b/src/Command/UpdateCoreRoutesCommand.php @@ -35,6 +35,7 @@ final class UpdateCoreRoutesCommand extends Command protected static $defaultDescription = 'Update core routes, from routing files to page manager'; private SiteManagerInterface $siteManager; + private RoutePageGenerator $pageGenerator; public function __construct( diff --git a/src/Controller/AjaxController.php b/src/Controller/AjaxController.php index f33151910..915617535 100644 --- a/src/Controller/AjaxController.php +++ b/src/Controller/AjaxController.php @@ -21,8 +21,6 @@ use Symfony\Component\HttpFoundation\Response; /** - * Render a block in ajax. - * * @author Thomas Rabaix */ final class AjaxController @@ -33,27 +31,21 @@ final class AjaxController private BlockContextManagerInterface $contextManager; - /** - * @param CmsManagerSelectorInterface $cmsManagerSelector CMS Manager selector - * @param BlockRendererInterface $blockRenderer Block renderer - * @param BlockContextManagerInterface $contextManager Context Manager - */ - public function __construct(CmsManagerSelectorInterface $cmsManagerSelector, BlockRendererInterface $blockRenderer, BlockContextManagerInterface $contextManager) - { + public function __construct( + CmsManagerSelectorInterface $cmsManagerSelector, + BlockRendererInterface $blockRenderer, + BlockContextManagerInterface $contextManager + ) { $this->cmsManagerSelector = $cmsManagerSelector; $this->blockRenderer = $blockRenderer; $this->contextManager = $contextManager; } /** - * Action for ajax route rendering a block by calling his executeAjax() method. - * - * @param int $pageId Page identifier - * @param int $blockId Block identifier - * - * @return Response + * @param int|string $pageId + * @param int|string $blockId */ - public function execute($pageId, $blockId) + public function execute($pageId, $blockId): Response { $cmsManager = $this->cmsManagerSelector->retrieve(); diff --git a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php index 9297ea4f7..7ad13f492 100644 --- a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php +++ b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php @@ -18,8 +18,6 @@ use Symfony\Component\DependencyInjection\Reference; /** - * GlobalVariablesCompilerPass. - * * @author Thomas Rabaix */ final class GlobalVariablesCompilerPass implements CompilerPassInterface diff --git a/src/DependencyInjection/Compiler/PageServiceCompilerPass.php b/src/DependencyInjection/Compiler/PageServiceCompilerPass.php index fe9e1a359..1ca1f7ef7 100644 --- a/src/DependencyInjection/Compiler/PageServiceCompilerPass.php +++ b/src/DependencyInjection/Compiler/PageServiceCompilerPass.php @@ -18,8 +18,6 @@ use Symfony\Component\DependencyInjection\Reference; /** - * Inject page services into page service manager. - * * @author Olivier Paradis */ final class PageServiceCompilerPass implements CompilerPassInterface diff --git a/src/DependencyInjection/SonataPageExtension.php b/src/DependencyInjection/SonataPageExtension.php index 010eb0307..cc6cf8e4e 100644 --- a/src/DependencyInjection/SonataPageExtension.php +++ b/src/DependencyInjection/SonataPageExtension.php @@ -103,12 +103,9 @@ public function load(array $configs, ContainerBuilder $container): void } /** - * Configure the page default settings. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configurePageDefaults(ContainerBuilder $container, array $config): void + private function configurePageDefaults(ContainerBuilder $container, array $config): void { $defaults = [ 'templateCode' => $config['default_template'], @@ -133,12 +130,9 @@ public function configurePageDefaults(ContainerBuilder $container, array $config } /** - * Registers service parameters from bundle configuration. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function registerParameters(ContainerBuilder $container, array $config): void + private function registerParameters(ContainerBuilder $container, array $config): void { $container->setParameter('sonata.page.site.class', $config['class']['site']); $container->setParameter('sonata.page.block.class', $config['class']['block']); @@ -155,12 +149,9 @@ public function registerParameters(ContainerBuilder $container, array $config): } /** - * Configure the multi-site feature. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configureMultisite(ContainerBuilder $container, array $config): void + private function configureMultisite(ContainerBuilder $container, array $config): void { $multisite = $config['multisite']; @@ -203,12 +194,9 @@ public function configureMultisite(ContainerBuilder $container, array $config): } /** - * Configure the page templates. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configureTemplates(ContainerBuilder $container, array $config): void + private function configureTemplates(ContainerBuilder $container, array $config): void { $templateManager = $container->getDefinition('sonata.page.template_manager'); @@ -232,12 +220,9 @@ public function configureTemplates(ContainerBuilder $container, array $config): } /** - * Configure the page admin templates. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configureTemplatesAdmin(ContainerBuilder $container, array $config): void + private function configureTemplatesAdmin(ContainerBuilder $container, array $config): void { $templateManager = $container->getDefinition('sonata.page.admin.page'); @@ -247,12 +232,9 @@ public function configureTemplatesAdmin(ContainerBuilder $container, array $conf } /** - * Configures the page custom exceptions. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configureExceptions(ContainerBuilder $container, array $config): void + private function configureExceptions(ContainerBuilder $container, array $config): void { $exceptions = []; foreach ($config['catch_exceptions'] as $keyWord => $codes) { @@ -271,12 +253,9 @@ public function configureExceptions(ContainerBuilder $container, array $config): } /** - * Configures the page services. - * - * @param ContainerBuilder $container Container builder - * @param array $config Array of configuration + * @param array $config */ - public function configurePageServices(ContainerBuilder $container, array $config): void + private function configurePageServices(ContainerBuilder $container, array $config): void { // set the default page service to use when no page type has been set. (backward compatibility) $definition = $container->getDefinition('sonata.page.page_service_manager'); diff --git a/src/Entity/BlockInteractor.php b/src/Entity/BlockInteractor.php index d4b5bb3bb..55964b7f1 100644 --- a/src/Entity/BlockInteractor.php +++ b/src/Entity/BlockInteractor.php @@ -17,6 +17,7 @@ use Doctrine\Persistence\ManagerRegistry; use Sonata\PageBundle\Model\BlockInteractorInterface; use Sonata\PageBundle\Model\BlockManagerInterface; +use Sonata\PageBundle\Model\PageBlockInterface; use Sonata\PageBundle\Model\PageInterface; /** @@ -25,7 +26,7 @@ final class BlockInteractor implements BlockInteractorInterface { /** - * @var bool[] + * @var array */ private array $pageBlocksLoaded = []; @@ -33,17 +34,13 @@ final class BlockInteractor implements BlockInteractorInterface private BlockManagerInterface $blockManager; - /** - * @param ManagerRegistry $registry Doctrine registry - * @param BlockManagerInterface $blockManager Block manager - */ public function __construct(ManagerRegistry $registry, BlockManagerInterface $blockManager) { $this->blockManager = $blockManager; $this->registry = $registry; } - public function getBlock($id) + public function getBlock($id): ?PageBlockInterface { $blocks = $this->getEntityManager()->createQueryBuilder() ->select('b') @@ -58,7 +55,7 @@ public function getBlock($id) return $blocks[0] ?? null; } - public function getBlocksById(PageInterface $page) + public function getBlocksById(PageInterface $page): array { $blocks = $this->getEntityManager() ->createQuery(sprintf('SELECT b FROM %s b INDEX BY b.id WHERE b.page = :page ORDER BY b.position ASC', $this->blockManager->getClass())) @@ -70,7 +67,7 @@ public function getBlocksById(PageInterface $page) return $blocks; } - public function saveBlocksPosition(array $data = [], $partial = true) + public function saveBlocksPosition(array $data = [], bool $partial = true): bool { $em = $this->getEntityManager(); $em->getConnection()->beginTransaction(); @@ -95,7 +92,7 @@ public function saveBlocksPosition(array $data = [], $partial = true) return true; } - public function createNewContainer(array $values) + public function createNewContainer(array $values): PageBlockInterface { $container = $this->blockManager->create(); $container->setEnabled($values['enabled'] ?? true); @@ -125,7 +122,7 @@ public function createNewContainer(array $values) return $container; } - public function loadPageBlocks(PageInterface $page) + public function loadPageBlocks(PageInterface $page): array { if (isset($this->pageBlocksLoaded[$page->getId()])) { return []; @@ -156,10 +153,7 @@ public function loadPageBlocks(PageInterface $page) return $blocks; } - /** - * @return EntityManagerInterface - */ - private function getEntityManager() + private function getEntityManager(): EntityManagerInterface { $entityManager = $this->registry->getManagerForClass($this->blockManager->getClass()); \assert($entityManager instanceof EntityManagerInterface); diff --git a/src/Entity/BlockManager.php b/src/Entity/BlockManager.php index 5a16ca16d..0649d7cb7 100644 --- a/src/Entity/BlockManager.php +++ b/src/Entity/BlockManager.php @@ -25,7 +25,7 @@ */ final class BlockManager extends BaseEntityManager implements BlockManagerInterface { - public function updatePosition($id, $position, $parentId = null, $pageId = null, $partial = true) + public function updatePosition($id, int $position, $parentId = null, $pageId = null, bool $partial = true): PageBlockInterface { $entityManager = $this->getEntityManager(); diff --git a/src/Entity/PageManager.php b/src/Entity/PageManager.php index aa51d33af..353ad771b 100644 --- a/src/Entity/PageManager.php +++ b/src/Entity/PageManager.php @@ -58,7 +58,7 @@ public function __construct( $this->pageDefaults = $pageDefaults; } - public function getPageByUrl(SiteInterface $site, $url) + public function getPageByUrl(SiteInterface $site, string $url): ?PageInterface { return $this->findOneBy([ 'url' => $url, @@ -139,7 +139,7 @@ public function save($entity, $andFlush = true): void parent::save($entity, $andFlush); } - public function loadPages(SiteInterface $site) + public function loadPages(SiteInterface $site): array { $siteId = $site->getId(); \assert(null !== $siteId); @@ -165,7 +165,7 @@ public function loadPages(SiteInterface $site) return $pages; } - public function getHybridPages(SiteInterface $site) + public function getHybridPages(SiteInterface $site): array { return $this->getEntityManager()->createQueryBuilder() ->select('p') diff --git a/src/Entity/SnapshotManager.php b/src/Entity/SnapshotManager.php index 32d9d81d1..934d0d753 100644 --- a/src/Entity/SnapshotManager.php +++ b/src/Entity/SnapshotManager.php @@ -83,7 +83,7 @@ public function enableSnapshots(array $snapshots, ?\DateTimeInterface $date = nu $q->execute(); } - public function findEnableSnapshot(array $criteria) + public function findEnableSnapshot(array $criteria): ?SnapshotInterface { $date = new \DateTime(); $parameters = [ @@ -126,12 +126,8 @@ public function findEnableSnapshot(array $criteria) return $query->getQuery()->getOneOrNullResult(); } - public function cleanup(PageInterface $page, $keep) + public function cleanup(PageInterface $page, int $keep): int { - if (!is_numeric($keep)) { - throw new \RuntimeException(sprintf('Please provide an integer value, %s given', \gettype($keep))); - } - $innerQb = $this->getRepository()->createQueryBuilder('i'); $expr = $innerQb->expr(); diff --git a/src/Entity/Transformer.php b/src/Entity/Transformer.php index 30352e37f..4cc61ce3a 100644 --- a/src/Entity/Transformer.php +++ b/src/Entity/Transformer.php @@ -65,7 +65,7 @@ public function __construct( $this->registry = $registry; } - public function create(PageInterface $page) + public function create(PageInterface $page): SnapshotInterface { $snapshot = $this->snapshotManager->create(); @@ -124,7 +124,7 @@ public function create(PageInterface $page) return $snapshot; } - public function load(SnapshotInterface $snapshot) + public function load(SnapshotInterface $snapshot): PageInterface { $page = $this->pageManager->createWithDefaults(); @@ -165,7 +165,7 @@ public function load(SnapshotInterface $snapshot) return $page; } - public function loadBlock(array $content, PageInterface $page) + public function loadBlock(array $content, PageInterface $page): PageBlockInterface { $block = $this->blockManager->create(); @@ -209,7 +209,7 @@ public function loadBlock(array $content, PageInterface $page) return $block; } - public function getChildren(PageInterface $page) + public function getChildren(PageInterface $page): Collection { $id = $page->getId(); \assert(null !== $id); @@ -258,7 +258,7 @@ public function getChildren(PageInterface $page) * * @phpstan-return BlockContent */ - private function createBlock(BlockInterface $block) + private function createBlock(BlockInterface $block): array { $childBlocks = []; diff --git a/src/Exception/InternalErrorException.php b/src/Exception/InternalErrorException.php index d46427aaf..5baefd4cb 100644 --- a/src/Exception/InternalErrorException.php +++ b/src/Exception/InternalErrorException.php @@ -14,8 +14,6 @@ namespace Sonata\PageBundle\Exception; /** - * Exception used to raise an internal error. - * * @author Thomas Rabaix */ final class InternalErrorException extends \RuntimeException diff --git a/src/Exception/PageNotFoundException.php b/src/Exception/PageNotFoundException.php index 67122e3a0..bcb264e56 100644 --- a/src/Exception/PageNotFoundException.php +++ b/src/Exception/PageNotFoundException.php @@ -16,8 +16,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** - * Exception used to handle a page not found situation. - * * @author Thomas Rabaix */ final class PageNotFoundException extends NotFoundHttpException diff --git a/src/Form/Type/CreateSnapshotType.php b/src/Form/Type/CreateSnapshotType.php index 6b80801e2..0ab14aa81 100644 --- a/src/Form/Type/CreateSnapshotType.php +++ b/src/Form/Type/CreateSnapshotType.php @@ -17,8 +17,6 @@ use Symfony\Component\Form\FormBuilderInterface; /** - * Select a Page. - * * @author Thomas Rabaix */ final class CreateSnapshotType extends AbstractType diff --git a/src/Form/Type/PageSelectorType.php b/src/Form/Type/PageSelectorType.php index 32becc4e9..df25a3382 100644 --- a/src/Form/Type/PageSelectorType.php +++ b/src/Form/Type/PageSelectorType.php @@ -51,10 +51,20 @@ public function configureOptions(OptionsResolver $resolver): void ]); } + public function getParent(): string + { + return ModelType::class; + } + + public function getBlockPrefix(): string + { + return 'sonata_page_selector'; + } + /** * @return array */ - public function getChoices(Options $options) + private function getChoices(Options $options): array { if (!$options['site'] instanceof SiteInterface) { return []; @@ -113,22 +123,10 @@ public function getChoices(Options $options) return $choices; } - public function getParent(): string - { - return ModelType::class; - } - - public function getBlockPrefix(): string - { - return 'sonata_page_selector'; - } - /** - * @param PageInterface $currentPage * @param array $choices - * @param int $level */ - private function childWalker(PageInterface $page, ?PageInterface $currentPage, &$choices, $level = 1): void + private function childWalker(PageInterface $page, ?PageInterface $currentPage, array &$choices, int $level = 1): void { foreach ($page->getChildren() as $child) { if (null !== $currentPage && $currentPage->getId() === $child->getId()) { diff --git a/src/Form/Type/PageTypeChoiceType.php b/src/Form/Type/PageTypeChoiceType.php index 01f8dab0c..b92dc43b5 100644 --- a/src/Form/Type/PageTypeChoiceType.php +++ b/src/Form/Type/PageTypeChoiceType.php @@ -19,8 +19,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver; /** - * Select a page type. - * * @author Olivier Paradis */ final class PageTypeChoiceType extends AbstractType @@ -42,10 +40,20 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults($defaults); } + public function getParent(): string + { + return ChoiceType::class; + } + + public function getBlockPrefix(): string + { + return 'sonata_page_type_choice'; + } + /** - * @return string[] + * @return array */ - public function getPageTypes() + private function getPageTypes(): array { $services = $this->manager->getAll(); $types = []; @@ -57,14 +65,4 @@ public function getPageTypes() return $types; } - - public function getParent(): string - { - return ChoiceType::class; - } - - public function getBlockPrefix(): string - { - return 'sonata_page_type_choice'; - } } diff --git a/src/Form/Type/TemplateChoiceType.php b/src/Form/Type/TemplateChoiceType.php index a5cb01ea2..a5b7e48be 100644 --- a/src/Form/Type/TemplateChoiceType.php +++ b/src/Form/Type/TemplateChoiceType.php @@ -19,8 +19,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver; /** - * Select a template. - * * @author Thomas Rabaix */ final class TemplateChoiceType extends AbstractType @@ -43,9 +41,9 @@ public function configureOptions(OptionsResolver $resolver): void } /** - * @return string[] + * @return array */ - public function getTemplates() + public function getTemplates(): array { $templates = []; foreach ($this->manager->getAll() as $code => $template) { diff --git a/src/Listener/ExceptionListener.php b/src/Listener/ExceptionListener.php index 30245852e..6a3a0db00 100644 --- a/src/Listener/ExceptionListener.php +++ b/src/Listener/ExceptionListener.php @@ -54,18 +54,19 @@ final class ExceptionListener private bool $status; /** - * @param SiteSelectorInterface $siteSelector Site selector - * @param CmsManagerSelectorInterface $cmsManagerSelector CMS Manager selector - * @param bool $debug Debug mode - * @param Environment $twig Twig engine - * @param PageServiceManagerInterface $pageServiceManager Page service manager - * @param DecoratorStrategyInterface $decoratorStrategy Decorator strategy - * @param array $httpErrorCodes An array of http error codes' routes - * @param LoggerInterface|null $logger Logger instance - * @param bool $status log 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, ?LoggerInterface $logger = null, bool $status = false) - { + public function __construct( + SiteSelectorInterface $siteSelector, + CmsManagerSelectorInterface $cmsManagerSelector, + bool $debug, + Environment $twig, + PageServiceManagerInterface $pageServiceManager, + DecoratorStrategyInterface $decoratorStrategy, + array $httpErrorCodes, + ?LoggerInterface $logger = null, + bool $status = false + ) { $this->siteSelector = $siteSelector; $this->cmsManagerSelector = $cmsManagerSelector; $this->debug = $debug; @@ -224,12 +225,7 @@ private function handleNativeError(ExceptionEvent $event): void $event->setResponse($response); } - /** - * @param \Throwable $originalException Original exception that called the listener - * @param \Throwable $generatedException Generated exception - * @param string|null $message Message to log - */ - private function logException(\Throwable $originalException, \Throwable $generatedException, $message = null): 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()); diff --git a/src/Listener/RequestListener.php b/src/Listener/RequestListener.php index f1237949b..c72a224a3 100644 --- a/src/Listener/RequestListener.php +++ b/src/Listener/RequestListener.php @@ -35,28 +35,23 @@ final class RequestListener private DecoratorStrategyInterface $decoratorStrategy; - /** - * @param CmsManagerSelectorInterface $cmsSelector Cms manager selector - * @param SiteSelectorInterface $siteSelector Site selector - * @param DecoratorStrategyInterface $decoratorStrategy Decorator strategy - */ - public function __construct(CmsManagerSelectorInterface $cmsSelector, SiteSelectorInterface $siteSelector, DecoratorStrategyInterface $decoratorStrategy) - { + public function __construct( + CmsManagerSelectorInterface $cmsSelector, + SiteSelectorInterface $siteSelector, + DecoratorStrategyInterface $decoratorStrategy + ) { $this->cmsSelector = $cmsSelector; $this->siteSelector = $siteSelector; $this->decoratorStrategy = $decoratorStrategy; } /** - * Filter the `core.request` event to decorated the action. - * * @throws InternalErrorException * @throws PageNotFoundException */ public function onCoreRequest(RequestEvent $event): void { $request = $event->getRequest(); - $cms = $this->cmsSelector->retrieve(); // true cms page diff --git a/src/Listener/ResponseListener.php b/src/Listener/ResponseListener.php index f6b53a3db..0abee0c6a 100644 --- a/src/Listener/ResponseListener.php +++ b/src/Listener/ResponseListener.php @@ -40,13 +40,6 @@ final class ResponseListener private bool $skipRedirection; - /** - * @param CmsManagerSelectorInterface $cmsSelector CMS manager selector - * @param PageServiceManagerInterface $pageServiceManager Page service manager - * @param DecoratorStrategyInterface $decoratorStrategy Decorator strategy - * @param Environment $twig Twig engine - * @param bool $skipRedirection To skip the redirection by configuration - */ public function __construct( CmsManagerSelectorInterface $cmsSelector, PageServiceManagerInterface $pageServiceManager, @@ -62,8 +55,6 @@ public function __construct( } /** - * Filter the `kernel.response` event to decorate the action. - * * @throws InternalErrorException */ public function onCoreResponse(ResponseEvent $event): void diff --git a/src/Model/Block.php b/src/Model/Block.php index 92ca1eba3..c8a12c0a1 100644 --- a/src/Model/Block.php +++ b/src/Model/Block.php @@ -38,7 +38,7 @@ public function setId($id): void $this->id = $id; } - public function getPage() + public function getPage(): ?PageInterface { return $this->page; } diff --git a/src/Model/BlockInteractorInterface.php b/src/Model/BlockInteractorInterface.php index c020126a9..7195a7ada 100644 --- a/src/Model/BlockInteractorInterface.php +++ b/src/Model/BlockInteractorInterface.php @@ -19,27 +19,19 @@ interface BlockInteractorInterface { /** - * Return a block with the given id. - * * @param int|string $id - * - * @return PageBlockInterface|null */ - public function getBlock($id); + public function getBlock($id): ?PageBlockInterface; /** - * Return a flat list if page's blocks. - * * @return array */ - public function getBlocksById(PageInterface $page); + public function getBlocksById(PageInterface $page): array; /** - * Load blocks attached the given page. - * * @return array */ - public function loadPageBlocks(PageInterface $page); + public function loadPageBlocks(PageInterface $page): array; /** * Save the blocks positions. Partial references are allowed. @@ -51,11 +43,8 @@ public function loadPageBlocks(PageInterface $page); * parent_id?: int|string|null, * page_id?: int|string|null, * }> $data - * @param bool $partial - * - * @return bool */ - public function saveBlocksPosition(array $data = [], $partial = true); + public function saveBlocksPosition(array $data = [], bool $partial = true): bool; /** * @param array{ @@ -66,8 +55,6 @@ public function saveBlocksPosition(array $data = [], $partial = true); * position?: int, * parent?: PageBlockInterface|null, * } $values An array of values for container creation - * - * @return PageBlockInterface */ - public function createNewContainer(array $values); + public function createNewContainer(array $values): PageBlockInterface; } diff --git a/src/Model/BlockManagerInterface.php b/src/Model/BlockManagerInterface.php index 038d93402..78b520469 100644 --- a/src/Model/BlockManagerInterface.php +++ b/src/Model/BlockManagerInterface.php @@ -21,15 +21,12 @@ interface BlockManagerInterface extends ManagerInterface { /** - * Updates position for given block. + * Update blocks position. Partial references are allowed. + * Better for performance, but can lead to query issues. * - * @param int|string $id Block Id - * @param int $position New Position + * @param int|string $id * @param int|string|null $parentId Parent block Id (needed when partial = true) * @param int|string|null $pageId Page Id (needed when partial = true) - * @param bool $partial Should we use partial references? (Better for performance, but can lead to query issues.) - * - * @return PageBlockInterface */ - public function updatePosition($id, $position, $parentId = null, $pageId = null, $partial = true); + public function updatePosition($id, int $position, $parentId = null, $pageId = null, bool $partial = true): PageBlockInterface; } diff --git a/src/Model/Page.php b/src/Model/Page.php index 7ff48e752..9dd53f1a8 100755 --- a/src/Model/Page.php +++ b/src/Model/Page.php @@ -26,145 +26,76 @@ abstract class Page implements PageInterface */ protected $id = null; - /** - * @var string|null - */ - protected $title = null; + protected ?string $title = null; - /** - * @var string|null - */ - protected $routeName = PageInterface::PAGE_ROUTE_CMS_NAME; + protected ?string $routeName = PageInterface::PAGE_ROUTE_CMS_NAME; - /** - * @var string|null - */ - protected $pageAlias = null; + protected ?string $pageAlias = null; - /** - * @var string|null - */ - protected $type = null; + protected ?string $type = null; - /** - * @var bool - */ - protected $enabled = false; + protected bool $enabled = false; - /** - * @var string|null - */ - protected $name = null; + protected ?string $name = null; - /** - * @var string|null - */ - protected $slug = null; + protected ?string $slug = null; - /** - * @var string|null - */ - protected $url = null; + protected ?string $url = null; - /** - * @var string|null - */ - protected $customUrl = null; + protected ?string $customUrl = null; - /** - * @var string|null - */ - protected $metaKeyword = null; + protected ?string $metaKeyword = null; - /** - * @var string|null - */ - protected $metaDescription = null; + protected ?string $metaDescription = null; - /** - * @var string|null - */ - protected $javascript = null; + protected ?string $javascript = null; - /** - * @var string|null - */ - protected $stylesheet = null; + protected ?string $stylesheet = null; - /** - * @var \DateTimeInterface|null - */ - protected $createdAt = null; + protected ?\DateTimeInterface $createdAt = null; - /** - * @var \DateTimeInterface|null - */ - protected $updatedAt = null; + protected ?\DateTimeInterface $updatedAt = null; /** * @var Collection */ - protected $children; + protected Collection $children; /** * @var Collection */ - protected $blocks; + protected Collection $blocks; - /** - * @var PageInterface|null - */ - protected $parent = null; + protected ?PageInterface $parent = null; /** * @var array|null */ - protected $parents = null; + protected ?array $parents = null; - /** - * @var string|null - */ - protected $templateCode = null; + protected ?string $templateCode = null; - /** - * @var bool - */ - protected $decorate = true; + protected bool $decorate = true; - /** - * @var int|null - */ - protected $position = 1; + protected ?int $position = 1; - /** - * @var string|null - */ - protected $requestMethod = 'GET|POST|HEAD|DELETE|PUT'; + protected ?string $requestMethod = 'GET|POST|HEAD|DELETE|PUT'; /** - * @var array + * @var array|null */ - protected $headers = []; + protected ?array $headers = null; - /** - * @var string|null - */ - protected $rawHeaders = null; + protected ?string $rawHeaders = null; - /** - * @var SiteInterface|null - */ - protected $site = null; + protected ?SiteInterface $site = null; - /** - * @var bool - */ - protected $edited = true; + protected bool $edited = true; /** * @var array */ - protected $snapshots = []; + protected array $snapshots = []; public function __construct() { @@ -172,7 +103,7 @@ public function __construct() $this->children = new ArrayCollection(); } - public function __toString() + public function __toString(): string { return $this->getName() ?? '-'; } @@ -187,32 +118,32 @@ public function setId($id): void $this->id = $id; } - public function getTitle() + public function getTitle(): ?string { return $this->title; } - public function setTitle($title): void + public function setTitle(?string $title): void { $this->title = $title; } - public function getRouteName() + public function getRouteName(): ?string { return $this->routeName; } - public function setRouteName($routeName): void + public function setRouteName(?string $routeName): void { $this->routeName = $routeName; } - public function getPageAlias() + public function getPageAlias(): ?string { return $this->pageAlias; } - public function setPageAlias($pageAlias): void + public function setPageAlias(?string $pageAlias): void { if ('_page_alias_' !== substr((string) $pageAlias, 0, 12)) { $pageAlias = '_page_alias_'.$pageAlias; @@ -221,107 +152,107 @@ public function setPageAlias($pageAlias): void $this->pageAlias = $pageAlias; } - public function getType() + public function getType(): ?string { return $this->type; } - public function setType($type): void + public function setType(?string $type): void { $this->type = $type; } - public function getEnabled() + public function getEnabled(): bool { return $this->enabled; } - public function setEnabled($enabled): void + public function setEnabled(bool $enabled): void { $this->enabled = $enabled; } - public function getName() + public function getName(): ?string { return $this->name; } - public function setName($name): void + public function setName(?string $name): void { $this->name = $name; } - public function getSlug() + public function getSlug(): ?string { return $this->slug; } - public function setSlug($slug): void + public function setSlug(?string $slug): void { $this->slug = $slug; } - public function getUrl() + public function getUrl(): ?string { return $this->url; } - public function setUrl($url): void + public function setUrl(?string $url): void { $this->url = $url; } - public function getCustomUrl() + public function getCustomUrl(): ?string { return $this->customUrl; } - public function setCustomUrl($customUrl): void + public function setCustomUrl(?string $customUrl): void { $this->customUrl = $customUrl; } - public function getMetaKeyword() + public function getMetaKeyword(): ?string { return $this->metaKeyword; } - public function setMetaKeyword($metaKeyword): void + public function setMetaKeyword(?string $metaKeyword): void { $this->metaKeyword = $metaKeyword; } - public function getMetaDescription() + public function getMetaDescription(): ?string { return $this->metaDescription; } - public function setMetaDescription($metaDescription): void + public function setMetaDescription(?string $metaDescription): void { $this->metaDescription = $metaDescription; } - public function getJavascript() + public function getJavascript(): ?string { return $this->javascript; } - public function setJavascript($javascript): void + public function setJavascript(?string $javascript): void { $this->javascript = $javascript; } - public function getStylesheet() + public function getStylesheet(): ?string { return $this->stylesheet; } - public function setStylesheet($stylesheet): void + public function setStylesheet(?string $stylesheet): void { $this->stylesheet = $stylesheet; } - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } @@ -331,7 +262,7 @@ public function setCreatedAt(?\DateTimeInterface $createdAt = null): void $this->createdAt = $createdAt; } - public function getUpdatedAt() + public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } @@ -341,12 +272,12 @@ public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void $this->updatedAt = $updatedAt; } - public function getChildren() + public function getChildren(): Collection { return $this->children; } - public function setChildren($children): void + public function setChildren(Collection $children): void { $this->children = $children; } @@ -358,7 +289,7 @@ public function addChild(PageInterface $child): void $child->setParent($this); } - public function getBlocks() + public function getBlocks(): Collection { return $this->blocks; } @@ -370,7 +301,7 @@ public function addBlock(PageBlockInterface $block): void $this->blocks[] = $block; } - public function getContainerByCode($code) + public function getContainerByCode(string $code): ?PageBlockInterface { foreach ($this->getBlocks() as $block) { if (\in_array($block->getType(), ['sonata.page.block.container', 'sonata.block.service.container'], true) && $block->getSetting('code') === $code) { @@ -381,7 +312,7 @@ public function getContainerByCode($code) return null; } - public function getBlocksByType($type) + public function getBlocksByType(string $type): array { $blocks = []; @@ -394,7 +325,7 @@ public function getBlocksByType($type) return $blocks; } - public function getParent($level = -1) + public function getParent(int $level = -1): ?PageInterface { if (-1 === $level) { return $this->parent; @@ -414,7 +345,7 @@ public function setParent(?PageInterface $parent = null): void $this->parent = $parent; } - public function getParents() + public function getParents(): array { if (null === $this->parents) { $parent = $this->getParent(); @@ -437,47 +368,47 @@ public function setParents(array $parents): void $this->parents = $parents; } - public function getTemplateCode() + public function getTemplateCode(): ?string { return $this->templateCode; } - public function setTemplateCode($templateCode): void + public function setTemplateCode(?string $templateCode): void { $this->templateCode = $templateCode; } - public function getDecorate() + public function getDecorate(): bool { return $this->decorate; } - public function setDecorate($decorate): void + public function setDecorate(bool $decorate): void { $this->decorate = $decorate; } - public function getPosition() + public function getPosition(): ?int { return $this->position; } - public function setPosition($position): void + public function setPosition(?int $position): void { $this->position = $position; } - public function getRequestMethod() + public function getRequestMethod(): ?string { return $this->requestMethod; } - public function setRequestMethod($method): void + public function setRequestMethod(?string $method): void { $this->requestMethod = $method; } - public function hasRequestMethod($method) + public function hasRequestMethod(string $method): bool { $method = strtoupper($method); @@ -495,7 +426,7 @@ public function getHeaders(): array if (null === $this->headers) { $rawHeaders = $this->getRawHeaders(); - $this->headers = $this->getHeadersAsArray($rawHeaders); + $this->headers = null !== $rawHeaders ? $this->getHeadersAsArray($rawHeaders) : []; } return $this->headers; @@ -505,12 +436,13 @@ public function setHeaders(array $headers = []): void { $this->headers = []; $this->rawHeaders = null; + foreach ($headers as $name => $header) { $this->addHeader($name, $header); } } - public function addHeader($name, $value): void + public function addHeader(string $name, $value): void { $headers = $this->getHeaders(); @@ -521,19 +453,17 @@ public function addHeader($name, $value): void $this->rawHeaders = $this->getHeadersAsString($headers); } - public function getRawHeaders() + public function getRawHeaders(): ?string { return $this->rawHeaders; } - public function setRawHeaders($rawHeaders): void + public function setRawHeaders(?string $rawHeaders): void { - $headers = $this->getHeadersAsArray($rawHeaders); - - $this->setHeaders($headers); + $this->setHeaders(null !== $rawHeaders ? $this->getHeadersAsArray($rawHeaders) : []); } - public function getSite() + public function getSite(): ?SiteInterface { return $this->site; } @@ -543,27 +473,27 @@ public function setSite(?SiteInterface $site = null): void $this->site = $site; } - public function getEdited() + public function getEdited(): bool { return $this->edited; } - public function setEdited($edited): void + public function setEdited(bool $edited): void { $this->edited = $edited; } - public function getSnapshots() + public function getSnapshots(): array { return $this->snapshots; } - public function setSnapshots($snapshots): void + public function setSnapshots(array $snapshots): void { $this->snapshots = $snapshots; } - public function getSnapshot() + public function getSnapshot(): ?SnapshotInterface { return $this->snapshots[0] ?? null; } @@ -575,41 +505,39 @@ public function addSnapshot(SnapshotInterface $snapshot): void $snapshot->setPage($this); } - public function isError() + public function isError(): bool { return '_page_internal_error_' === substr($this->getRouteName() ?? '', 0, 21); } - public function isHybrid() + public function isHybrid(): bool { return PageInterface::PAGE_ROUTE_CMS_NAME !== $this->getRouteName() && !$this->isInternal(); } - public function isDynamic() + public function isDynamic(): bool { return $this->isHybrid() && false !== strpos($this->getUrl() ?? '', '{'); } - public function isCms() + public function isCms(): bool { return PageInterface::PAGE_ROUTE_CMS_NAME === $this->getRouteName() && !$this->isInternal(); } - public function isInternal() + public function isInternal(): bool { return '_page_internal_' === substr($this->getRouteName() ?? '', 0, 15); } /** - * @param string|null $rawHeaders - * * @return array */ - private function getHeadersAsArray($rawHeaders) + private function getHeadersAsArray(string $rawHeaders): array { $headers = []; - foreach (explode("\r\n", (string) $rawHeaders) as $header) { + foreach (explode("\r\n", $rawHeaders) as $header) { if (false !== strpos($header, ':')) { [$name, $headerStr] = explode(':', $header, 2); $headers[trim($name)] = trim($headerStr); @@ -621,10 +549,8 @@ private function getHeadersAsArray($rawHeaders) /** * @param array $headers - * - * @return string */ - private function getHeadersAsString(array $headers) + private function getHeadersAsString(array $headers): string { $rawHeaders = []; diff --git a/src/Model/PageBlockInterface.php b/src/Model/PageBlockInterface.php index f6fb537d5..30d11e693 100644 --- a/src/Model/PageBlockInterface.php +++ b/src/Model/PageBlockInterface.php @@ -17,13 +17,7 @@ interface PageBlockInterface extends BlockInterface { - /** - * @return PageInterface|null - */ - public function getPage(); + public function getPage(): ?PageInterface; - /** - * @return void - */ - public function setPage(?PageInterface $page = null); + public function setPage(?PageInterface $page = null): void; } diff --git a/src/Model/PageInterface.php b/src/Model/PageInterface.php index be56db408..04a502ebf 100644 --- a/src/Model/PageInterface.php +++ b/src/Model/PageInterface.php @@ -22,10 +22,7 @@ interface PageInterface extends \Stringable { public const PAGE_ROUTE_CMS_NAME = 'page_slug'; - /** - * @return string - */ - public function __toString(); + public function __toString(): string; /** * @return int|string|null @@ -34,39 +31,18 @@ public function getId(); /** * @param int|string|null $id - * - * @return void */ - public function setId($id); + public function setId($id): void; - /** - * @return string|null - */ - public function getTitle(); + public function getTitle(): ?string; - /** - * @param string|null $title - * - * @return void - */ - public function setTitle($title); + public function setTitle(?string $title): void; - /** - * @return string|null - */ - public function getRouteName(); + public function getRouteName(): ?string; - /** - * @param string|null $routeName - * - * @return void - */ - public function setRouteName($routeName); + public function setRouteName(?string $routeName): void; - /** - * @return string|null - */ - public function getPageAlias(); + public function getPageAlias(): ?string; /** * The route alias defines an internal url code that user can use to point @@ -74,272 +50,117 @@ public function getPageAlias(); * * For performance, all pageAlias must be prefixed by _page_alias_ this will avoid * database lookup to load non existent alias - * - * @param string|null $pageAlias - * - * @return void */ - public function setPageAlias($pageAlias); + public function setPageAlias(?string $pageAlias): void; - /** - * @return string|null - */ - public function getType(); + public function getType(): ?string; - /** - * @param string|null $type - * - * @return void - */ - public function setType($type); + public function setType(?string $type): void; - /** - * @return bool $enabled - */ - public function getEnabled(); + public function getEnabled(): bool; - /** - * @param bool $enabled - * - * @return void - */ - public function setEnabled($enabled); + public function setEnabled(bool $enabled): void; - /** - * @return string|null $name - */ - public function getName(); + public function getName(): ?string; - /** - * @param string|null $name - * - * @return void - */ - public function setName($name); + public function setName(?string $name): void; - /** - * @return string|null - */ - public function getSlug(); + public function getSlug(): ?string; - /** - * @param string|null $slug - * - * @return void - */ - public function setSlug($slug); + public function setSlug(?string $slug): void; - /** - * @return string|null - */ - public function getUrl(); + public function getUrl(): ?string; - /** - * @param string|null $url - * - * @return void - */ - public function setUrl($url); + public function setUrl(?string $url): void; - /** - * @return string|null - */ - public function getCustomUrl(); + public function getCustomUrl(): ?string; - /** - * @param string|null $customUrl - * - * @return void - */ - public function setCustomUrl($customUrl); + public function setCustomUrl(?string $customUrl): void; - /** - * @return string|null - */ - public function getMetaKeyword(); + public function getMetaKeyword(): ?string; - /** - * @param string|null $metaKeyword - * - * @return void - */ - public function setMetaKeyword($metaKeyword); + public function setMetaKeyword(?string $metaKeyword): void; - /** - * @return string|null - */ - public function getMetaDescription(); + public function getMetaDescription(): ?string; - /** - * @param string|null $metaDescription - * - * @return void - */ - public function setMetaDescription($metaDescription); + public function setMetaDescription(?string $metaDescription): void; - /** - * @return string|null - */ - public function getJavascript(); + public function getJavascript(): ?string; - /** - * @param string|null $javascript - * - * @return void - */ - public function setJavascript($javascript); + public function setJavascript(?string $javascript): void; - /** - * @return string|null - */ - public function getStylesheet(); + public function getStylesheet(): ?string; - /** - * @param string|null $stylesheet - * - * @return void - */ - public function setStylesheet($stylesheet); + public function setStylesheet(?string $stylesheet): void; - /** - * @return \DateTimeInterface|null - */ - public function getCreatedAt(); + public function getCreatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setCreatedAt(?\DateTimeInterface $createdAt = null); + public function setCreatedAt(?\DateTimeInterface $createdAt = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getUpdatedAt(); + public function getUpdatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setUpdatedAt(?\DateTimeInterface $updatedAt = null); + public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void; /** * @return Collection */ - public function getChildren(); + public function getChildren(): Collection; /** * @param Collection $children */ - public function setChildren($children): void; + public function setChildren(Collection $children): void; - /** - * @return void - */ - public function addChild(self $child); + public function addChild(self $child): void; /** * @return Collection */ - public function getBlocks(); + public function getBlocks(): Collection; - /** - * @return void - */ - public function addBlock(PageBlockInterface $block); + public function addBlock(PageBlockInterface $block): void; - /** - * @param string $code - * - * @return PageBlockInterface|null - */ - public function getContainerByCode($code); + public function getContainerByCode(string $code): ?PageBlockInterface; /** - * @param string $type - * * @return array */ - public function getBlocksByType($type); + public function getBlocksByType(string $type): array; - /** - * @param int $level - * - * @return PageInterface|null - */ - public function getParent($level = -1); + public function getParent(int $level = -1): ?self; - /** - * @return void - */ - public function setParent(?self $parent = null); + public function setParent(?self $parent = null): void; /** * @return array */ - public function getParents(); + public function getParents(): array; /** * @param array $parents - * - * @return void */ - public function setParents(array $parents); + public function setParents(array $parents): void; - /** - * @return string|null - */ - public function getTemplateCode(); + public function getTemplateCode(): ?string; - /** - * @param string|null $templateCode - * - * @return void - */ - public function setTemplateCode($templateCode); + public function setTemplateCode(?string $templateCode): void; - /** - * @return bool - */ - public function getDecorate(); + public function getDecorate(): bool; /** * Indicates if the page should be decorated with the CMS outer layout. - * - * @param bool $decorate - * - * @return void */ - public function setDecorate($decorate); + public function setDecorate(bool $decorate): void; - /** - * @return int|null - */ - public function getPosition(); + public function getPosition(): ?int; - /** - * @param int|null $position - * - * @return void - */ - public function setPosition($position); + public function setPosition(?int $position): void; - /** - * @return string|null - */ - public function getRequestMethod(); + public function getRequestMethod(): ?string; - /** - * @param string|null $method - * - * @return void - */ - public function setRequestMethod($method); + public function setRequestMethod(?string $method): void; - /** - * @param string $method - * - * @return bool - */ - public function hasRequestMethod($method); + public function hasRequestMethod(string $method): bool; /** * @return array @@ -348,101 +169,60 @@ public function getHeaders(): array; /** * @param array $headers - * - * @return void */ - public function setHeaders(array $headers = []); + public function setHeaders(array $headers = []): void; /** - * @param string $name - * @param mixed $value - * - * @return void + * @param mixed $value */ - public function addHeader($name, $value); + public function addHeader(string $name, $value): void; - /** - * @return string|null - */ - public function getRawHeaders(); + public function getRawHeaders(): ?string; - /** - * @param string|null $rawHeaders - * - * @return void - */ - public function setRawHeaders($rawHeaders); + public function setRawHeaders(?string $rawHeaders): void; - /** - * @return SiteInterface|null - */ - public function getSite(); + public function getSite(): ?SiteInterface; - /** - * @return void - */ - public function setSite(?SiteInterface $site = null); + public function setSite(?SiteInterface $site = null): void; - /** - * @return bool - */ - public function getEdited(); + public function getEdited(): bool; - /** - * @param bool $edited - * - * @return void - */ - public function setEdited($edited); + public function setEdited(bool $edited): void; /** * @return array */ - public function getSnapshots(); + public function getSnapshots(): array; /** * @param array $snapshots */ - public function setSnapshots($snapshots): void; + public function setSnapshots(array $snapshots): void; - /** - * @return SnapshotInterface|null - */ - public function getSnapshot(); + public function getSnapshot(): ?SnapshotInterface; public function addSnapshot(SnapshotInterface $snapshot): void; - /** - * @return bool - */ - public function isError(); + public function isError(): bool; /** * Returns true if the page is hybrid (symfony action with no parameter). - * - * @return bool */ - public function isHybrid(); + public function isHybrid(): bool; /** * Returns true if the page is dynamic (symfony action with parameter). - * - * @return bool */ - public function isDynamic(); + public function isDynamic(): bool; /** * Returns true if the page is static. - * - * @return bool */ - public function isCms(); + public function isCms(): bool; /** * Returns true if the page is internal (no direct access with an url) * This is used to define transversal page. - * - * @return bool */ - public function isInternal(); + public function isInternal(): bool; } diff --git a/src/Model/PageManagerInterface.php b/src/Model/PageManagerInterface.php index 2334787df..f3d154115 100644 --- a/src/Model/PageManagerInterface.php +++ b/src/Model/PageManagerInterface.php @@ -27,27 +27,19 @@ interface PageManagerInterface extends ManagerInterface */ public function createWithDefaults(array $defaults = []): PageInterface; - /** - * @param string $url - * - * @return PageInterface|null - */ - public function getPageByUrl(SiteInterface $site, $url); + public function getPageByUrl(SiteInterface $site, string $url): ?PageInterface; /** * Returns an array of Pages Entity where the id is the key. * * @return array */ - public function loadPages(SiteInterface $site); + public function loadPages(SiteInterface $site): array; /** * @return array */ - public function getHybridPages(SiteInterface $site); + public function getHybridPages(SiteInterface $site): array; - /** - * @return void - */ - public function fixUrl(PageInterface $page); + public function fixUrl(PageInterface $page): void; } diff --git a/src/Model/Site.php b/src/Model/Site.php index 3c7953790..a57cbb4f0 100644 --- a/src/Model/Site.php +++ b/src/Model/Site.php @@ -23,72 +23,33 @@ abstract class Site implements SiteInterface */ protected $id = null; - /** - * @var string|null - */ - protected $name = null; + protected ?string $name = null; - /** - * @var string|null - */ - protected $title = null; + protected ?string $title = null; - /** - * @var string|null - */ - protected $host = null; + protected ?string $host = null; - /** - * @var string|null - */ - protected $locale; + protected ?string $locale = null; - /** - * @var \DateTimeInterface|null - */ - protected $enabledFrom = null; + protected ?\DateTimeInterface $enabledFrom = null; - /** - * @var \DateTimeInterface|null - */ - protected $enabledTo = null; + protected ?\DateTimeInterface $enabledTo = null; - /** - * @var bool - */ - protected $isDefault = false; + protected bool $isDefault = false; - /** - * @var string|null - */ - protected $relativePath = null; + protected ?string $relativePath = null; - /** - * @var bool - */ - protected $enabled = false; + protected bool $enabled = false; - /** - * @var \DateTimeInterface|null - */ - protected $createdAt = null; + protected ?\DateTimeInterface $createdAt = null; - /** - * @var \DateTimeInterface|null - */ - protected $updatedAt = null; + protected ?\DateTimeInterface $updatedAt = null; - /** - * @var string|null - */ - protected $metaDescription = null; + protected ?string $metaDescription = null; - /** - * @var string|null - */ - protected $metaKeywords = null; + protected ?string $metaKeywords = null; - public function __toString() + public function __toString(): string { return $this->getName() ?? 'n/a'; } @@ -98,47 +59,47 @@ public function getId() return $this->id; } - public function getName() + public function getName(): ?string { return $this->name; } - public function setName($name): void + public function setName(?string $name): void { $this->name = $name; } - public function getTitle() + public function getTitle(): ?string { return $this->title; } - public function setTitle($title): void + public function setTitle(?string $title): void { $this->title = $title; } - public function getHost() + public function getHost(): ?string { return $this->host; } - public function setHost($host): void + public function setHost(?string $host): void { $this->host = $host; } - public function getLocale() + public function getLocale(): ?string { return $this->locale; } - public function setLocale($locale): void + public function setLocale(?string $locale): void { $this->locale = $locale; } - public function getEnabledFrom() + public function getEnabledFrom(): ?\DateTimeInterface { return $this->enabledFrom; } @@ -148,7 +109,7 @@ public function setEnabledFrom(?\DateTimeInterface $enabledFrom = null): void $this->enabledFrom = $enabledFrom; } - public function getEnabledTo() + public function getEnabledTo(): ?\DateTimeInterface { return $this->enabledTo; } @@ -158,37 +119,37 @@ public function setEnabledTo(?\DateTimeInterface $enabledTo = null): void $this->enabledTo = $enabledTo; } - public function getIsDefault() + public function getIsDefault(): bool { return $this->isDefault; } - public function setIsDefault($default): void + public function setIsDefault(bool $default): void { $this->isDefault = $default; } - public function getRelativePath() + public function getRelativePath(): ?string { return $this->relativePath; } - public function setRelativePath($path): void + public function setRelativePath(?string $path): void { $this->relativePath = $path; } - public function getEnabled() + public function getEnabled(): bool { return $this->enabled; } - public function setEnabled($enabled): void + public function setEnabled(bool $enabled): void { $this->enabled = $enabled; } - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } @@ -198,7 +159,7 @@ public function setCreatedAt(?\DateTimeInterface $createdAt = null): void $this->createdAt = $createdAt; } - public function getUpdatedAt() + public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } @@ -208,27 +169,27 @@ public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void $this->updatedAt = $updatedAt; } - public function getMetaDescription() + public function getMetaDescription(): ?string { return $this->metaDescription; } - public function setMetaDescription($metaDescription): void + public function setMetaDescription(?string $metaDescription): void { $this->metaDescription = $metaDescription; } - public function getMetaKeywords() + public function getMetaKeywords(): ?string { return $this->metaKeywords; } - public function setMetaKeywords($metaKeywords): void + public function setMetaKeywords(?string $metaKeywords): void { $this->metaKeywords = $metaKeywords; } - public function getUrl() + public function getUrl(): ?string { if ($this->isLocalhost()) { return $this->getRelativePath(); @@ -237,7 +198,7 @@ public function getUrl() return sprintf('//%s%s', $this->getHost() ?? '', $this->getRelativePath() ?? ''); } - public function isEnabled() + public function isEnabled(): bool { $now = new \DateTime(); @@ -254,7 +215,7 @@ public function isEnabled() return $this->enabled; } - public function isLocalhost() + public function isLocalhost(): bool { return 'localhost' === $this->getHost(); } diff --git a/src/Model/SiteInterface.php b/src/Model/SiteInterface.php index 90c6b2b92..3ec770fb0 100644 --- a/src/Model/SiteInterface.php +++ b/src/Model/SiteInterface.php @@ -18,176 +18,68 @@ */ interface SiteInterface { - /** - * @return string - */ - public function __toString(); + public function __toString(): string; /** * @return int|string|null */ public function getId(); - /** - * @return string|null - */ - public function getName(); + public function getName(): ?string; - /** - * @param string|null $name - * - * @return void - */ - public function setName($name); + public function setName(?string $name): void; - /** - * @return string|null - */ - public function getTitle(); + public function getTitle(): ?string; - /** - * @param string|null $title - * - * @return void - */ - public function setTitle($title); + public function setTitle(?string $title): void; - /** - * @return string|null - */ - public function getHost(); + public function getHost(): ?string; - /** - * @param string|null $host - * - * @return void - */ - public function setHost($host); + public function setHost(?string $host): void; - /** - * @return string|null - */ - public function getLocale(); + public function getLocale(): ?string; - /** - * @param string|null $locale - * - * @return void - */ - public function setLocale($locale); + public function setLocale(?string $locale): void; - /** - * @return \DateTimeInterface|null - */ - public function getEnabledFrom(); + public function getEnabledFrom(): ?\DateTimeInterface; - /** - * @return void - */ - public function setEnabledFrom(?\DateTimeInterface $enabledFrom = null); + public function setEnabledFrom(?\DateTimeInterface $enabledFrom = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getEnabledTo(); + public function getEnabledTo(): ?\DateTimeInterface; - /** - * @return void - */ - public function setEnabledTo(?\DateTimeInterface $enabledTo = null); + public function setEnabledTo(?\DateTimeInterface $enabledTo = null): void; - /** - * @return bool - */ - public function getIsDefault(); + public function getIsDefault(): bool; - /** - * @param bool $default - * - * @return void - */ - public function setIsDefault($default); + public function setIsDefault(bool $default): void; - /** - * @return string|null - */ - public function getRelativePath(); + public function getRelativePath(): ?string; - /** - * @param string|null $path - * - * @return void - */ - public function setRelativePath($path); + public function setRelativePath(?string $path): void; - /** - * @return bool $enabled - */ - public function getEnabled(); + public function getEnabled(): bool; - /** - * @param bool $enabled - * - * @return void - */ - public function setEnabled($enabled); + public function setEnabled(bool $enabled): void; - /** - * @return \DateTimeInterface|null - */ - public function getCreatedAt(); + public function getCreatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setCreatedAt(?\DateTimeInterface $createdAt = null); + public function setCreatedAt(?\DateTimeInterface $createdAt = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getUpdatedAt(); + public function getUpdatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setUpdatedAt(?\DateTimeInterface $updatedAt = null); + public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void; - /** - * @return string|null - */ - public function getMetaDescription(); + public function getMetaDescription(): ?string; - /** - * @param string|null $metaDescription - * - * @return void - */ - public function setMetaDescription($metaDescription); + public function setMetaDescription(?string $metaDescription): void; - /** - * @return string|null - */ - public function getMetaKeywords(); + public function getMetaKeywords(): ?string; - /** - * @param string|null $metaKeywords - * - * @return void - */ - public function setMetaKeywords($metaKeywords); + public function setMetaKeywords(?string $metaKeywords): void; - /** - * @return string|null - */ - public function getUrl(); + public function getUrl(): ?string; - /** - * @return bool - */ - public function isEnabled(); + public function isEnabled(): bool; - /** - * @return bool - */ - public function isLocalhost(); + public function isLocalhost(): bool; } diff --git a/src/Model/Snapshot.php b/src/Model/Snapshot.php index 0607d3554..b54e71beb 100644 --- a/src/Model/Snapshot.php +++ b/src/Model/Snapshot.php @@ -25,94 +25,52 @@ abstract class Snapshot implements SnapshotInterface */ protected $id = null; - /** - * @var string|null - */ - protected $routeName = null; + protected ?string $routeName = null; - /** - * @var string|null - */ - protected $pageAlias = null; + protected ?string $pageAlias = null; - /** - * @var string|null - */ - protected $type = null; + protected ?string $type = null; - /** - * @var bool - */ - protected $enabled = false; + protected bool $enabled = false; - /** - * @var string|null - */ - protected $name = null; + protected ?string $name = null; - /** - * @var string|null - */ - protected $url = null; + protected ?string $url = null; - /** - * @var \DateTimeInterface|null - */ - protected $publicationDateStart = null; + protected ?\DateTimeInterface $publicationDateStart = null; - /** - * @var \DateTimeInterface|null - */ - protected $publicationDateEnd = null; + protected ?\DateTimeInterface $publicationDateEnd = null; - /** - * @var \DateTimeInterface|null - */ - protected $createdAt = null; + protected ?\DateTimeInterface $createdAt = null; - /** - * @var \DateTimeInterface|null - */ - protected $updatedAt = null; + protected ?\DateTimeInterface $updatedAt = null; - /** - * @var bool - */ - protected $decorate = true; + protected bool $decorate = true; - /** - * @var int|null - */ - protected $position = 1; + protected ?int $position = 1; - /** - * @var PageInterface|null - */ - protected $page = null; + protected ?PageInterface $page = null; - /** - * @var SiteInterface|null - */ - protected $site = null; + protected ?SiteInterface $site = null; /** * @var array|null * * @phpstan-var PageContent|null */ - protected $content = null; + protected ?array $content = null; /** * @var array */ - protected $children = []; + protected array $children = []; /** * @var int|string|null */ protected $parentId = null; - public function __toString() + public function __toString(): string { return $this->getName() ?? '-'; } @@ -122,67 +80,67 @@ public function getId() return $this->id; } - public function getRouteName() + public function getRouteName(): ?string { return $this->routeName; } - public function setRouteName($routeName): void + public function setRouteName(?string $routeName): void { $this->routeName = $routeName; } - public function getPageAlias() + public function getPageAlias(): ?string { return $this->pageAlias; } - public function setPageAlias($pageAlias): void + public function setPageAlias(?string $pageAlias): void { $this->pageAlias = $pageAlias; } - public function getType() + public function getType(): ?string { return $this->type; } - public function setType($type): void + public function setType(?string $type): void { $this->type = $type; } - public function getEnabled() + public function getEnabled(): bool { return $this->enabled; } - public function setEnabled($enabled): void + public function setEnabled(bool $enabled): void { $this->enabled = $enabled; } - public function getName() + public function getName(): ?string { return $this->name; } - public function setName($name): void + public function setName(?string $name): void { $this->name = $name; } - public function getUrl() + public function getUrl(): ?string { return $this->url; } - public function setUrl($url): void + public function setUrl(?string $url): void { $this->url = $url; } - public function getPublicationDateStart() + public function getPublicationDateStart(): ?\DateTimeInterface { return $this->publicationDateStart; } @@ -192,7 +150,7 @@ public function setPublicationDateStart(?\DateTimeInterface $publicationDateStar $this->publicationDateStart = $publicationDateStart; } - public function getPublicationDateEnd() + public function getPublicationDateEnd(): ?\DateTimeInterface { return $this->publicationDateEnd; } @@ -202,7 +160,7 @@ public function setPublicationDateEnd(?\DateTimeInterface $publicationDateEnd = $this->publicationDateEnd = $publicationDateEnd; } - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } @@ -212,7 +170,7 @@ public function setCreatedAt(?\DateTimeInterface $createdAt = null): void $this->createdAt = $createdAt; } - public function getUpdatedAt() + public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } @@ -222,27 +180,27 @@ public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void $this->updatedAt = $updatedAt; } - public function getDecorate() + public function getDecorate(): bool { return $this->decorate; } - public function setDecorate($decorate): void + public function setDecorate(bool $decorate): void { $this->decorate = $decorate; } - public function getPosition() + public function getPosition(): ?int { return $this->position; } - public function setPosition($position): void + public function setPosition(?int $position): void { $this->position = $position; } - public function getPage() + public function getPage(): ?PageInterface { return $this->page; } @@ -252,7 +210,7 @@ public function setPage(?PageInterface $page = null): void $this->page = $page; } - public function getSite() + public function getSite(): ?SiteInterface { return $this->site; } @@ -262,12 +220,12 @@ public function setSite(?SiteInterface $site = null): void $this->site = $site; } - public function getContent() + public function getContent(): ?array { return $this->content; } - public function setContent($content): void + public function setContent(?array $content): void { $this->content = $content; } @@ -282,7 +240,7 @@ public function setParentId($parentId): void $this->parentId = $parentId; } - public function isHybrid() + public function isHybrid(): bool { return PageInterface::PAGE_ROUTE_CMS_NAME !== $this->getRouteName(); } diff --git a/src/Model/SnapshotChildrenCollection.php b/src/Model/SnapshotChildrenCollection.php index 26f1586da..851831267 100644 --- a/src/Model/SnapshotChildrenCollection.php +++ b/src/Model/SnapshotChildrenCollection.php @@ -36,7 +36,7 @@ public function __construct(TransformerInterface $transformer, PageInterface $pa $this->page = $page; } - protected function doInitialize() + protected function doInitialize(): void { $this->collection = $this->transformer->getChildren($this->page); } diff --git a/src/Model/SnapshotInterface.php b/src/Model/SnapshotInterface.php index eff038fda..05a7ceb1d 100644 --- a/src/Model/SnapshotInterface.php +++ b/src/Model/SnapshotInterface.php @@ -25,178 +25,79 @@ interface SnapshotInterface */ public function getId(); - /** - * @return string|null - */ - public function getRouteName(); + public function getRouteName(): ?string; - /** - * @param string|null $routeName - * - * @return void - */ - public function setRouteName($routeName); + public function setRouteName(?string $routeName): void; - /** - * @return string|null - */ - public function getPageAlias(); + public function getPageAlias(): ?string; /** * The route alias defines an internal url code that user can use to point * to an url. This feature must used with care to avoid to many generated queries. - * - * @param string|null $pageAlias - * - * @return void */ - public function setPageAlias($pageAlias); + public function setPageAlias(?string $pageAlias): void; - /** - * @return string|null - */ - public function getType(); + public function getType(): ?string; - /** - * @param string|null $type - * - * @return void - */ - public function setType($type); + public function setType(?string $type): void; - /** - * @return bool $enabled - */ - public function getEnabled(); + public function getEnabled(): bool; - /** - * @param bool $enabled - * - * @return void - */ - public function setEnabled($enabled); + public function setEnabled(bool $enabled): void; - /** - * @return string|null - */ - public function getName(); + public function getName(): ?string; - /** - * @param string|null $name - * - * @return void - */ - public function setName($name); + public function setName(?string $name): void; - /** - * @return string|null - */ - public function getUrl(); + public function getUrl(): ?string; - /** - * @param string|null $url - * - * @return void - */ - public function setUrl($url); + public function setUrl(?string $url): void; - /** - * @return \DateTimeInterface|null - */ - public function getPublicationDateStart(); + public function getPublicationDateStart(): ?\DateTimeInterface; - /** - * @return void - */ - public function setPublicationDateStart(?\DateTimeInterface $publicationDateStart = null); + public function setPublicationDateStart(?\DateTimeInterface $publicationDateStart = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getPublicationDateEnd(); + public function getPublicationDateEnd(): ?\DateTimeInterface; - /** - * @return void - */ - public function setPublicationDateEnd(?\DateTimeInterface $publicationDateEnd = null); + public function setPublicationDateEnd(?\DateTimeInterface $publicationDateEnd = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getCreatedAt(); + public function getCreatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setCreatedAt(?\DateTimeInterface $createdAt = null); + public function setCreatedAt(?\DateTimeInterface $createdAt = null): void; - /** - * @return \DateTimeInterface|null - */ - public function getUpdatedAt(); + public function getUpdatedAt(): ?\DateTimeInterface; - /** - * @return void - */ - public function setUpdatedAt(?\DateTimeInterface $updatedAt = null); + public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void; - /** - * @return bool - */ - public function getDecorate(); + public function getDecorate(): bool; - /** - * @param bool $decorate - * - * @return void - */ - public function setDecorate($decorate); + public function setDecorate(bool $decorate): void; - /** - * @return int|null - */ - public function getPosition(); + public function getPosition(): ?int; - /** - * @param int|null $position - * - * @return void - */ - public function setPosition($position); + public function setPosition(?int $position): void; - /** - * @return PageInterface|null - */ - public function getPage(); + public function getPage(): ?PageInterface; - /** - * @return void - */ - public function setPage(?PageInterface $page = null); + public function setPage(?PageInterface $page = null): void; - /** - * @return SiteInterface|null - */ - public function getSite(); + public function getSite(): ?SiteInterface; - /** - * @return void - */ - public function setSite(?SiteInterface $site = null); + public function setSite(?SiteInterface $site = null): void; /** * @return array|null * * @phpstan-return PageContent|null */ - public function getContent(); + public function getContent(): ?array; /** * @param array|null $content * * @phpstan-param PageContent|null $content */ - public function setContent($content): void; + public function setContent(?array $content): void; /** * @return int|string|null @@ -208,8 +109,5 @@ public function getParentId(); */ public function setParentId($parentId): void; - /** - * @return bool - */ - public function isHybrid(); + public function isHybrid(): bool; } diff --git a/src/Model/SnapshotManagerInterface.php b/src/Model/SnapshotManagerInterface.php index 38b29609b..5366de9b1 100644 --- a/src/Model/SnapshotManagerInterface.php +++ b/src/Model/SnapshotManagerInterface.php @@ -24,27 +24,19 @@ interface SnapshotManagerInterface extends ManagerInterface { /** * @param array $criteria - * - * @return SnapshotInterface|null */ - public function findEnableSnapshot(array $criteria); + public function findEnableSnapshot(array $criteria): ?SnapshotInterface; /** * @param array $snapshots - * - * @return void */ - public function enableSnapshots(array $snapshots, ?\DateTimeInterface $date = null); + public function enableSnapshots(array $snapshots, ?\DateTimeInterface $date = null): void; public function createSnapshotPageProxy(TransformerInterface $transformer, SnapshotInterface $snapshot): SnapshotPageProxyInterface; /** * Cleanup old snapshots and keep only the $keep number of them. * This method returns the number of deleted snapshots. - * - * @param int $keep - * - * @return int */ - public function cleanup(PageInterface $page, $keep); + public function cleanup(PageInterface $page, int $keep): int; } diff --git a/src/Model/SnapshotPageProxy.php b/src/Model/SnapshotPageProxy.php index a81ce9a08..4dbc4cbd8 100644 --- a/src/Model/SnapshotPageProxy.php +++ b/src/Model/SnapshotPageProxy.php @@ -13,6 +13,8 @@ namespace Sonata\PageBundle\Model; +use Doctrine\Common\Collections\Collection; + /** * @author Thomas Rabaix */ @@ -41,10 +43,7 @@ public function __construct( $this->transformer = $transformer; } - /** - * @return string - */ - public function __toString() + public function __toString(): string { return (string) $this->getPage(); } @@ -70,10 +69,8 @@ public function __unserialize(array $data): void /** * Serialize a snapshot page proxy. - * - * @return string */ - public function serialize() + public function serialize(): string { return serialize([ 'pageId' => $this->getPage()->getId(), @@ -83,10 +80,8 @@ public function serialize() /** * Unserialize a snapshot page proxy. - * - * @param string $serialized */ - public function unserialize($serialized) + public function unserialize($data): void { // TODO: Implement unserialize() method. } @@ -101,137 +96,137 @@ public function setId($id): void $this->getPage()->setId($id); } - public function getTitle() + public function getTitle(): ?string { return $this->getPage()->getTitle(); } - public function setTitle($title): void + public function setTitle(?string $title): void { $this->getPage()->setTitle($title); } - public function getRouteName() + public function getRouteName(): ?string { return $this->getPage()->getRouteName(); } - public function setRouteName($routeName): void + public function setRouteName(?string $routeName): void { $this->getPage()->setRouteName($routeName); } - public function getPageAlias() + public function getPageAlias(): ?string { return $this->getPage()->getPageAlias(); } - public function setPageAlias($pageAlias) + public function setPageAlias(?string $pageAlias): void { $this->getPage()->setPageAlias($pageAlias); } - public function getType() + public function getType(): ?string { return $this->getPage()->getType(); } - public function setType($type): void + public function setType(?string $type): void { $this->getPage()->setType($type); } - public function getEnabled() + public function getEnabled(): bool { return $this->getPage()->getEnabled(); } - public function setEnabled($enabled): void + public function setEnabled(bool $enabled): void { $this->getPage()->setEnabled($enabled); } - public function getName() + public function getName(): ?string { return $this->getPage()->getName(); } - public function setName($name): void + public function setName(?string $name): void { $this->getPage()->setName($name); } - public function getSlug() + public function getSlug(): ?string { return $this->getPage()->getSlug(); } - public function setSlug($slug): void + public function setSlug(?string $slug): void { $this->getPage()->setSlug($slug); } - public function getUrl() + public function getUrl(): ?string { return $this->getPage()->getUrl(); } - public function setUrl($url): void + public function setUrl(?string $url): void { $this->getPage()->setUrl($url); } - public function getCustomUrl() + public function getCustomUrl(): ?string { return $this->getPage()->getCustomUrl(); } - public function setCustomUrl($customUrl): void + public function setCustomUrl(?string $customUrl): void { $this->getPage()->setCustomUrl($customUrl); } - public function getMetaKeyword() + public function getMetaKeyword(): ?string { return $this->getPage()->getMetaKeyword(); } - public function setMetaKeyword($metaKeyword): void + public function setMetaKeyword(?string $metaKeyword): void { $this->getPage()->setMetaKeyword($metaKeyword); } - public function getMetaDescription() + public function getMetaDescription(): ?string { return $this->getPage()->getMetaDescription(); } - public function setMetaDescription($metaDescription): void + public function setMetaDescription(?string $metaDescription): void { $this->getPage()->setMetaDescription($metaDescription); } - public function getJavascript() + public function getJavascript(): ?string { return $this->getPage()->getJavascript(); } - public function setJavascript($javascript): void + public function setJavascript(?string $javascript): void { $this->getPage()->setJavascript($javascript); } - public function getStylesheet() + public function getStylesheet(): ?string { return $this->getPage()->getStylesheet(); } - public function setStylesheet($stylesheet): void + public function setStylesheet(?string $stylesheet): void { $this->getPage()->setStylesheet($stylesheet); } - public function getCreatedAt() + public function getCreatedAt(): ?\DateTimeInterface { return $this->getPage()->getCreatedAt(); } @@ -241,7 +236,7 @@ public function setCreatedAt(?\DateTimeInterface $createdAt = null): void $this->getPage()->setCreatedAt($createdAt); } - public function getUpdatedAt() + public function getUpdatedAt(): ?\DateTimeInterface { return $this->getPage()->getUpdatedAt(); } @@ -251,7 +246,7 @@ public function setUpdatedAt(?\DateTimeInterface $updatedAt = null): void $this->getPage()->setUpdatedAt($updatedAt); } - public function getChildren() + public function getChildren(): Collection { if (0 === $this->getPage()->getChildren()->count()) { $this->getPage()->setChildren(new SnapshotChildrenCollection($this->transformer, $this->getPage())); @@ -260,7 +255,7 @@ public function getChildren() return $this->getPage()->getChildren(); } - public function setChildren($children): void + public function setChildren(Collection $children): void { $this->getPage()->setChildren($children); } @@ -270,7 +265,7 @@ public function addChild(PageInterface $child): void $this->getPage()->addChild($child); } - public function getBlocks() + public function getBlocks(): Collection { if (0 === \count($this->getPage()->getBlocks())) { $content = $this->snapshot->getContent(); @@ -293,17 +288,17 @@ public function addBlock(PageBlockInterface $block): void $this->getPage()->addBlock($block); } - public function getContainerByCode($code) + public function getContainerByCode(string $code): ?PageBlockInterface { return $this->getPage()->getContainerByCode($code); } - public function getBlocksByType($type) + public function getBlocksByType(string $type): array { return $this->getPage()->getBlocksByType($type); } - public function getParent($level = -1) + public function getParent(int $level = -1): ?PageInterface { $parents = $this->getParents(); @@ -319,7 +314,7 @@ public function setParent(?PageInterface $parent = null): void $this->getPage()->setParent($parent); } - public function getParents() + public function getParents(): array { if (null === $this->parents) { $parents = []; @@ -355,47 +350,47 @@ public function setParents(array $parents): void $this->parents = $parents; } - public function getTemplateCode() + public function getTemplateCode(): ?string { return $this->getPage()->getTemplateCode(); } - public function setTemplateCode($templateCode): void + public function setTemplateCode(?string $templateCode): void { $this->getPage()->setTemplateCode($templateCode); } - public function getDecorate() + public function getDecorate(): bool { return $this->getPage()->getDecorate(); } - public function setDecorate($decorate): void + public function setDecorate(bool $decorate): void { $this->getPage()->setDecorate($decorate); } - public function getPosition() + public function getPosition(): ?int { return $this->getPage()->getPosition(); } - public function setPosition($position): void + public function setPosition(?int $position): void { $this->getPage()->setPosition($position); } - public function getRequestMethod() + public function getRequestMethod(): ?string { return $this->getPage()->getRequestMethod(); } - public function setRequestMethod($method): void + public function setRequestMethod(?string $method): void { $this->getPage()->setRequestMethod($method); } - public function hasRequestMethod($method) + public function hasRequestMethod(string $method): bool { return $this->getPage()->hasRequestMethod($method); } @@ -410,22 +405,22 @@ public function setHeaders(array $headers = []): void $this->getPage()->setHeaders($headers); } - public function addHeader($name, $value): void + public function addHeader(string $name, $value): void { $this->getPage()->addHeader($name, $value); } - public function getRawHeaders() + public function getRawHeaders(): ?string { return $this->getPage()->getRawHeaders(); } - public function setRawHeaders($rawHeaders): void + public function setRawHeaders(?string $rawHeaders): void { $this->getPage()->setRawHeaders($rawHeaders); } - public function getSite() + public function getSite(): ?SiteInterface { return $this->getPage()->getSite(); } @@ -435,27 +430,27 @@ public function setSite(?SiteInterface $site = null): void $this->getPage()->setSite($site); } - public function getEdited() + public function getEdited(): bool { return $this->getPage()->getEdited(); } - public function setEdited($edited): void + public function setEdited(bool $edited): void { $this->getPage()->setEdited($edited); } - public function getSnapshots() + public function getSnapshots(): array { return $this->getPage()->getSnapshots(); } - public function setSnapshots($snapshots): void + public function setSnapshots(array $snapshots): void { $this->getPage()->setSnapshots($snapshots); } - public function getSnapshot() + public function getSnapshot(): ?SnapshotInterface { return $this->getPage()->getSnapshot(); } @@ -465,27 +460,27 @@ public function addSnapshot(SnapshotInterface $snapshot): void $this->getPage()->addSnapshot($snapshot); } - public function isError() + public function isError(): bool { return $this->getPage()->isError(); } - public function isHybrid() + public function isHybrid(): bool { return $this->getPage()->isHybrid(); } - public function isDynamic() + public function isDynamic(): bool { return $this->getPage()->isDynamic(); } - public function isCms() + public function isCms(): bool { return $this->getPage()->isCms(); } - public function isInternal() + public function isInternal(): bool { return $this->getPage()->isInternal(); } diff --git a/src/Model/SnapshotPageProxyFactory.php b/src/Model/SnapshotPageProxyFactory.php index 1b90cad53..c0e309e83 100644 --- a/src/Model/SnapshotPageProxyFactory.php +++ b/src/Model/SnapshotPageProxyFactory.php @@ -23,13 +23,16 @@ final class SnapshotPageProxyFactory implements SnapshotPageProxyFactoryInterfac /** * @param class-string $snapshotPageProxyClass */ - public function __construct($snapshotPageProxyClass) + public function __construct(string $snapshotPageProxyClass) { $this->snapshotPageProxyClass = $snapshotPageProxyClass; } - public function create(SnapshotManagerInterface $manager, TransformerInterface $transformer, SnapshotInterface $snapshot) - { + public function create( + SnapshotManagerInterface $manager, + TransformerInterface $transformer, + SnapshotInterface $snapshot + ): SnapshotPageProxyInterface { return new $this->snapshotPageProxyClass($manager, $transformer, $snapshot); } } diff --git a/src/Model/SnapshotPageProxyFactoryInterface.php b/src/Model/SnapshotPageProxyFactoryInterface.php index a1f9e870a..a01cbcfb0 100644 --- a/src/Model/SnapshotPageProxyFactoryInterface.php +++ b/src/Model/SnapshotPageProxyFactoryInterface.php @@ -15,8 +15,5 @@ interface SnapshotPageProxyFactoryInterface { - /** - * @return SnapshotPageProxyInterface - */ - public function create(SnapshotManagerInterface $manager, TransformerInterface $transformer, SnapshotInterface $snapshot); + public function create(SnapshotManagerInterface $manager, TransformerInterface $transformer, SnapshotInterface $snapshot): SnapshotPageProxyInterface; } diff --git a/src/Model/Template.php b/src/Model/Template.php index f2a2417da..70afd678d 100644 --- a/src/Model/Template.php +++ b/src/Model/Template.php @@ -45,8 +45,6 @@ final class Template private array $containers = []; /** - * @param string $name - * @param string $path * @param array $containers */ - public function __construct($name, $path, array $containers = []) + public function __construct(string $name, string $path, array $containers = []) { $this->name = $name; $this->path = $path; @@ -70,7 +68,7 @@ public function __construct($name, $path, array $containers = []) * * @phpstan-return array */ - public function getContainers() + public function getContainers(): array { return $this->containers; } @@ -79,7 +77,6 @@ public function getContainers() * The meta array is an array containing the * - area name. * - * @param string $code * @param array{ * name?: string, * type?: int, @@ -88,19 +85,17 @@ public function getContainers() * shared?: bool * } $meta */ - public function addContainer($code, $meta): void + public function addContainer(string $code, array $meta): void { $this->containers[$code] = $this->normalize($meta); } /** - * @param string $code - * * @return array|null * * @phpstan-return Container|null */ - public function getContainer($code) + public function getContainer(string $code): ?array { if (isset($this->containers[$code])) { return $this->containers[$code]; @@ -109,18 +104,12 @@ public function getContainer($code) return null; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->name; } - /** - * @return string - */ - public function getPath() + public function getPath(): string { return $this->path; } @@ -138,7 +127,7 @@ public function getPath() * * @phpstan-return Container */ - private function normalize(array $meta) + private function normalize(array $meta): array { return [ 'name' => $meta['name'] ?? 'n/a', diff --git a/src/Model/TransformerInterface.php b/src/Model/TransformerInterface.php index 6d3a7f1cc..49ff307f7 100644 --- a/src/Model/TransformerInterface.php +++ b/src/Model/TransformerInterface.php @@ -62,27 +62,19 @@ */ interface TransformerInterface { - /** - * @return PageInterface - */ - public function load(SnapshotInterface $snapshot); + public function load(SnapshotInterface $snapshot): PageInterface; - /** - * @return SnapshotInterface - */ - public function create(PageInterface $page); + public function create(PageInterface $page): SnapshotInterface; /** * @return Collection */ - public function getChildren(PageInterface $page); + public function getChildren(PageInterface $page): Collection; /** * @param array $content * - * @return PageBlockInterface - * * @phpstan-param BlockContent $content */ - public function loadBlock(array $content, PageInterface $page); + public function loadBlock(array $content, PageInterface $page): PageBlockInterface; } diff --git a/src/Page/PageServiceManager.php b/src/Page/PageServiceManager.php index e1312bd08..13a057563 100644 --- a/src/Page/PageServiceManager.php +++ b/src/Page/PageServiceManager.php @@ -29,18 +29,18 @@ final class PageServiceManager implements PageServiceManagerInterface { /** - * @var PageServiceInterface[] + * @var array */ private array $services = []; private ?PageServiceInterface $default = null; - public function add($type, PageServiceInterface $service): void + public function add(string $type, PageServiceInterface $service): void { $this->services[$type] = $service; } - public function get($type) + public function get($type): PageServiceInterface { if ($type instanceof PageInterface) { $type = $type->getType(); @@ -57,7 +57,7 @@ public function get($type) return $this->services[$type]; } - public function getAll() + public function getAll(): array { return $this->services; } @@ -67,7 +67,7 @@ public function setDefault(PageServiceInterface $service): void $this->default = $service; } - public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null) + public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null): Response { $service = $this->get($page); diff --git a/src/Page/PageServiceManagerInterface.php b/src/Page/PageServiceManagerInterface.php index a307ed1c9..b53359cdf 100644 --- a/src/Page/PageServiceManagerInterface.php +++ b/src/Page/PageServiceManagerInterface.php @@ -18,55 +18,28 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * Interface to manage page services. - */ interface PageServiceManagerInterface { - /** - * Adds a page service for given page type. - * - * @param string $type Page type - * @param PageServiceInterface $service Service - * - * @return void - */ - public function add($type, PageServiceInterface $service); + public function add(string $type, PageServiceInterface $service): void; /** - * Returns the page service for given page. - * * @param string|PageInterface $type - * - * @return PageServiceInterface */ - public function get($type); + public function get($type): PageServiceInterface; /** - * Returns all page services. - * - * @return PageServiceInterface[] + * @return array */ - public function getAll(); + public function getAll(): array; - /** - * Sets the default page service. - * - * @return void - */ - public function setDefault(PageServiceInterface $service); + public function setDefault(PageServiceInterface $service): void; /** * Executes the page. This method acts as a controller's action for a specific page and is therefor expected * to return a Response object. * - * @param PageInterface $page Page to execute - * @param Request $request Request object * @param array $parameters An array of view parameters. In the case of hybrid pages, it may have a * parameter "content" that contains the view result of the controller - * @param Response|null $response Response object - * - * @return Response */ - public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null); + public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null): Response; } diff --git a/src/Page/Service/BasePageService.php b/src/Page/Service/BasePageService.php index a11e2e12a..14c22fd58 100644 --- a/src/Page/Service/BasePageService.php +++ b/src/Page/Service/BasePageService.php @@ -14,28 +14,21 @@ namespace Sonata\PageBundle\Page\Service; /** - * Abstract page service that provides a basic implementation. - * * @author Olivier Paradis */ abstract class BasePageService implements PageServiceInterface { /** * Page service name used in the admin. - * - * @var string */ - protected $name; + protected string $name; - /** - * @param string $name Page service name - */ - public function __construct($name) + public function __construct(string $name) { $this->name = $name; } - public function getName() + public function getName(): string { return $this->name; } diff --git a/src/Page/Service/DefaultPageService.php b/src/Page/Service/DefaultPageService.php index 8be7465a7..a85904987 100644 --- a/src/Page/Service/DefaultPageService.php +++ b/src/Page/Service/DefaultPageService.php @@ -28,21 +28,23 @@ final class DefaultPageService extends BasePageService private ?SeoPageInterface $seoPage; - /** - * @param string $name Page service name - * @param TemplateManagerInterface $templateManager Template manager - * @param SeoPageInterface|null $seoPage SEO page object - */ - public function __construct($name, TemplateManagerInterface $templateManager, ?SeoPageInterface $seoPage = null) - { + public function __construct( + string $name, + TemplateManagerInterface $templateManager, + ?SeoPageInterface $seoPage = null + ) { parent::__construct($name); $this->templateManager = $templateManager; $this->seoPage = $seoPage; } - public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null) - { + public function execute( + PageInterface $page, + Request $request, + array $parameters = [], + ?Response $response = null + ): Response { $this->updateSeoPage($page); $templateCode = $page->getTemplateCode(); diff --git a/src/Page/Service/PageServiceInterface.php b/src/Page/Service/PageServiceInterface.php index e3e634769..7e673adcd 100644 --- a/src/Page/Service/PageServiceInterface.php +++ b/src/Page/Service/PageServiceInterface.php @@ -31,24 +31,14 @@ */ interface PageServiceInterface { - /** - * Returns the page service name. - * - * @return string - */ - public function getName(); + public function getName(): string; /** * Executes the page. This method acts as a controller's action for a specific page and is therefor expected * to return a Response object. * - * @param PageInterface $page Page to execute - * @param Request $request Request object * @param array $parameters An array of view parameters. In the case of hybrid pages, it may have a * parameter "content" that contains the view result of the controller - * @param Response|null $response Response object - * - * @return Response */ - public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null); + public function execute(PageInterface $page, Request $request, array $parameters = [], ?Response $response = null): Response; } diff --git a/src/Page/TemplateManager.php b/src/Page/TemplateManager.php index 3f9a42b12..b1a6e4ac3 100644 --- a/src/Page/TemplateManager.php +++ b/src/Page/TemplateManager.php @@ -42,8 +42,7 @@ final class TemplateManager implements TemplateManagerInterface private string $defaultTemplatePath = '@SonataPage/layout.html.twig'; /** - * @param Environment $twig Templating twig - * @param array $defaultParameters An array of default view parameters + * @param array $defaultParameters */ public function __construct(Environment $twig, array $defaultParameters = []) { @@ -51,12 +50,12 @@ public function __construct(Environment $twig, array $defaultParameters = []) $this->defaultParameters = $defaultParameters; } - public function add($code, Template $template): void + public function add(string $code, Template $template): void { $this->templates[$code] = $template; } - public function get($code) + public function get(string $code): ?Template { if (!isset($this->templates[$code])) { return null; @@ -65,22 +64,22 @@ public function get($code) return $this->templates[$code]; } - public function setDefaultTemplateCode($code): void + public function setDefaultTemplateCode(string $code): void { $this->defaultTemplateCode = $code; } - public function getDefaultTemplateCode() + public function getDefaultTemplateCode(): string { return $this->defaultTemplateCode; } - public function setAll($templates): void + public function setAll(array $templates): void { $this->templates = $templates; } - public function getAll() + public function getAll(): array { return $this->templates; } diff --git a/src/Page/TemplateManagerInterface.php b/src/Page/TemplateManagerInterface.php index 14604bca5..7b16859e3 100644 --- a/src/Page/TemplateManagerInterface.php +++ b/src/Page/TemplateManagerInterface.php @@ -22,48 +22,25 @@ interface TemplateManagerInterface { /** - * @param string|null $code Template code - * @param array $parameters An array of view parameters - * @param Response $response Response to update + * @param array $parameters */ public function renderResponse(?string $code, array $parameters = [], ?Response $response = null): Response; - /** - * @param string $code Code - * @param Template $template Template object - * - * @return void - */ - public function add($code, Template $template); + public function add(string $code, Template $template): void; - /** - * @param string $code - * - * @return Template|null - */ - public function get($code); + public function get(string $code): ?Template; - /** - * @param string $code - * - * @return void - */ - public function setDefaultTemplateCode($code); + public function setDefaultTemplateCode(string $code): void; - /** - * @return string - */ - public function getDefaultTemplateCode(); + public function getDefaultTemplateCode(): string; /** - * @param Template[] $templates - * - * @return void + * @param array