From c7b743db3f5923811c3b03dbd7779ab493de1302 Mon Sep 17 00:00:00 2001 From: simbr Date: Tue, 24 Mar 2026 20:32:42 +0100 Subject: [PATCH 1/6] Php cs fixer --- Command/ExportCommand.php | 31 ++-- Command/ImportCommand.php | 45 ++---- Controller/ContentController.php | 60 +++----- Controller/Crud/ContentController.php | 43 ++---- Controller/Crud/PageController.php | 26 +--- Controller/Crud/ScopeController.php | 12 +- Controller/PageController.php | 18 +-- Controller/ToolsController.php | 39 ++--- DependencyInjection/Compiler/ElementPass.php | 2 +- .../Compiler/FormThemePass.php | 2 +- DependencyInjection/Configuration.php | 6 +- .../SherlockodeAdvancedContentExtension.php | 12 +- Doctrine/MigrationHelper.php | 63 ++------ Doctrine/MigrationHelperAwareInterface.php | 2 - Doctrine/MigrationHelperInterface.php | 44 ------ Element/AbstractElement.php | 4 +- Element/ElementInterface.php | 9 +- Event/AcbFilePreSubmitEvent.php | 10 -- EventListener/AcbFileListener.php | 15 -- EventListener/ContentListener.php | 16 +- EventListener/PageListener.php | 27 +--- EventListener/VersionListener.php | 8 +- Exception/InvalidElementException.php | 2 +- Export/ContentExport.php | 8 +- Export/ElementExport.php | 19 --- Export/PageExport.php | 18 +-- Export/ScopeExport.php | 11 +- FieldType/AbstractFieldType.php | 24 +-- FieldType/AbstractInputType.php | 2 +- FieldType/Content.php | 11 +- FieldType/FieldTypeInterface.php | 11 +- FieldType/File.php | 10 +- FieldType/Iframe.php | 6 +- FieldType/Image.php | 2 +- FieldType/ImageCarousel.php | 7 +- FieldType/Link.php | 7 +- FieldType/RelativeLink.php | 5 +- FieldType/Separator.php | 2 +- FieldType/Text.php | 2 +- FieldType/TextArea.php | 4 +- FieldType/Title.php | 2 +- FieldType/Video.php | 2 +- FieldType/Wysiwyg.php | 2 +- Form/DataTransformer/StringToEntity.php | 9 +- Form/Type/AcbContentType.php | 8 - Form/Type/AcbFileType.php | 21 +-- Form/Type/ContentType.php | 25 +--- Form/Type/ElementHideOnType.php | 3 - Form/Type/ElementType.php | 9 -- Form/Type/ElementsType.php | 32 ++-- Form/Type/EntityType.php | 2 +- Form/Type/ExportType.php | 7 +- Form/Type/ImageType.php | 9 -- Form/Type/LinkType.php | 3 - Form/Type/PageMetaType.php | 13 +- Form/Type/PageType.php | 21 +-- Form/Type/PageTypeType.php | 3 - Form/Type/PictureEntryType.php | 2 +- Form/Type/PictureType.php | 5 +- Form/Type/RepeatedChildWrappedType.php | 4 +- Form/Type/RepeaterType.php | 3 +- Form/Type/ScopeChoiceType.php | 12 +- Form/Type/ScopeType.php | 3 - Form/Type/WysiwygType.php | 3 - Import/AbstractImport.php | 46 ++---- Import/ContentImport.php | 16 +- Import/ElementImport.php | 34 ++--- Import/ImportResult.php | 8 +- Import/PageImport.php | 18 +-- LayoutType/AbstractLayoutType.php | 16 +- LayoutType/Column.php | 4 - LayoutType/LayoutTypeInterface.php | 1 - LayoutType/Row.php | 3 - Manager/ConfigurationManager.php | 11 +- Manager/ContentManager.php | 17 +-- Manager/ElementManager.php | 17 +-- Manager/ExportManager.php | 21 +-- Manager/ImportManager.php | 17 +-- Manager/MimeTypeManager.php | 35 ++--- Manager/PageManager.php | 14 +- Manager/UploadManager.php | 27 ++-- Manager/UrlBuilderManager.php | 22 +-- Manager/VersionManager.php | 80 ++-------- Model/Content.php | 22 +-- Model/ContentInterface.php | 20 +-- Model/ContentVersion.php | 9 +- Model/ContentVersionInterface.php | 4 - Model/LocaleScope.php | 7 +- Model/LocaleScopeInterface.php | 5 - Model/Page.php | 31 +--- Model/PageInterface.php | 21 +-- Model/PageMeta.php | 6 - Model/PageMetaInterface.php | 2 - Model/PageMetaVersion.php | 8 - Model/PageMetaVersionInterface.php | 2 - Model/PageTypeInterface.php | 6 +- Model/PageVersion.php | 15 -- Model/PageVersionInterface.php | 6 - Model/ScopableInterface.php | 4 - Model/Scope.php | 3 - Model/Version.php | 18 --- Model/VersionInterface.php | 11 +- Naming/ClientOriginalNamer.php | 5 - Naming/NamerInterface.php | 5 - Naming/UniqueNamer.php | 7 +- Scope/LocaleScopeHandler.php | 26 +--- Scope/ScopeHandler.php | 35 +---- Scope/ScopeHandlerInterface.php | 39 ----- SherlockodeAdvancedContentBundle.php | 14 +- Slug/SlugProvider.php | 18 +-- Slug/SlugProviderInterface.php | 9 -- Twig/Extension/ContentExtension.php | 138 ++++-------------- Twig/Extension/ScopeExtension.php | 10 +- User/AnonymousUserProvider.php | 11 -- User/UserProviderInterface.php | 8 - composer.json | 10 +- 116 files changed, 377 insertions(+), 1413 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 99f61cb2..5c6c7837 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -15,7 +15,7 @@ class ExportCommand extends Command { - const AVAILABLE_ENTITIES = ['Page', 'Content']; + public const AVAILABLE_ENTITIES = ['Page', 'Content']; /** * @var EntityManagerInterface @@ -58,12 +58,8 @@ class ExportCommand extends Command private $exportTypes = []; /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - * @param ExportManager $exportManager - * @param string $rootDir - * @param null|string $name + * @param string $rootDir + * @param string|null $name */ public function __construct( EntityManagerInterface $em, @@ -71,7 +67,7 @@ public function __construct( TranslatorInterface $translator, ExportManager $exportManager, $rootDir, - $name = null + $name = null, ) { parent::__construct($name); $this->em = $em; @@ -103,9 +99,6 @@ protected function configure() } /** - * @param InputInterface $input - * @param OutputInterface $output - * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) @@ -149,34 +142,28 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * @param InputInterface $input - * * @throws \Exception */ private function init(InputInterface $input) { $initDir = $input->getOption('dir'); - if ($initDir === null) { + if (null === $initDir) { $initDir = $this->configurationManager->getInitDirectory(); } - if (strpos($initDir, '/') !== 0) { - $initDir = $this->rootDir . '/' . $initDir; + if (0 !== strpos($initDir, '/')) { + $initDir = $this->rootDir.'/'.$initDir; } $initDir .= '/'; if (!file_exists($initDir)) { - throw new \Exception( - $this->translator->trans('init.errors.init_dir', ['%dir%' => $initDir], 'AdvancedContentBundle') - ); + throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $initDir], 'AdvancedContentBundle')); } $this->sourceDirectory = $initDir; $exportTypes = $input->getOption('type'); foreach ($exportTypes as $exportType) { if (!in_array($exportType, self::AVAILABLE_ENTITIES)) { - throw new \Exception( - $this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $exportType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle') - ); + throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $exportType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); } } $this->exportTypes = $exportTypes; diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index 948589a8..cddce5d0 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -14,7 +14,7 @@ class ImportCommand extends Command { - const AVAILABLE_ENTITIES = ['Page', 'Content']; + public const AVAILABLE_ENTITIES = ['Page', 'Content']; /** * @var ConfigurationManager @@ -57,18 +57,15 @@ class ImportCommand extends Command private $filename; /** - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - * @param ImportManager $importManager - * @param string $rootDir - * @param null|string $name + * @param string $rootDir + * @param string|null $name */ public function __construct( ConfigurationManager $configurationManager, TranslatorInterface $translator, ImportManager $importManager, $rootDir, - $name = null + $name = null, ) { parent::__construct($name); $this->configurationManager = $configurationManager; @@ -117,9 +114,6 @@ protected function configure() } /** - * @param InputInterface $input - * @param OutputInterface $output - * * @return void */ protected function execute(InputInterface $input, OutputInterface $output) @@ -131,7 +125,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->addFilesToProcess(); $this->importManager->setSymfonyStyle($this->symfonyStyle); $this->importManager->processData($this->importTypes); - } catch (\Exception $e) { $this->symfonyStyle->error($e->getMessage()); @@ -152,7 +145,7 @@ private function addFilesToProcess() $finder = new Finder(); $finder->files()->in($this->sourceDirectory); - if ($this->filename !== null) { + if (null !== $this->filename) { $finder->name($this->filename); if (!$finder->hasResults()) { $this->symfonyStyle->warning( @@ -174,36 +167,30 @@ private function addFilesToProcess() } /** - * @param InputInterface $input - * * @throws \Exception */ private function init(InputInterface $input) { $initDir = $input->getOption('dir'); - if ($initDir === null) { + if (null === $initDir) { $initDir = $this->configurationManager->getInitDirectory(); } $initDir = $this->getDirFullPath($initDir); $this->sourceDirectory = $initDir; $filesDir = $input->getOption('files-dir'); - if ($filesDir !== null) { + if (null !== $filesDir) { $filesDir = $this->getDirFullPath($filesDir); $this->importManager->setFilesDirectory($filesDir); } $targetDir = $this->configurationManager->getImageDirectory(); - if (!file_exists($targetDir) && !mkdir($targetDir, 0755)) { - throw new \Exception($this->translator->trans( - 'init.errors.cannot_create_directory', - ['%path%' => $targetDir], - 'AdvancedContentBundle' - )); + if (!file_exists($targetDir) && !mkdir($targetDir, 0o755)) { + throw new \Exception($this->translator->trans('init.errors.cannot_create_directory', ['%path%' => $targetDir], 'AdvancedContentBundle')); } $allowUpdate = $this->configurationManager->initCanUpdate(); - if ($input->getOption('update') === true) { + if (true === $input->getOption('update')) { $allowUpdate = true; } @@ -212,9 +199,7 @@ private function init(InputInterface $input) $importTypes = $input->getOption('type'); foreach ($importTypes as $importType) { if (!in_array($importType, self::AVAILABLE_ENTITIES)) { - throw new \Exception( - $this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $importType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle') - ); + throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $importType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); } } $this->importTypes = $importTypes; @@ -231,15 +216,13 @@ private function init(InputInterface $input) */ private function getDirFullPath($dir) { - if (strpos($dir, '/') !== 0) { - $dir = $this->rootDir . '/' . $dir; + if (0 !== strpos($dir, '/')) { + $dir = $this->rootDir.'/'.$dir; } $dir .= '/'; if (!file_exists($dir)) { - throw new \Exception( - $this->translator->trans('init.errors.init_dir', ['%dir%' => $dir], 'AdvancedContentBundle') - ); + throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $dir], 'AdvancedContentBundle')); } return $dir; diff --git a/Controller/ContentController.php b/Controller/ContentController.php index 3033fb99..0e658f04 100644 --- a/Controller/ContentController.php +++ b/Controller/ContentController.php @@ -8,19 +8,18 @@ use Sherlockode\AdvancedContentBundle\Form\Type\ElementType; use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; use Sherlockode\AdvancedContentBundle\Manager\ContentManager; -use Sherlockode\AdvancedContentBundle\Manager\VersionManager; use Sherlockode\AdvancedContentBundle\Manager\ElementManager; +use Sherlockode\AdvancedContentBundle\Manager\VersionManager; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; /** - * Class ContentController + * Class ContentController. */ class ContentController extends AbstractController { @@ -64,25 +63,15 @@ class ContentController extends AbstractController */ private $eventDispatcherInterface; - /** - * @param EntityManagerInterface $em - * @param ContentManager $contentManager - * @param ElementManager $elementManager - * @param ConfigurationManager $configurationManager - * @param FormFactoryInterface $formFactory - * @param TranslatorInterface $translator - * @param VersionManager $versionManager - * @param EventDispatcherInterface $eventDispatcher - */ public function __construct( EntityManagerInterface $em, - ContentManager $contentManager, - ElementManager $elementManager, - ConfigurationManager $configurationManager, - FormFactoryInterface $formFactory, - TranslatorInterface $translator, + ContentManager $contentManager, + ElementManager $elementManager, + ConfigurationManager $configurationManager, + FormFactoryInterface $formFactory, + TranslatorInterface $translator, VersionManager $versionManager, - EventDispatcherInterface $eventDispatcher + EventDispatcherInterface $eventDispatcher, ) { $this->em = $em; $this->contentManager = $contentManager; @@ -110,8 +99,6 @@ public function addFieldAction() } /** - * @param Request $request - * * @return Response */ public function fieldFormAction(Request $request) @@ -140,12 +127,12 @@ public function fieldFormAction(Request $request) // Rebuild form for row and columns // Because data is being rearranged on submit // Otherwise posted elements cannot be matched with form children - if ($element->getCode() === 'row' || $element->getCode() === 'column') { + if ('row' === $element->getCode() || 'column' === $element->getCode()) { $formBuilder = $this->formFactory->createNamedBuilder('__field_name__', ElementType::class, $form->getData(), [ - 'element_type' => $element, - 'action' => $this->generateUrl('sherlockode_acb_content_field_form', ['type' => $element->getCode()]), + 'element_type' => $element, + 'action' => $this->generateUrl('sherlockode_acb_content_field_form', ['type' => $element->getCode()]), 'csrf_protection' => false, - 'label' => $element->getFormFieldLabel(), + 'label' => $element->getFormFieldLabel(), ]); $form = $formBuilder->getForm(); } @@ -159,14 +146,14 @@ public function fieldFormAction(Request $request) 'form' => $form->createView(), ]), ]); - } else { - return new JsonResponse([ - 'success' => false, - 'content' => $this->renderView('@SherlockodeAdvancedContent/Content/_edit_element.html.twig', [ - 'form' => $form->createView(), - ]), - ]); } + + return new JsonResponse([ + 'success' => false, + 'content' => $this->renderView('@SherlockodeAdvancedContent/Content/_edit_element.html.twig', [ + 'form' => $form->createView(), + ]), + ]); } return new JsonResponse([ @@ -181,7 +168,6 @@ public function fieldFormAction(Request $request) } /** - * @param Request $request * @return JsonResponse */ public function saveDraftAction(Request $request) @@ -189,7 +175,7 @@ public function saveDraftAction(Request $request) $id = $request->get('id'); $content = $this->contentManager->getContentById($id); - if ($content === null) { + if (null === $content) { return new JsonResponse([ 'success' => false, ]); @@ -228,8 +214,6 @@ public function saveDraftAction(Request $request) } /** - * @param Request $request - * * @return JsonResponse */ public function deleteVersionAction(Request $request) @@ -237,13 +221,13 @@ public function deleteVersionAction(Request $request) $id = $request->get('id'); $content = $this->contentManager->getContentById($id); - if ($content === null) { + if (null === $content) { return new JsonResponse([ 'success' => false, ]); } - $versionId = (int)$request->get('versionId'); + $versionId = (int) $request->get('versionId'); foreach ($content->getVersions() as $version) { if ($versionId === $version->getId()) { $this->em->remove($version); diff --git a/Controller/Crud/ContentController.php b/Controller/Crud/ContentController.php index c975ceeb..26d4e563 100644 --- a/Controller/Crud/ContentController.php +++ b/Controller/Crud/ContentController.php @@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\Response; /** - * Class ContentController + * Class ContentController. */ class ContentController extends AbstractController { @@ -33,15 +33,11 @@ class ContentController extends AbstractController /** * ContentController constructor. - * - * @param EntityManagerInterface $em - * @param ContentManager $contentManager - * @param ConfigurationManager $configurationManager */ public function __construct( EntityManagerInterface $em, ContentManager $contentManager, - ConfigurationManager $configurationManager + ConfigurationManager $configurationManager, ) { $this->em = $em; $this->contentManager = $contentManager; @@ -49,8 +45,7 @@ public function __construct( } /** - * @param int $id - * @param Request $request + * @param int $id * * @return Response */ @@ -58,10 +53,8 @@ public function editAction($id, Request $request) { $content = $this->contentManager->getContentById($id); - if ($content === null) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id) - ); + if (null === $content) { + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id)); } $form = $this->createForm(ContentType::class, $content, [ @@ -77,14 +70,12 @@ public function editAction($id, Request $request) } return $this->render('@SherlockodeAdvancedContent/Content/edit_content.html.twig', [ - 'form' => $form->createView(), - 'data' => $content, - ]); + 'form' => $form->createView(), + 'data' => $content, + ]); } /** - * @param Request $request - * * @return Response */ public function createAction(Request $request) @@ -92,14 +83,12 @@ public function createAction(Request $request) if ($id = $request->get('duplicateId')) { $contentToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->find($id); if (!$contentToDuplicate instanceof ContentInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id)); } $content = $this->contentManager->duplicate($contentToDuplicate); } else { $contentEntityClass = $this->configurationManager->getEntityClass('content'); - $content = new $contentEntityClass; + $content = new $contentEntityClass(); } $form = $this->createForm(ContentType::class, $content, [ @@ -142,10 +131,8 @@ public function deleteAction($id) { $content = $this->contentManager->getContentById($id); - if ($content === null) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id) - ); + if (null === $content) { + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id)); } $this->em->remove($content); @@ -163,10 +150,8 @@ public function showAction($id) { $content = $this->contentManager->getContentById($id); - if ($content === null) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id) - ); + if (null === $content) { + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id)); } return $this->render('@SherlockodeAdvancedContent/Content/show.html.twig', [ diff --git a/Controller/Crud/PageController.php b/Controller/Crud/PageController.php index 2c9226e1..93d1f9d1 100644 --- a/Controller/Crud/PageController.php +++ b/Controller/Crud/PageController.php @@ -28,15 +28,10 @@ class PageController extends AbstractController */ private $pageManager; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param PageManager $pageManager - */ public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, - PageManager $pageManager + PageManager $pageManager, ) { $this->em = $em; $this->configurationManager = $configurationManager; @@ -44,8 +39,7 @@ public function __construct( } /** - * @param int $id - * @param Request $request + * @param int $id * * @return Response */ @@ -54,9 +48,7 @@ public function editAction($id, Request $request) $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); if (!$page instanceof PageInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id)); } $form = $this->createForm(PageType::class, $page, [ @@ -77,8 +69,6 @@ public function editAction($id, Request $request) } /** - * @param Request $request - * * @return Response */ public function createAction(Request $request) @@ -86,14 +76,12 @@ public function createAction(Request $request) if ($id = $request->get('duplicateId')) { $pageToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); if (!$pageToDuplicate instanceof PageInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id)); } $page = $this->pageManager->duplicate($pageToDuplicate); } else { $pageEntityClass = $this->configurationManager->getEntityClass('page'); - $page = new $pageEntityClass; + $page = new $pageEntityClass(); } $form = $this->createForm(PageType::class, $page, [ @@ -136,9 +124,7 @@ public function deleteAction($id) $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); if (!$page instanceof PageInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id)); } $this->em->remove($page); diff --git a/Controller/Crud/ScopeController.php b/Controller/Crud/ScopeController.php index ca35cfc6..c05c2576 100644 --- a/Controller/Crud/ScopeController.php +++ b/Controller/Crud/ScopeController.php @@ -6,8 +6,6 @@ use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; use Sherlockode\AdvancedContentBundle\Model\ScopeInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\FormError; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; class ScopeController extends AbstractController @@ -22,13 +20,9 @@ class ScopeController extends AbstractController */ private $configurationManager; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - */ public function __construct( EntityManagerInterface $em, - ConfigurationManager $configurationManager + ConfigurationManager $configurationManager, ) { $this->em = $em; $this->configurationManager = $configurationManager; @@ -44,9 +38,7 @@ public function deleteAction($id) $scope = $this->em->getRepository($this->configurationManager->getEntityClass('scope'))->find($id); if (!$scope instanceof ScopeInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('scope'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('scope'), $id)); } $this->em->remove($scope); diff --git a/Controller/PageController.php b/Controller/PageController.php index 398cb476..df89e651 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -40,19 +40,12 @@ class PageController extends AbstractController */ private $formFactory; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param PageManager $pageManager - * @param VersionManager $versionManager - * @param FormFactoryInterface $formFactory - */ public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, PageManager $pageManager, VersionManager $versionManager, - FormFactoryInterface $formFactory + FormFactoryInterface $formFactory, ) { $this->em = $em; $this->configurationManager = $configurationManager; @@ -62,7 +55,6 @@ public function __construct( } /** - * @param Request $request * @return JsonResponse */ public function saveDraftAction(Request $request) @@ -70,7 +62,7 @@ public function saveDraftAction(Request $request) $id = $request->get('id'); $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); - if ($page === null) { + if (null === $page) { return new JsonResponse([ 'success' => false, ]); @@ -115,8 +107,6 @@ public function saveDraftAction(Request $request) } /** - * @param Request $request - * * @return JsonResponse */ public function deleteVersionAction(Request $request) @@ -124,13 +114,13 @@ public function deleteVersionAction(Request $request) $id = $request->get('id'); $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); - if ($page === null) { + if (null === $page) { return new JsonResponse([ 'success' => false, ]); } - $versionId = (int)$request->get('versionId'); + $versionId = (int) $request->get('versionId'); foreach ($page->getVersions() as $version) { if ($versionId === $version->getId()) { $this->em->remove($version); diff --git a/Controller/ToolsController.php b/Controller/ToolsController.php index 5e1ea55f..8797b2e1 100644 --- a/Controller/ToolsController.php +++ b/Controller/ToolsController.php @@ -51,12 +51,7 @@ class ToolsController extends AbstractController private $template; /** - * @param ImportManager $importManager - * @param ExportManager $exportManager - * @param TranslatorInterface $translator - * @param ConfigurationManager $configurationManager - * @param EntityManagerInterface $em - * @param string $template + * @param string $template */ public function __construct( ImportManager $importManager, @@ -64,7 +59,7 @@ public function __construct( TranslatorInterface $translator, ConfigurationManager $configurationManager, EntityManagerInterface $em, - $template + $template, ) { $this->importManager = $importManager; $this->exportManager = $exportManager; @@ -86,7 +81,7 @@ public function indexAction(Request $request) $pageTypeClass = $this->configurationManager->getEntityClass('page_type'); $pageTypes = $this->em->getRepository($pageTypeClass)->findAll(); - $pageType = new $pageTypeClass; + $pageType = new $pageTypeClass(); $pageTypeForm = $this->createForm(PageTypeType::class, $pageType, [ 'action' => $this->generateUrl('sherlockode_acb_tools_index'), ]); @@ -95,21 +90,20 @@ public function indexAction(Request $request) $existingPageTypes = $this->em->getRepository($pageTypeClass)->findBy([ 'name' => $pageType->getName(), ]); - if (count($existingPageTypes) === 0) { + if (0 === count($existingPageTypes)) { $this->em->persist($pageType); $this->em->flush(); return $this->redirectToRoute('sherlockode_acb_tools_index'); - } else { - $pageTypeForm->addError(new FormError( - $this->translator->trans('page_type.errors.unique_name', [], 'AdvancedContentBundle') - )); } + $pageTypeForm->addError(new FormError( + $this->translator->trans('page_type.errors.unique_name', [], 'AdvancedContentBundle') + )); } $scopeClass = $this->configurationManager->getEntityClass('scope'); $scopes = $this->em->getRepository($scopeClass)->findAll(); - $scope = new $scopeClass; + $scope = new $scopeClass(); $scopeForm = $this->createForm(ScopeType::class, $scope, [ 'action' => $this->generateUrl('sherlockode_acb_tools_index'), ]); @@ -118,16 +112,15 @@ public function indexAction(Request $request) $existingScopes = $this->em->getRepository($scopeClass)->findBy([ 'locale' => $scope->getLocale(), ]); - if (count($existingScopes) === 0) { + if (0 === count($existingScopes)) { $this->em->persist($scope); $this->em->flush(); return $this->redirectToRoute('sherlockode_acb_tools_index'); - } else { - $scopeForm->addError(new FormError( - $this->translator->trans('scope.errors.unique_locale', [], 'AdvancedContentBundle') - )); } + $scopeForm->addError(new FormError( + $this->translator->trans('scope.errors.unique_locale', [], 'AdvancedContentBundle') + )); } return $this->render($this->template, [ @@ -141,8 +134,6 @@ public function indexAction(Request $request) } /** - * @param Request $request - * * @return Response */ public function importAction(Request $request) @@ -171,8 +162,6 @@ public function importAction(Request $request) } /** - * @param Request $request - * * @return Response */ public function exportAction(Request $request) @@ -220,9 +209,7 @@ public function deletePageTypeAction($id) $pageType = $this->em->getRepository($this->configurationManager->getEntityClass('page_type'))->find($id); if (!$pageType instanceof PageTypeInterface) { - throw $this->createNotFoundException( - sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page_type'), $id) - ); + throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page_type'), $id)); } $this->em->remove($pageType); diff --git a/DependencyInjection/Compiler/ElementPass.php b/DependencyInjection/Compiler/ElementPass.php index 28501b4c..ae9fa4e7 100644 --- a/DependencyInjection/Compiler/ElementPass.php +++ b/DependencyInjection/Compiler/ElementPass.php @@ -2,8 +2,8 @@ namespace Sherlockode\AdvancedContentBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; class ElementPass implements CompilerPassInterface diff --git a/DependencyInjection/Compiler/FormThemePass.php b/DependencyInjection/Compiler/FormThemePass.php index 230fbef4..bbd77b8c 100644 --- a/DependencyInjection/Compiler/FormThemePass.php +++ b/DependencyInjection/Compiler/FormThemePass.php @@ -2,8 +2,8 @@ namespace Sherlockode\AdvancedContentBundle\DependencyInjection\Compiler; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel; class FormThemePass implements CompilerPassInterface diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9f7bdb0c..d24d86aa 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -2,17 +2,13 @@ namespace Sherlockode\AdvancedContentBundle\DependencyInjection; -use Sherlockode\AdvancedContentBundle\Entity\Content; -use Sherlockode\AdvancedContentBundle\Entity\Page; -use Sherlockode\AdvancedContentBundle\Entity\PageMeta; -use Sherlockode\AdvancedContentBundle\Entity\PageType; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { /** - * Build config tree for bundle + * Build config tree for bundle. * * @return TreeBuilder */ diff --git a/DependencyInjection/SherlockodeAdvancedContentExtension.php b/DependencyInjection/SherlockodeAdvancedContentExtension.php index b1ab36af..e10b2bd5 100644 --- a/DependencyInjection/SherlockodeAdvancedContentExtension.php +++ b/DependencyInjection/SherlockodeAdvancedContentExtension.php @@ -4,22 +4,20 @@ use Sherlockode\AdvancedContentBundle\FieldType\FieldTypeInterface; use Sherlockode\AdvancedContentBundle\LayoutType\LayoutTypeInterface; -use Sherlockode\AdvancedContentBundle\Naming\NamerInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; /** - * Class SherlockodeAdvancedContentExtension + * Class SherlockodeAdvancedContentExtension. */ class SherlockodeAdvancedContentExtension extends Extension { public function load(array $configs, ContainerBuilder $container) { - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); $loader->load('controllers.xml'); $loader->load('field_types.xml'); @@ -62,12 +60,6 @@ protected function setupUploads(array $config, ContainerBuilder $container) ]); } - /** - * @param array $config - * @param ContainerBuilder $container - * - * @return void - */ private function setupMimeType(array $config, ContainerBuilder $container): void { $mimeTypesConfiguration = $config['mime_type_group'] ?? null; diff --git a/Doctrine/MigrationHelper.php b/Doctrine/MigrationHelper.php index af62ee0b..93aedbaf 100644 --- a/Doctrine/MigrationHelper.php +++ b/Doctrine/MigrationHelper.php @@ -19,10 +19,6 @@ class MigrationHelper implements MigrationHelperInterface */ private $mapping; - /** - * @param EntityManagerInterface $em - * @param array $mapping - */ public function __construct(EntityManagerInterface $em, array $mapping) { $this->em = $em; @@ -30,10 +26,6 @@ public function __construct(EntityManagerInterface $em, array $mapping) } /** - * @param string $slug - * - * @return int|null - * * @throws DriverException * @throws DBALException */ @@ -56,17 +48,13 @@ public function getContentIdBySlug(string $slug): ?int } /** - * @param string $slug - * - * @return array|null - * * @throws DriverException * @throws DBALException */ public function readContent(string $slug): ?array { $query = $this->em->getConnection()->prepare(sprintf( - 'SELECT cv.data FROM %s c INNER JOIN %s cv ON c.content_version_id = cv.id ' . + 'SELECT cv.data FROM %s c INNER JOIN %s cv ON c.content_version_id = cv.id '. 'WHERE c.page_id IS NULL AND c.slug = :slug', $this->getTableName('content'), $this->getTableName('content_version') @@ -74,7 +62,7 @@ public function readContent(string $slug): ?array $stmt = $query->executeQuery(['slug' => $slug]); $row = $stmt->fetchAssociative(); - $raw = isset($row['data']) ? $row['data'] : null; + $raw = $row['data'] ?? null; if ($raw) { return json_decode($raw, true); @@ -84,12 +72,6 @@ public function readContent(string $slug): ?array } /** - * @param string $slug - * @param array $data - * @param string|null $name - * - * @return int - * * @throws DriverException * @throws DBALException */ @@ -103,7 +85,7 @@ public function writeContent(string $slug, array $data, ?string $name = null): i $connection->insert( $contentTable, [ - 'name' => isset($name) ? $name : $slug, + 'name' => $name ?? $slug, 'slug' => $slug, ] ); @@ -131,10 +113,6 @@ public function writeContent(string $slug, array $data, ?string $name = null): i } /** - * @param string $slug - * - * @return void - * * @throws DriverException * @throws DBALException */ @@ -148,10 +126,6 @@ public function removeContent(string $slug): void } /** - * @param string $identifier - * - * @return int|null - * * @throws DriverException * @throws DBALException */ @@ -174,18 +148,14 @@ public function getPageIdByIdentifier(string $identifier): ?int } /** - * @param string $identifier - * - * @return array|null - * * @throws DriverException * @throws DBALException */ public function readPage(string $identifier): ?array { $query = $this->em->getConnection()->prepare(sprintf( - 'SELECT cv.data FROM %s p INNER JOIN %s pv ON p.page_version_id = pv.id ' . - 'INNER JOIN %s cv ON pv.content_version_id = cv.id ' . + 'SELECT cv.data FROM %s p INNER JOIN %s pv ON p.page_version_id = pv.id '. + 'INNER JOIN %s cv ON pv.content_version_id = cv.id '. 'WHERE p.page_identifier = :identifier', $this->getTableName('page'), $this->getTableName('page_version'), @@ -194,7 +164,7 @@ public function readPage(string $identifier): ?array $stmt = $query->executeQuery(['identifier' => $identifier]); $row = $stmt->fetchAssociative(); - $raw = isset($row['data']) ? $row['data'] : null; + $raw = $row['data'] ?? null; if ($raw) { return json_decode($raw, true); @@ -204,13 +174,6 @@ public function readPage(string $identifier): ?array } /** - * @param string $identifier - * @param array $data - * @param string|null $name - * @param int $status - * - * @return int - * * @throws DriverException * @throws DBALException */ @@ -218,7 +181,7 @@ public function writePage( string $identifier, array $data, ?string $name = null, - int $status = PageInterface::STATUS_DRAFT + int $status = PageInterface::STATUS_DRAFT, ): int { $now = date('Y-m-d H:i:s'); $connection = $this->em->getConnection(); @@ -246,7 +209,7 @@ public function writePage( if (!$stmt->rowCount()) { $connection->insert($contentTable, [ 'page_id' => $pageId, - 'name' => isset($name) ? $name : $identifier, + 'name' => $name ?? $identifier, 'slug' => $identifier, ]); $contentId = $connection->lastInsertId(); @@ -276,7 +239,7 @@ public function writePage( $connection->insert($this->getTableName('page_meta_version'), [ 'page_meta_id' => $metaId, - 'title' => isset($name) ? $name : $identifier, + 'title' => $name ?? $identifier, 'slug' => $identifier, 'created_at' => $now, 'auto_save' => 0, @@ -298,10 +261,6 @@ public function writePage( } /** - * @param string $identifier - * - * @return void - * * @throws DriverException * @throws DBALException */ @@ -342,10 +301,6 @@ public function removePage(string $identifier): void } /** - * @param string $defaultTableName - * - * @return string|null - * * @throws \Exception */ private function getTableName(string $defaultTableName): ?string diff --git a/Doctrine/MigrationHelperAwareInterface.php b/Doctrine/MigrationHelperAwareInterface.php index 772169e6..c2cbfd11 100644 --- a/Doctrine/MigrationHelperAwareInterface.php +++ b/Doctrine/MigrationHelperAwareInterface.php @@ -5,8 +5,6 @@ interface MigrationHelperAwareInterface { /** - * @param MigrationHelperInterface $helper - * * @return $this */ public function setHelper(MigrationHelperInterface $helper): self; diff --git a/Doctrine/MigrationHelperInterface.php b/Doctrine/MigrationHelperInterface.php index ebf68133..0d48db0a 100644 --- a/Doctrine/MigrationHelperInterface.php +++ b/Doctrine/MigrationHelperInterface.php @@ -4,63 +4,19 @@ interface MigrationHelperInterface { - /** - * @param string $slug - * - * @return int|null - */ public function getContentIdBySlug(string $slug): ?int; - /** - * @param string $slug - * - * @return array|null - */ public function readContent(string $slug): ?array; - /** - * @param string $slug - * @param array $data - * @param string|null $name - * - * @return int - */ public function writeContent(string $slug, array $data, ?string $name = null): int; - /** - * @param string $slug - * - * @return void - */ public function removeContent(string $slug): void; - /** - * @param string $identifier - * - * @return int|null - */ public function getPageIdByIdentifier(string $identifier): ?int; - /** - * @param string $identifier - * - * @return array|null - */ public function readPage(string $identifier): ?array; - /** - * @param string $identifier - * @param array $data - * @param string|null $name - * - * @return int - */ public function writePage(string $identifier, array $data, ?string $name = null): int; - /** - * @param string $identifier - * - * @return void - */ public function removePage(string $identifier): void; } diff --git a/Element/AbstractElement.php b/Element/AbstractElement.php index d5841fdc..c7c92cd5 100644 --- a/Element/AbstractElement.php +++ b/Element/AbstractElement.php @@ -21,9 +21,7 @@ protected function getDefaultIconClass() } /** - * Add element's field(s) to content form - * - * @param FormBuilderInterface $builder + * Add element's field(s) to content form. * * @return void */ diff --git a/Element/ElementInterface.php b/Element/ElementInterface.php index e92d6081..ae98cefe 100644 --- a/Element/ElementInterface.php +++ b/Element/ElementInterface.php @@ -21,22 +21,17 @@ public function getFormFieldLabel(); */ public function getFrontTemplate(); - /** - * @return mixed - */ public function getPreviewTemplate(); /** - * Add element's field(s) to content form - * - * @param FormBuilderInterface $builder + * Add element's field(s) to content form. * * @return void */ public function buildContentElement(FormBuilderInterface $builder); /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/Event/AcbFilePreSubmitEvent.php b/Event/AcbFilePreSubmitEvent.php index e8006358..5ccf4204 100644 --- a/Event/AcbFilePreSubmitEvent.php +++ b/Event/AcbFilePreSubmitEvent.php @@ -19,27 +19,17 @@ class AcbFilePreSubmitEvent extends Event */ private $fileName; - /** - * @param UploadedFile $uploadedFile - * @param string $fileName - */ public function __construct(UploadedFile $uploadedFile, string $fileName) { $this->uploadedFile = $uploadedFile; $this->fileName = $fileName; } - /** - * @return UploadedFile - */ public function getUploadedFile(): UploadedFile { return $this->uploadedFile; } - /** - * @return string - */ public function getFileName(): string { return $this->fileName; diff --git a/EventListener/AcbFileListener.php b/EventListener/AcbFileListener.php index d55cfd05..40413c77 100644 --- a/EventListener/AcbFileListener.php +++ b/EventListener/AcbFileListener.php @@ -2,13 +2,10 @@ namespace Sherlockode\AdvancedContentBundle\EventListener; -use FOS\UserBundle\FOSUserEvents; -use Sherlockode\AdvancedContentBundle\Event\AcbFileEvent; use Sherlockode\AdvancedContentBundle\Event\AcbFilePostValidate; use Sherlockode\AdvancedContentBundle\Event\AcbFilePreSubmitEvent; use Sherlockode\AdvancedContentBundle\Manager\UploadManager; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\HttpFoundation\File\UploadedFile; class AcbFileListener implements EventSubscriberInterface { @@ -22,9 +19,6 @@ class AcbFileListener implements EventSubscriberInterface */ private $uploadManager; - /** - * @param UploadManager $uploadManager - */ public function __construct(UploadManager $uploadManager) { $this->uploadManager = $uploadManager; @@ -41,20 +35,11 @@ public static function getSubscribedEvents(): array ]; } - /** - * @param AcbFilePreSubmitEvent $event - * - * @return void - */ public function onPreSubmit(AcbFilePreSubmitEvent $event): void { $this->files = array_merge($this->files, [['file' => $event->getUploadedFile(), 'fileName' => $event->getFileName()]]); - } - /** - * @return void - */ public function onPostValidate(): void { foreach ($this->files as $file) { diff --git a/EventListener/ContentListener.php b/EventListener/ContentListener.php index e7018a76..9dc97223 100644 --- a/EventListener/ContentListener.php +++ b/EventListener/ContentListener.php @@ -20,19 +20,12 @@ class ContentListener */ private $versionManager; - /** - * @param ConfigurationManager $configurationManager - * @param VersionManager $versionManager - */ public function __construct(ConfigurationManager $configurationManager, VersionManager $versionManager) { $this->configurationManager = $configurationManager; $this->versionManager = $versionManager; } - /** - * @param LifecycleEventArgs $args - */ public function postLoad(LifecycleEventArgs $args) { $entity = $args->getEntity(); @@ -40,16 +33,13 @@ public function postLoad(LifecycleEventArgs $args) if (!$entity instanceof ContentInterface) { return; } - if ($entity->getPage() !== null) { + if (null !== $entity->getPage()) { return; } $entity->setData($this->versionManager->getContentData($entity), false); } - /** - * @param OnFlushEventArgs $args - */ public function onFlush(OnFlushEventArgs $args) { $em = $args->getEntityManager(); @@ -57,7 +47,7 @@ public function onFlush(OnFlushEventArgs $args) $entities = [ ...$uow->getScheduledEntityInsertions(), - ...$uow->getScheduledEntityUpdates() + ...$uow->getScheduledEntityUpdates(), ]; $contentVersionClassMetadata = $em->getClassMetadata($this->configurationManager->getEntityClass('content_version')); @@ -66,7 +56,7 @@ public function onFlush(OnFlushEventArgs $args) if (!$entity instanceof ContentInterface) { continue; } - if ($entity->getPage() !== null) { + if (null !== $entity->getPage()) { continue; } diff --git a/EventListener/PageListener.php b/EventListener/PageListener.php index c3ca3803..f3d25987 100644 --- a/EventListener/PageListener.php +++ b/EventListener/PageListener.php @@ -22,19 +22,12 @@ class PageListener */ private $versionManager; - /** - * @param ConfigurationManager $configurationManager - * @param VersionManager $versionManager - */ public function __construct(ConfigurationManager $configurationManager, VersionManager $versionManager) { $this->configurationManager = $configurationManager; $this->versionManager = $versionManager; } - /** - * @param LifecycleEventArgs $args - */ public function postLoad(LifecycleEventArgs $args) { $entity = $args->getEntity(); @@ -44,12 +37,12 @@ public function postLoad(LifecycleEventArgs $args) } $pageVersion = $this->versionManager->getPageVersionToLoad($entity); - if ($pageVersion === null) { + if (null === $pageVersion) { return; } $pageMetaVersion = $pageVersion->getPageMetaVersion(); - if ($pageMetaVersion !== null) { + if (null !== $pageMetaVersion) { foreach ($entity->getPageMeta()->getVersions() as $version) { if ($version->getId() === $pageMetaVersion->getId()) { $entity->getPageMeta()->setTitle($version->getTitle()); @@ -62,7 +55,7 @@ public function postLoad(LifecycleEventArgs $args) } $contentVersion = $pageVersion->getContentVersion(); - if ($contentVersion !== null) { + if (null !== $contentVersion) { foreach ($entity->getContent()->getVersions() as $version) { if ($version->getId() === $contentVersion->getId()) { $entity->getContent()->setData($contentVersion->getData()); @@ -72,9 +65,6 @@ public function postLoad(LifecycleEventArgs $args) } } - /** - * @param LifecycleEventArgs $args - */ public function prePersist(LifecycleEventArgs $args) { $object = $args->getObject(); @@ -83,14 +73,11 @@ public function prePersist(LifecycleEventArgs $args) return; } - if ($object->getStatus() === null) { + if (null === $object->getStatus()) { $object->setStatus(PageInterface::STATUS_DRAFT); } } - /** - * @param OnFlushEventArgs $args - */ public function onFlush(OnFlushEventArgs $args) { $em = $args->getEntityManager(); @@ -98,7 +85,7 @@ public function onFlush(OnFlushEventArgs $args) $entities = [ ...$uow->getScheduledEntityInsertions(), - ...$uow->getScheduledEntityUpdates() + ...$uow->getScheduledEntityUpdates(), ]; $pages = []; @@ -107,11 +94,11 @@ public function onFlush(OnFlushEventArgs $args) $pages[$entity->getId()] = $entity; continue; } - if ($entity instanceof PageMetaInterface && $entity->getPage() !== null && $entity->getPage()->getId()) { + if ($entity instanceof PageMetaInterface && null !== $entity->getPage() && $entity->getPage()->getId()) { $pages[$entity->getPage()->getId()] = $entity->getPage(); continue; } - if ($entity instanceof ContentInterface && $entity->getPage() !== null && $entity->getPage()->getId()) { + if ($entity instanceof ContentInterface && null !== $entity->getPage() && $entity->getPage()->getId()) { $pages[$entity->getPage()->getId()] = $entity->getPage(); } } diff --git a/EventListener/VersionListener.php b/EventListener/VersionListener.php index 8670dd33..e812e28d 100644 --- a/EventListener/VersionListener.php +++ b/EventListener/VersionListener.php @@ -3,16 +3,12 @@ namespace Sherlockode\AdvancedContentBundle\EventListener; use Doctrine\ORM\Event\LifecycleEventArgs; -use Doctrine\ORM\Event\OnFlushEventArgs; use Sherlockode\AdvancedContentBundle\Model\ContentVersionInterface; use Sherlockode\AdvancedContentBundle\Model\PageVersionInterface; use Sherlockode\AdvancedContentBundle\Model\VersionInterface; class VersionListener { - /** - * @param LifecycleEventArgs $args - */ public function prePersist(LifecycleEventArgs $args) { $entity = $args->getEntity(); @@ -21,7 +17,7 @@ public function prePersist(LifecycleEventArgs $args) return; } - if ($entity instanceof ContentVersionInterface && $entity->getContent()->getPage() === null) { + if ($entity instanceof ContentVersionInterface && null === $entity->getContent()->getPage()) { $versions = $entity->getContent()->getVersions(); } elseif ($entity instanceof PageVersionInterface) { $versions = $entity->getPage()->getVersions(); @@ -38,7 +34,7 @@ public function prePersist(LifecycleEventArgs $args) continue; } if ($version->getCreatedAt() < $entity->getCreatedAt()) { - $count++; + ++$count; } if ($count >= 10) { // Keep only the last 10 drafts by same user diff --git a/Exception/InvalidElementException.php b/Exception/InvalidElementException.php index 09f95923..fb054fbc 100644 --- a/Exception/InvalidElementException.php +++ b/Exception/InvalidElementException.php @@ -3,7 +3,7 @@ namespace Sherlockode\AdvancedContentBundle\Exception; /** - * Class InvalidFieldTypeException + * Class InvalidFieldTypeException. */ class InvalidElementException extends \RuntimeException { diff --git a/Export/ContentExport.php b/Export/ContentExport.php index ef34db57..dc9a33ee 100644 --- a/Export/ContentExport.php +++ b/Export/ContentExport.php @@ -16,10 +16,6 @@ class ContentExport */ private $scopeExport; - /** - * @param ElementExport $elementExport - * @param ScopeExport $scopeExport - */ public function __construct(ElementExport $elementExport, ScopeExport $scopeExport) { $this->elementExport = $elementExport; @@ -27,8 +23,6 @@ public function __construct(ElementExport $elementExport, ScopeExport $scopeExpo } /** - * @param ContentInterface $content - * * @return array */ public function exportData(ContentInterface $content) @@ -59,7 +53,7 @@ public function exportElements($elements) if (!is_array($elements)) { return []; } - if (count($elements) === 0) { + if (0 === count($elements)) { return []; } diff --git a/Export/ElementExport.php b/Export/ElementExport.php index b3b84c65..e60216a6 100644 --- a/Export/ElementExport.php +++ b/Export/ElementExport.php @@ -7,7 +7,6 @@ use Sherlockode\AdvancedContentBundle\FieldType\FieldTypeInterface; use Sherlockode\AdvancedContentBundle\FieldType\File; use Sherlockode\AdvancedContentBundle\FieldType\Image; -use Sherlockode\AdvancedContentBundle\LayoutType\Column; use Sherlockode\AdvancedContentBundle\LayoutType\LayoutTypeInterface; use Sherlockode\AdvancedContentBundle\Manager\ElementManager; use Symfony\Contracts\Translation\TranslatorInterface; @@ -24,21 +23,12 @@ class ElementExport */ private $translator; - /** - * @param ElementManager $elementManager - * @param TranslatorInterface $translator - */ public function __construct(ElementManager $elementManager, TranslatorInterface $translator) { $this->elementManager = $elementManager; $this->translator = $translator; } - /** - * @param array $elementData - * - * @return array - */ public function getElementExportData(array $elementData): array { if (!isset($elementData['elementType'])) { @@ -60,12 +50,6 @@ public function getElementExportData(array $elementData): array ], $data); } - /** - * @param FieldTypeInterface $element - * @param array $elementData - * - * @return array - */ private function getFieldTypeExportData(FieldTypeInterface $element, array $elementData): array { $raw = $element->getRawValue($elementData['value'] ?? null); @@ -105,9 +89,6 @@ private function getFieldTypeExportData(FieldTypeInterface $element, array $elem } /** - * @param LayoutTypeInterface $element - * @param array $elementData - * * @return array[] */ private function getLayoutTypeExportData(LayoutTypeInterface $element, array $elementData): array diff --git a/Export/PageExport.php b/Export/PageExport.php index fd76130b..c3bac4f9 100644 --- a/Export/PageExport.php +++ b/Export/PageExport.php @@ -17,17 +17,12 @@ class PageExport */ private $scopeExport; - /** - * @param ScopeExport $scopeExport - */ public function __construct(ScopeExport $scopeExport) { $this->scopeExport = $scopeExport; } /** - * @param PageInterface $page - * * @return array */ public function exportData(PageInterface $page) @@ -38,16 +33,16 @@ public function exportData(PageInterface $page) $data['pageType'] = $page->getPageType()->getName(); } $data = array_merge($data, $this->scopeExport->getEntityScopes($page)); - if ($page->getContent() !== null) { + if (null !== $page->getContent()) { $data['content'] = $this->contentExport->exportElements($page->getContent()->getData()); } $pageMeta = $page->getPageMeta(); - if ($pageMeta !== null) { + if (null !== $pageMeta) { $data['meta'] = [ - 'title' => $pageMeta->getTitle(), - 'slug' => $pageMeta->getSlug(), - 'meta_title' => $pageMeta->getMetaTitle(), + 'title' => $pageMeta->getTitle(), + 'slug' => $pageMeta->getSlug(), + 'meta_title' => $pageMeta->getMetaTitle(), 'meta_description' => $pageMeta->getMetaDescription(), ]; } @@ -61,9 +56,6 @@ public function exportData(PageInterface $page) return $data; } - /** - * @param ContentExport $contentExport - */ public function setContentExport(ContentExport $contentExport) { $this->contentExport = $contentExport; diff --git a/Export/ScopeExport.php b/Export/ScopeExport.php index 62303d46..98d2e2d1 100644 --- a/Export/ScopeExport.php +++ b/Export/ScopeExport.php @@ -18,23 +18,14 @@ class ScopeExport */ private $scopeHandler; - /** - * @param ConfigurationManager $configurationManager - * @param ScopeHandlerInterface $scopeHandler - */ public function __construct( ConfigurationManager $configurationManager, - ScopeHandlerInterface $scopeHandler + ScopeHandlerInterface $scopeHandler, ) { $this->configurationManager = $configurationManager; $this->scopeHandler = $scopeHandler; } - /** - * @param ScopableInterface $entity - * - * @return array - */ public function getEntityScopes(ScopableInterface $entity): array { if (!$this->configurationManager->isScopesEnabled()) { diff --git a/FieldType/AbstractFieldType.php b/FieldType/AbstractFieldType.php index 1bfb6cc0..713c1288 100644 --- a/FieldType/AbstractFieldType.php +++ b/FieldType/AbstractFieldType.php @@ -3,7 +3,6 @@ namespace Sherlockode\AdvancedContentBundle\FieldType; use Sherlockode\AdvancedContentBundle\Element\AbstractElement; -use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -24,7 +23,7 @@ public function setConfigData(array $data) */ public function getFormFieldLabel() { - return 'field_type.' . $this->getCode() . '.label'; + return 'field_type.'.$this->getCode().'.label'; } public function getIconClass() @@ -37,7 +36,7 @@ public function getIconClass() */ public function getFrontTemplate() { - return '@SherlockodeAdvancedContent/Field/front/' . $this->getCode() . '.html.twig'; + return '@SherlockodeAdvancedContent/Field/front/'.$this->getCode().'.html.twig'; } /** @@ -45,7 +44,7 @@ public function getFrontTemplate() */ public function getPreviewTemplate() { - return '@SherlockodeAdvancedContent/Field/preview/'. $this->getCode() .'.html.twig'; + return '@SherlockodeAdvancedContent/Field/preview/'.$this->getCode().'.html.twig'; } /** @@ -57,9 +56,7 @@ public function getPreviewPicture() } /** - * Add element's field(s) to content form - * - * @param FormBuilderInterface $builder + * Add element's field(s) to content form. * * @return void */ @@ -73,7 +70,7 @@ public function buildContentElement(FormBuilderInterface $builder) )); $modelTransformer = $this->getValueModelTransformer(); - if ($modelTransformer !== null) { + if (null !== $modelTransformer) { $builder->get('value') ->addModelTransformer($modelTransformer); } @@ -104,7 +101,7 @@ public function getDefaultFormElementOptions() } /** - * Get model transformer for value field + * Get model transformer for value field. * * @return null */ @@ -114,7 +111,7 @@ public function getValueModelTransformer() } /** - * Get options to apply on element + * Get options to apply on element. * * @return array */ @@ -150,18 +147,13 @@ public function getRawData($element) ]); } - /** - * @param mixed $element - * - * @return mixed - */ public function getRawValue($element) { return $element; } /** - * Get form field type + * Get form field type. * * @return string */ diff --git a/FieldType/AbstractInputType.php b/FieldType/AbstractInputType.php index ea836479..7ded993f 100644 --- a/FieldType/AbstractInputType.php +++ b/FieldType/AbstractInputType.php @@ -12,7 +12,7 @@ protected function getDefaultIconClass() } /** - * Get options to apply on element + * Get options to apply on element. * * @return array */ diff --git a/FieldType/Content.php b/FieldType/Content.php index 7c84b899..a8b5e31a 100644 --- a/FieldType/Content.php +++ b/FieldType/Content.php @@ -12,11 +12,8 @@ class Content extends AbstractFieldType */ private $scopeHandler; - /** - * @param ScopeHandlerInterface $scopeHandler - */ public function __construct( - ScopeHandlerInterface $scopeHandler + ScopeHandlerInterface $scopeHandler, ) { $this->scopeHandler = $scopeHandler; } @@ -30,7 +27,7 @@ public function getFormFieldType() } /** - * Get field's code + * Get field's code. * * @return string */ @@ -45,8 +42,6 @@ public function getPreviewPicture(): ?string } /** - * @param mixed $element - * * @return array */ public function getRawValue($element) @@ -54,7 +49,7 @@ public function getRawValue($element) $element['entity'] = null; $contentSlug = $element['content'] ?? null; - if ($contentSlug === null) { + if (null === $contentSlug) { return $element; } diff --git a/FieldType/FieldTypeInterface.php b/FieldType/FieldTypeInterface.php index 4a0fb0eb..0638e32b 100644 --- a/FieldType/FieldTypeInterface.php +++ b/FieldType/FieldTypeInterface.php @@ -8,14 +8,14 @@ interface FieldTypeInterface extends ElementInterface { /** - * Get options to apply on element + * Get options to apply on element. * * @return array */ public function getFormElementOptions(); /** - * Get model transformer for value field + * Get model transformer for value field. * * @return DataTransformerInterface|null */ @@ -27,16 +27,9 @@ public function getValueModelTransformer(); public function getFieldGroup(); /** - * @param array $data - * * @return $this */ public function setConfigData(array $data); - /** - * @param mixed $element - * - * @return mixed - */ public function getRawValue($element); } diff --git a/FieldType/File.php b/FieldType/File.php index edb9436f..b0d8d132 100644 --- a/FieldType/File.php +++ b/FieldType/File.php @@ -12,9 +12,6 @@ class File extends AbstractFieldType */ private $urlBuilderManager; - /** - * @param UrlBuilderManager $urlBuilderManager - */ public function __construct(UrlBuilderManager $urlBuilderManager) { $this->urlBuilderManager = $urlBuilderManager; @@ -34,7 +31,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ @@ -58,11 +55,6 @@ protected function getFilename($value) return $this->urlBuilderManager->getFileUrl($value['src'] ?? ''); } - /** - * @param mixed $element - * - * @return mixed - */ public function getRawValue($element) { $element['url'] = $this->getFilename($element); diff --git a/FieldType/Iframe.php b/FieldType/Iframe.php index f6fe70ba..53e5a0c9 100644 --- a/FieldType/Iframe.php +++ b/FieldType/Iframe.php @@ -18,9 +18,7 @@ public function getFormFieldType() } /** - * Add element's field(s) to content form - * - * @param FormBuilderInterface $builder + * Add element's field(s) to content form. * * @return void */ @@ -36,7 +34,7 @@ public function buildContentElement(FormBuilderInterface $builder) } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Image.php b/FieldType/Image.php index 3f4b4f60..81047dc1 100644 --- a/FieldType/Image.php +++ b/FieldType/Image.php @@ -25,7 +25,7 @@ public function getPreviewPicture(): ?string } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/ImageCarousel.php b/FieldType/ImageCarousel.php index 2a2b3e35..ef7d4e67 100644 --- a/FieldType/ImageCarousel.php +++ b/FieldType/ImageCarousel.php @@ -20,7 +20,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ @@ -34,11 +34,6 @@ public function getPreviewPicture(): ?string return 'bundles/sherlockodeadvancedcontent/preview_picture/image_carousel.svg'; } - /** - * @param mixed $element - * - * @return mixed - */ public function getRawValue($element) { $images = $element['images'] ?? []; diff --git a/FieldType/Link.php b/FieldType/Link.php index 1fc8393d..825cf7df 100644 --- a/FieldType/Link.php +++ b/FieldType/Link.php @@ -41,7 +41,7 @@ protected function getUrlFormType() } /** - * Get field's code + * Get field's code. * * @return string */ @@ -55,11 +55,6 @@ public function getPreviewPicture(): ?string return 'bundles/sherlockodeadvancedcontent/preview_picture/link.svg'; } - /** - * @param mixed $element - * - * @return mixed - */ public function getRawValue($element) { $url = $this->getUrlValue($element); diff --git a/FieldType/RelativeLink.php b/FieldType/RelativeLink.php index bf8d46f0..e8d3da56 100644 --- a/FieldType/RelativeLink.php +++ b/FieldType/RelativeLink.php @@ -12,9 +12,6 @@ class RelativeLink extends Link */ private $urlBuilderManager; - /** - * @param UrlBuilderManager $urlBuilderManager - */ public function __construct(UrlBuilderManager $urlBuilderManager) { $this->urlBuilderManager = $urlBuilderManager; @@ -26,7 +23,7 @@ public function getPreviewTemplate() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Separator.php b/FieldType/Separator.php index 3a14abe4..21d1e0d0 100644 --- a/FieldType/Separator.php +++ b/FieldType/Separator.php @@ -20,7 +20,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Text.php b/FieldType/Text.php index a33d7b18..85a5595e 100644 --- a/FieldType/Text.php +++ b/FieldType/Text.php @@ -15,7 +15,7 @@ public function getFormFieldType() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/TextArea.php b/FieldType/TextArea.php index 590f3115..fb271711 100644 --- a/FieldType/TextArea.php +++ b/FieldType/TextArea.php @@ -7,7 +7,7 @@ class TextArea extends AbstractInputType { /** - * Get options to apply on element + * Get options to apply on element. * * @return array */ @@ -32,7 +32,7 @@ public function getFormFieldType() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Title.php b/FieldType/Title.php index 684de340..dabccfae 100644 --- a/FieldType/Title.php +++ b/FieldType/Title.php @@ -20,7 +20,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Video.php b/FieldType/Video.php index 085504c1..3d27eee5 100644 --- a/FieldType/Video.php +++ b/FieldType/Video.php @@ -20,7 +20,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/FieldType/Wysiwyg.php b/FieldType/Wysiwyg.php index 8f265b3d..468619e0 100644 --- a/FieldType/Wysiwyg.php +++ b/FieldType/Wysiwyg.php @@ -20,7 +20,7 @@ protected function getDefaultIconClass() } /** - * Get field's code + * Get field's code. * * @return string */ diff --git a/Form/DataTransformer/StringToEntity.php b/Form/DataTransformer/StringToEntity.php index b7a5489c..28a5b416 100644 --- a/Form/DataTransformer/StringToEntity.php +++ b/Form/DataTransformer/StringToEntity.php @@ -24,9 +24,8 @@ class StringToEntity implements DataTransformerInterface private $identifierField; /** - * @param EntityManagerInterface $oe - * @param string $entityClass - * @param string $identifierField + * @param string $entityClass + * @param string $identifierField */ public function __construct(EntityManagerInterface $em, $entityClass, $identifierField) { @@ -36,7 +35,7 @@ public function __construct(EntityManagerInterface $em, $entityClass, $identifie } /** - * Transforms a string into an entity + * Transforms a string into an entity. * * @param string $valueAsString * @@ -56,7 +55,7 @@ public function transform($valueAsString) } /** - * Transforms an entity into a string + * Transforms an entity into a string. * * @param object $entity * diff --git a/Form/Type/AcbContentType.php b/Form/Type/AcbContentType.php index b8ede262..e46c79c3 100644 --- a/Form/Type/AcbContentType.php +++ b/Form/Type/AcbContentType.php @@ -20,20 +20,12 @@ class AcbContentType extends AbstractType */ private $em; - /** - * @param ConfigurationManager $configurationManager - * @param EntityManagerInterface $em - */ public function __construct(ConfigurationManager $configurationManager, EntityManagerInterface $em) { $this->configurationManager = $configurationManager; $this->em = $em; } - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options) { $contents = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findBy([ diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php index b9e35982..516bff2b 100644 --- a/Form/Type/AcbFileType.php +++ b/Form/Type/AcbFileType.php @@ -38,11 +38,6 @@ class AcbFileType extends AbstractType */ private $mimeTypeManager; - /** - * @param UploadManager $uploadManager - * @param EventDispatcherInterface $eventDispatcher - * @param MimeTypeManager $mimeTypeManager - */ public function __construct(UploadManager $uploadManager, EventDispatcherInterface $eventDispatcher, MimeTypeManager $mimeTypeManager) { $this->uploadManager = $uploadManager; @@ -68,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'choice_attr' => function ($choice): array { return ['data-mime-type' => json_encode($this->mimeTypeManager->getMimeTypesByCode($choice))]; }, - 'attr' => ['data-mime-type-restriction' => ''] + 'attr' => ['data-mime-type-restriction' => ''], ]) ; @@ -133,10 +128,9 @@ function (FormEvent $event) use ($options) { } /** - * @param FormInterface $form - * @param array $data - * @param array $options - * @param bool $hasFile + * @param array $data + * @param array $options + * @param bool $hasFile * * @return void */ @@ -177,7 +171,7 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal 'label' => 'field_type.file.file', 'required' => !$isFileUploaded && $options['required'], 'constraints' => $options['file_constraints'], - 'attr' => ['data-mime-type-restriction' => ''] + 'attr' => ['data-mime-type-restriction' => ''], ]) ; @@ -194,9 +188,6 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal } } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ @@ -208,7 +199,7 @@ public function configureOptions(OptionsResolver $resolver) } /** - * Make the image accessible in view + * Make the image accessible in view. * * @param FormView $view The view * @param FormInterface $form The form diff --git a/Form/Type/ContentType.php b/Form/Type/ContentType.php index 986e2c4c..4fb5b909 100644 --- a/Form/Type/ContentType.php +++ b/Form/Type/ContentType.php @@ -40,17 +40,11 @@ class ContentType extends AbstractType */ private $translator; - /** - * @param ConfigurationManager $configurationManager - * @param UrlGeneratorInterface $urlGenerator - * @param ScopeHandlerInterface $scopeHandler - * @param TranslatorInterface $translator - */ public function __construct( ConfigurationManager $configurationManager, UrlGeneratorInterface $urlGenerator, ScopeHandlerInterface $scopeHandler, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->configurationManager = $configurationManager; $this->urlGenerator = $urlGenerator; @@ -58,10 +52,6 @@ public function __construct( $this->translator = $translator; } - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options) { $token = uniqid('content_'); @@ -98,12 +88,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($options, $token) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token) { $form = $event->getForm(); /** @var ContentInterface $content */ $content = $event->getData(); $slugClass = 'acb-content-slug'; - if ($content !== null && $content->getId()) { + if (null !== $content && $content->getId()) { $slugClass = ''; } $form @@ -123,7 +113,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } - if ($content === null || empty($content->getData())) { + if (null === $content || empty($content->getData())) { $emptyRowCol = [ 'elementType' => 'row', 'position' => 0, @@ -142,11 +132,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) { + $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $event->setData(json_decode($event->getData(), true)); }, 1); - $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { $form = $event->getForm(); if ($form->has('slug')) { $content = $event->getData(); @@ -171,9 +161,6 @@ public function finishView(FormView $view, FormInterface $form, array $options) $view->vars['multipart'] = true; } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/ElementHideOnType.php b/Form/Type/ElementHideOnType.php index 655cfbc6..40967286 100644 --- a/Form/Type/ElementHideOnType.php +++ b/Form/Type/ElementHideOnType.php @@ -16,9 +16,6 @@ public function getParent() return ChoiceType::class; } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/ElementType.php b/Form/Type/ElementType.php index 876afb24..b7d1b448 100644 --- a/Form/Type/ElementType.php +++ b/Form/Type/ElementType.php @@ -3,8 +3,6 @@ namespace Sherlockode\AdvancedContentBundle\Form\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; @@ -13,10 +11,6 @@ class ElementType extends AbstractType { - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options) { $options['element_type']->buildContentElement($builder); @@ -37,9 +31,6 @@ public function buildView(FormView $view, FormInterface $form, array $options) $view->vars['field_icon'] = $options['element_type']->getIconClass(); } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['element_type']); diff --git a/Form/Type/ElementsType.php b/Form/Type/ElementsType.php index 0904745c..13dc1bba 100644 --- a/Form/Type/ElementsType.php +++ b/Form/Type/ElementsType.php @@ -9,8 +9,6 @@ use Symfony\Component\Form\FormError; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; -use Symfony\Component\Form\FormInterface; -use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Contracts\Translation\TranslatorInterface; @@ -31,28 +29,19 @@ class ElementsType extends AbstractType */ private $translator; - /** - * @param ElementManager $elementManager - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - */ public function __construct( ElementManager $elementManager, ConfigurationManager $configurationManager, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->elementManager = $elementManager; $this->configurationManager = $configurationManager; $this->translator = $translator; } - /** - * @param FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options) { + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { $data = $event->getData(); $form = $event->getForm(); if (!$data) { @@ -63,14 +52,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) foreach ($data as $name => $element) { $field = $this->elementManager->getElementByCode($element['elementType']); $form->add($i++, ElementType::class, [ - 'label' => $field->getFormFieldLabel(), + 'label' => $field->getFormFieldLabel(), 'element_type' => $field, 'property_path' => '['.$name.']', ]); } }); - $builder->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) use ($options) { + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); if (!is_array($data)) { @@ -95,7 +84,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($options) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { $form = $event->getForm(); $data = $event->getData(); $data = array_values($data); @@ -103,22 +92,22 @@ public function buildForm(FormBuilderInterface $builder, array $options) if ($parentForm = $form->getParent()) { $parentElementType = $parentForm->has('elementType') ? $parentForm->get('elementType')->getData() : 'root'; foreach ($data as $child) { - if ($parentElementType === 'root' && $child['elementType'] !== 'row') { + if ('root' === $parentElementType && 'row' !== $child['elementType']) { $form->addError(new FormError($this->translator->trans( 'layout_type.errors.invalid_element_in_root', [], 'AdvancedContentBundle' ))); } - if ($parentElementType === 'row' && $child['elementType'] !== 'column') { + if ('row' === $parentElementType && 'column' !== $child['elementType']) { $form->addError(new FormError($this->translator->trans( 'layout_type.errors.invalid_element_in_row', [], 'AdvancedContentBundle' ))); } - if ($parentElementType === 'column' && - ($child['elementType'] === 'column' || $child['elementType'] === 'row') + if ('column' === $parentElementType + && ('column' === $child['elementType'] || 'row' === $child['elementType']) ) { $form->addError(new FormError($this->translator->trans( 'layout_type.errors.invalid_element_in_column', @@ -133,9 +122,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/EntityType.php b/Form/Type/EntityType.php index 1f68f41c..3e1b08bb 100644 --- a/Form/Type/EntityType.php +++ b/Form/Type/EntityType.php @@ -3,9 +3,9 @@ namespace Sherlockode\AdvancedContentBundle\Form\Type; use Sherlockode\AdvancedContentBundle\Form\DataTransformer\StringToEntity; +use Symfony\Bridge\Doctrine\Form\Type\EntityType as SymfonyEntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Bridge\Doctrine\Form\Type\EntityType as SymfonyEntityType; class EntityType extends AbstractType { diff --git a/Form/Type/ExportType.php b/Form/Type/ExportType.php index a1f9d7f5..f19c169e 100644 --- a/Form/Type/ExportType.php +++ b/Form/Type/ExportType.php @@ -18,9 +18,6 @@ class ExportType extends AbstractType */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct(ConfigurationManager $configurationManager) { $this->configurationManager = $configurationManager; @@ -32,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('page', EntityType::class, [ 'label' => 'tools.export.page', 'class' => $this->configurationManager->getEntityClass('page'), - 'choice_label' => function(PageInterface $page) { + 'choice_label' => function (PageInterface $page) { return $page->getPageMeta()->getTitle(); }, 'expanded' => true, @@ -57,7 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) return $er->createQueryBuilder('c') ->leftJoin('c.page', 'p') ->where('p.id IS NULL'); - } + }, ]) ->add('contentAll', CheckboxType::class, [ 'label' => 'tools.export.all', diff --git a/Form/Type/ImageType.php b/Form/Type/ImageType.php index b04367a9..da11f53a 100644 --- a/Form/Type/ImageType.php +++ b/Form/Type/ImageType.php @@ -10,14 +10,8 @@ class ImageType extends AbstractType { - /** - * @var MimeTypeManager - */ private MimeTypeManager $mimeTypeManager; - /** - * @param MimeTypeManager $mimeTypeManager - */ public function __construct(MimeTypeManager $mimeTypeManager) { $this->mimeTypeManager = $mimeTypeManager; @@ -50,9 +44,6 @@ public function getBlockPrefix() return 'acb_image'; } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/LinkType.php b/Form/Type/LinkType.php index c837b2e2..64a974d4 100644 --- a/Form/Type/LinkType.php +++ b/Form/Type/LinkType.php @@ -29,9 +29,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/PageMetaType.php b/Form/Type/PageMetaType.php index 1346364d..de91a9f7 100644 --- a/Form/Type/PageMetaType.php +++ b/Form/Type/PageMetaType.php @@ -19,17 +19,11 @@ class PageMetaType extends AbstractType */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct(ConfigurationManager $configurationManager) { $this->configurationManager = $configurationManager; } - /** - * @inheritDoc - */ public function buildForm(FormBuilderInterface $builder, array $options) { $token = uniqid('page_meta_'); @@ -69,12 +63,12 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ; - $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) use ($options, $token) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token) { $form = $event->getForm(); /** @var PageMetaInterface $pageMeta */ $pageMeta = $event->getData(); $slugClass = 'acb-pagemeta-slug'; - if ($pageMeta !== null && $pageMeta->getId()) { + if (null !== $pageMeta && $pageMeta->getId()) { $slugClass = ''; } $form @@ -93,9 +87,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - /** - * @inheritDoc - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/PageType.php b/Form/Type/PageType.php index b95a84a3..dffd0bd5 100644 --- a/Form/Type/PageType.php +++ b/Form/Type/PageType.php @@ -34,15 +34,10 @@ class PageType extends AbstractType */ private $translator; - /** - * @param ConfigurationManager $configurationManager - * @param ScopeHandlerInterface $scopeHandler - * @param TranslatorInterface $translator - */ public function __construct( ConfigurationManager $configurationManager, ScopeHandlerInterface $scopeHandler, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->configurationManager = $configurationManager; $this->scopeHandler = $scopeHandler; @@ -66,7 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'required' => false, ]) ->add('pageMeta', PageMetaType::class, [ - 'label' => 'page.form.page_meta', + 'label' => 'page.form.page_meta', ]) ->add('content', ContentType::class, [ 'label' => 'page.form.content', @@ -79,7 +74,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->addEventListener(FormEvents::POST_SET_DATA, function(FormEvent $event) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { $form = $event->getForm(); /** @var PageInterface $page */ $page = $event->getData(); @@ -100,17 +95,17 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); // fill the content name and slug as they are not part of the form in Page context - $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { /** @var PageInterface $page */ $page = $event->getData(); $content = $page->getContent(); - if ($content === null) { + if (null === $content) { $content = new ($this->configurationManager->getEntityClass('content')); $page->setContent($content); } if (!$content->getId()) { - $content->setName('page-' . $page->getPageIdentifier() . '-' . bin2hex(random_bytes(6))); - $content->setSlug($page->getPageMeta()->getSlug() . '-' . bin2hex(random_bytes(6))); + $content->setName('page-'.$page->getPageIdentifier().'-'.bin2hex(random_bytes(6))); + $content->setSlug($page->getPageMeta()->getSlug().'-'.bin2hex(random_bytes(6))); } $form = $event->getForm(); @@ -138,7 +133,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) { + $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $form = $event->getForm(); if ($form->isValid()) { // Reset page version to make sure that page is flagged as to be updated diff --git a/Form/Type/PageTypeType.php b/Form/Type/PageTypeType.php index 9b2a2a31..30671683 100644 --- a/Form/Type/PageTypeType.php +++ b/Form/Type/PageTypeType.php @@ -16,9 +16,6 @@ class PageTypeType extends AbstractType */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct(ConfigurationManager $configurationManager) { $this->configurationManager = $configurationManager; diff --git a/Form/Type/PictureEntryType.php b/Form/Type/PictureEntryType.php index d1218942..6f93d7ac 100644 --- a/Form/Type/PictureEntryType.php +++ b/Form/Type/PictureEntryType.php @@ -26,7 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener( FormEvents::PRE_SUBMIT, - function (FormEvent $event) use ($options) { + function (FormEvent $event) { $data = $event->getData(); if (isset($data['mime_type'])) { // Remove mime type data to prevent form extra fields error diff --git a/Form/Type/PictureType.php b/Form/Type/PictureType.php index f816df5f..2f92259c 100644 --- a/Form/Type/PictureType.php +++ b/Form/Type/PictureType.php @@ -32,7 +32,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener( FormEvents::PRE_SUBMIT, - function (FormEvent $event) use ($options) { + function (FormEvent $event) { $data = $event->getData(); $globalMimeTypes = $data['image']['mime_type'] ?? []; if (isset($data['sources']) && is_array($data['sources'])) { @@ -46,9 +46,6 @@ function (FormEvent $event) use ($options) { ); } - /** - * @param OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ diff --git a/Form/Type/RepeatedChildWrappedType.php b/Form/Type/RepeatedChildWrappedType.php index 3c6afe15..2f589ca9 100644 --- a/Form/Type/RepeatedChildWrappedType.php +++ b/Form/Type/RepeatedChildWrappedType.php @@ -12,7 +12,7 @@ /** * FormType wrapper for non-compound forms inside RepeaterType - * Used in order to be able to add the "position" field + * Used in order to be able to add the "position" field. */ class RepeatedChildWrappedType extends AbstractType { @@ -38,7 +38,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'position' => 0, - 'child_options'=> [], + 'child_options' => [], ]); $resolver->setRequired(['child_form']); $resolver->setNormalizer('child_options', function (Options $options, $value) { diff --git a/Form/Type/RepeaterType.php b/Form/Type/RepeaterType.php index fe95cfb8..820dfd84 100644 --- a/Form/Type/RepeaterType.php +++ b/Form/Type/RepeaterType.php @@ -65,7 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $form->add($i, RepeatedChildWrappedType::class, [ 'child_options' => $child->getConfig()->getOptions(), 'child_form' => get_class($child->getConfig()->getType()->getInnerType()), - 'position' => $i + 'position' => $i, ]); } } @@ -100,6 +100,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $item = $item['wrapped_child']; } } + return $item; }, $orderedData); diff --git a/Form/Type/ScopeChoiceType.php b/Form/Type/ScopeChoiceType.php index ab68259a..b1b49c53 100644 --- a/Form/Type/ScopeChoiceType.php +++ b/Form/Type/ScopeChoiceType.php @@ -20,21 +20,14 @@ class ScopeChoiceType extends AbstractType */ private $scopeHandler; - /** - * @param ConfigurationManager $configurationManager - * @param ScopeHandlerInterface $scopeHandler - */ public function __construct( ConfigurationManager $configurationManager, - ScopeHandlerInterface $scopeHandler + ScopeHandlerInterface $scopeHandler, ) { $this->configurationManager = $configurationManager; $this->scopeHandler = $scopeHandler; } - /** - * {@inheritdoc} - */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ @@ -48,9 +41,6 @@ public function configureOptions(OptionsResolver $resolver) ]); } - /** - * {@inheritdoc} - */ public function getParent(): ?string { return EntityType::class; diff --git a/Form/Type/ScopeType.php b/Form/Type/ScopeType.php index f62664c8..f5adf7f6 100644 --- a/Form/Type/ScopeType.php +++ b/Form/Type/ScopeType.php @@ -16,9 +16,6 @@ class ScopeType extends AbstractType */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct(ConfigurationManager $configurationManager) { $this->configurationManager = $configurationManager; diff --git a/Form/Type/WysiwygType.php b/Form/Type/WysiwygType.php index 222398f1..6dbe6b8e 100644 --- a/Form/Type/WysiwygType.php +++ b/Form/Type/WysiwygType.php @@ -14,9 +14,6 @@ class WysiwygType extends AbstractType */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct(ConfigurationManager $configurationManager) { $this->configurationManager = $configurationManager; diff --git a/Import/AbstractImport.php b/Import/AbstractImport.php index 44a99fbd..67357d7c 100644 --- a/Import/AbstractImport.php +++ b/Import/AbstractImport.php @@ -52,17 +52,11 @@ abstract class AbstractImport */ protected $errors = []; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - * @param ScopeHandlerInterface $scopeHandler - */ public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, TranslatorInterface $translator, - ScopeHandlerInterface $scopeHandler + ScopeHandlerInterface $scopeHandler, ) { $this->em = $em; $this->configurationManager = $configurationManager; @@ -139,34 +133,23 @@ public function getErrors() } /** - * @param array $scopesData - * - * @return array - * * @throws \Exception */ protected function getScopesForEntity(array $scopesData): array { if (!$this->configurationManager->isScopesEnabled()) { if (count($scopesData) > 0) { - throw new \Exception($this->translator->trans( - 'init.errors.scopes_disabled', - [], - 'AdvancedContentBundle' - )); + throw new \Exception($this->translator->trans('init.errors.scopes_disabled', [], 'AdvancedContentBundle')); } + return []; } $scopes = []; foreach ($scopesData as $scopeData) { $scope = $this->scopeHandler->getScopeFromData($scopeData); - if ($scope === null) { - throw new \Exception($this->translator->trans( - 'init.errors.unknown_scope', - ['%scope%' => json_encode($scopeData)], - 'AdvancedContentBundle' - )); + if (null === $scope) { + throw new \Exception($this->translator->trans('init.errors.unknown_scope', ['%scope%' => json_encode($scopeData)], 'AdvancedContentBundle')); } $scopes[] = $scope; } @@ -175,21 +158,15 @@ protected function getScopesForEntity(array $scopesData): array } /** - * @param string $entityClass - * @param array $criteria - * @param array $scopes - * - * @return ScopableInterface|null - * * @throws \Exception */ protected function getExistingScopableEntity(string $entityClass, array $criteria, array $scopes): ?ScopableInterface { $existingEntities = $this->em->getRepository($entityClass)->findBy($criteria); - if (count($existingEntities) === 0) { + if (0 === count($existingEntities)) { return null; } - if (count($existingEntities) === 1) { + if (1 === count($existingEntities)) { return reset($existingEntities); } @@ -204,12 +181,8 @@ protected function getExistingScopableEntity(string $entityClass, array $criteri } if (count($result) > 0) { - if ($entity !== null) { - throw new \Exception($this->translator->trans( - 'init.errors.multiple_entities_same_scope', - [], - 'AdvancedContentBundle' - )); + if (null !== $entity) { + throw new \Exception($this->translator->trans('init.errors.multiple_entities_same_scope', [], 'AdvancedContentBundle')); } $entity = $existingEntity; } @@ -219,7 +192,6 @@ protected function getExistingScopableEntity(string $entityClass, array $criteri } /** - * @param ScopableInterface $entity * @param array|ScopeInterface[] $scopes */ protected function updateEntityScopes(ScopableInterface $entity, array $scopes): void diff --git a/Import/ContentImport.php b/Import/ContentImport.php index 5800e965..a8f825dd 100644 --- a/Import/ContentImport.php +++ b/Import/ContentImport.php @@ -15,19 +15,12 @@ class ContentImport extends AbstractImport */ private $elementImport; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - * @param ScopeHandlerInterface $scopeHandler - * @param ElementImport $elementImport - */ public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, TranslatorInterface $translator, ScopeHandlerInterface $scopeHandler, - ElementImport $elementImport + ElementImport $elementImport, ) { parent::__construct($em, $configurationManager, $translator, $scopeHandler); @@ -56,7 +49,7 @@ protected function importEntity($slug, $contentData) } if (!$content instanceof ContentInterface) { - $content = new $this->entityClasses['content']; + $content = new $this->entityClasses['content'](); } elseif (!$this->allowUpdate) { // Content already exist but update is not allowed by configuration return; @@ -75,6 +68,7 @@ protected function importEntity($slug, $contentData) } else { $this->errors[] = $this->translator->trans('content.errors.duplicate_slug_no_scope', [], 'AdvancedContentBundle'); } + return; } @@ -82,10 +76,6 @@ protected function importEntity($slug, $contentData) $this->em->flush(); } - /** - * @param array $elementsData - * @param ContentInterface $content - */ public function createElements(array $elementsData, ContentInterface $content) { $elements = []; diff --git a/Import/ElementImport.php b/Import/ElementImport.php index c8581be2..74e26404 100644 --- a/Import/ElementImport.php +++ b/Import/ElementImport.php @@ -5,7 +5,6 @@ use Doctrine\ORM\EntityManagerInterface; use Sherlockode\AdvancedContentBundle\Exception\InvalidElementException; use Sherlockode\AdvancedContentBundle\FieldType\FieldTypeInterface; -use Sherlockode\AdvancedContentBundle\LayoutType\Column; use Sherlockode\AdvancedContentBundle\LayoutType\LayoutTypeInterface; use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; use Sherlockode\AdvancedContentBundle\Manager\ElementManager; @@ -51,12 +50,7 @@ class ElementImport private $filesDirectory; /** - * @param ElementManager $elementManager - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param TranslatorInterface $translator - * @param UploadManager $uploadManager - * @param string $rootDir + * @param string $rootDir */ public function __construct( ElementManager $elementManager, @@ -64,7 +58,7 @@ public function __construct( ConfigurationManager $configurationManager, TranslatorInterface $translator, UploadManager $uploadManager, - $rootDir + $rootDir, ) { $this->elementManager = $elementManager; $this->em = $em; @@ -99,7 +93,7 @@ public function getElementImportData(array $elementData, int $position = 0) private function getFieldTypeImportData(FieldTypeInterface $element, array $elementData) { $value = ''; - if ($element->getValueModelTransformer() !== null) { + if (null !== $element->getValueModelTransformer()) { $value = []; } if (isset($elementData['value'])) { @@ -132,7 +126,7 @@ private function processValueArray(array $data) if (isset($data['_file'])) { // handle file $result = $this->processFileUpload($data); - if ($result !== false) { + if (false !== $result) { $data = $result; } } @@ -141,10 +135,8 @@ private function processValueArray(array $data) $content = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findOneBy([ 'slug' => $slug, ]); - if ($content === null) { - throw new \Exception($this->translator->trans('init.errors.content_entity_not_found', [ - '%slug%' => $slug, - ], 'AdvancedContentBundle')); + if (null === $content) { + throw new \Exception($this->translator->trans('init.errors.content_entity_not_found', ['%slug%' => $slug], 'AdvancedContentBundle')); } } @@ -163,7 +155,7 @@ private function processValueArray(array $data) private function processFileUpload(array $data) { - $fileName = $this->getFilesDirectory() . $data['_file']; + $fileName = $this->getFilesDirectory().$data['_file']; if (!file_exists($fileName)) { throw new \Exception($this->translator->trans('init.errors.element_file_not_found', ['%file%' => $fileName], 'AdvancedContentBundle')); } @@ -183,17 +175,15 @@ private function processFileUpload(array $data) */ private function getFilesDirectory() { - if ($this->filesDirectory === null) { + if (null === $this->filesDirectory) { $filesDirectory = $this->configurationManager->getInitFilesDirectory(); - if (strpos($filesDirectory, '/') !== 0) { - $filesDirectory = $this->rootDir . '/' . $filesDirectory; + if (0 !== strpos($filesDirectory, '/')) { + $filesDirectory = $this->rootDir.'/'.$filesDirectory; } if (!file_exists($filesDirectory)) { - throw new \Exception( - $this->translator->trans('init.errors.init_dir', ['%dir%' => $filesDirectory], 'AdvancedContentBundle') - ); + throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $filesDirectory], 'AdvancedContentBundle')); } - $this->filesDirectory = $filesDirectory . '/'; + $this->filesDirectory = $filesDirectory.'/'; } return $this->filesDirectory; diff --git a/Import/ImportResult.php b/Import/ImportResult.php index 364b87ff..bf065c60 100644 --- a/Import/ImportResult.php +++ b/Import/ImportResult.php @@ -4,9 +4,9 @@ class ImportResult { - const FAILURE = 0; - const SUCCESS = 1; - const UNKNOWN = 2; + public const FAILURE = 0; + public const SUCCESS = 1; + public const UNKNOWN = 2; /** * @var int @@ -36,7 +36,7 @@ public function getStatus() */ public function isSuccess() { - return $this->status == self::SUCCESS; + return self::SUCCESS == $this->status; } /** diff --git a/Import/PageImport.php b/Import/PageImport.php index 1463836f..f63cf2d0 100644 --- a/Import/PageImport.php +++ b/Import/PageImport.php @@ -36,7 +36,7 @@ protected function importEntity($pageIdentifier, $pageData) } if (!$page instanceof PageInterface) { - $page = new $this->entityClasses['page']; + $page = new $this->entityClasses['page'](); } elseif (!$this->allowUpdate) { // Page already exist but update is not allowed by configuration return; @@ -49,7 +49,7 @@ protected function importEntity($pageIdentifier, $pageData) $pageType = null; if (isset($pageData['pageType'])) { $pageTypes = $this->em->getRepository($this->entityClasses['page_type'])->findBy([ - 'name' => $pageData['pageType'] + 'name' => $pageData['pageType'], ]); if (count($pageTypes) > 1) { $this->errors[] = $this->translator->trans('init.errors.page_type_too_many_matches', ['%name%' => $pageData['pageType']], 'AdvancedContentBundle'); @@ -63,7 +63,7 @@ protected function importEntity($pageIdentifier, $pageData) } if (!$pageType instanceof PageTypeInterface) { /** @var PageTypeInterface $pageType */ - $pageType = new $this->entityClasses['page_type']; + $pageType = new $this->entityClasses['page_type'](); $pageType->setName($pageData['pageType']); $this->em->persist($pageType); } @@ -73,9 +73,9 @@ protected function importEntity($pageIdentifier, $pageData) if (!empty($pageData['content'])) { $contentData = $pageData['content']; $content = $page->getContent(); - if ($content === null) { + if (null === $content) { /** @var ContentInterface $content */ - $content = new $this->entityClasses['content']; + $content = new $this->entityClasses['content'](); $content->setName($page->getPageIdentifier()); $content->setSlug($page->getPageIdentifier()); $page->setContent($content); @@ -101,9 +101,9 @@ protected function importEntity($pageIdentifier, $pageData) $title = $metaData['title']; $slug = $metaData['slug']; - if ($pageMeta === null) { + if (null === $pageMeta) { /** @var PageMetaInterface $pageMeta */ - $pageMeta = new $this->entityClasses['page_meta']; + $pageMeta = new $this->entityClasses['page_meta'](); $page->setPageMeta($pageMeta); } $pageMeta->setTitle($title); @@ -117,6 +117,7 @@ protected function importEntity($pageIdentifier, $pageData) } else { $this->errors[] = $this->translator->trans('page.errors.duplicate_identifier_no_scope', [], 'AdvancedContentBundle'); } + return; } if (!$this->scopeHandler->isPageSlugValid($page)) { @@ -125,6 +126,7 @@ protected function importEntity($pageIdentifier, $pageData) } else { $this->errors[] = $this->translator->trans('page.errors.duplicate_slug_no_scope', [], 'AdvancedContentBundle'); } + return; } @@ -135,8 +137,6 @@ protected function importEntity($pageIdentifier, $pageData) } /** - * @param ContentImport $contentImport - * * @return $this */ public function setContentImport(ContentImport $contentImport) diff --git a/LayoutType/AbstractLayoutType.php b/LayoutType/AbstractLayoutType.php index 557cac7b..795a96e8 100644 --- a/LayoutType/AbstractLayoutType.php +++ b/LayoutType/AbstractLayoutType.php @@ -13,7 +13,7 @@ abstract class AbstractLayoutType extends AbstractElement implements LayoutTypeI */ public function getFormFieldLabel() { - return 'layout_type.' . $this->getCode() . '.label'; + return 'layout_type.'.$this->getCode().'.label'; } /** @@ -21,7 +21,7 @@ public function getFormFieldLabel() */ public function getFrontTemplate() { - return '@SherlockodeAdvancedContent/Layout/front/' . $this->getCode() . '.html.twig'; + return '@SherlockodeAdvancedContent/Layout/front/'.$this->getCode().'.html.twig'; } /** @@ -29,13 +29,11 @@ public function getFrontTemplate() */ public function getPreviewTemplate() { - return '@SherlockodeAdvancedContent/Layout/preview/'. $this->getCode() .'.html.twig'; + return '@SherlockodeAdvancedContent/Layout/preview/'.$this->getCode().'.html.twig'; } /** - * Add element's field(s) to content form - * - * @param FormBuilderInterface $builder + * Add element's field(s) to content form. * * @return void */ @@ -51,7 +49,7 @@ public function buildContentElement(FormBuilderInterface $builder) ]); $configurationFormType = $this->getConfigurationFormType(); - if ($configurationFormType !== null) { + if (null !== $configurationFormType) { $builder->add('config', $configurationFormType, [ 'label' => false, ]); @@ -78,9 +76,7 @@ public function getRawData($element) } /** - * Get layout configuration form type - * - * @return string + * Get layout configuration form type. */ abstract protected function getConfigurationFormType(): ?string; } diff --git a/LayoutType/Column.php b/LayoutType/Column.php index 9143254c..ace41fd4 100644 --- a/LayoutType/Column.php +++ b/LayoutType/Column.php @@ -3,7 +3,6 @@ namespace Sherlockode\AdvancedContentBundle\LayoutType; use Sherlockode\AdvancedContentBundle\Form\Type\ColumnType; -use Symfony\Component\Form\FormBuilderInterface; class Column extends AbstractLayoutType { @@ -17,9 +16,6 @@ protected function getDefaultIconClass() return 'fa-solid fa-columns'; } - /** - * @return string|null - */ protected function getConfigurationFormType(): ?string { return ColumnType::class; diff --git a/LayoutType/LayoutTypeInterface.php b/LayoutType/LayoutTypeInterface.php index 36cf79f9..13eb4dc7 100644 --- a/LayoutType/LayoutTypeInterface.php +++ b/LayoutType/LayoutTypeInterface.php @@ -6,5 +6,4 @@ interface LayoutTypeInterface extends ElementInterface { - } diff --git a/LayoutType/Row.php b/LayoutType/Row.php index 82014c04..211db717 100644 --- a/LayoutType/Row.php +++ b/LayoutType/Row.php @@ -16,9 +16,6 @@ protected function getDefaultIconClass() return 'fa-solid fa-bars'; } - /** - * @return string|null - */ protected function getConfigurationFormType(): ?string { return RowType::class; diff --git a/Manager/ConfigurationManager.php b/Manager/ConfigurationManager.php index 33c81c80..8f858243 100644 --- a/Manager/ConfigurationManager.php +++ b/Manager/ConfigurationManager.php @@ -10,9 +10,7 @@ class ConfigurationManager protected $config; /** - * Set bundle configuration - * - * @param $config + * Set bundle configuration. */ public function setConfig($config) { @@ -20,7 +18,7 @@ public function setConfig($config) } /** - * Get entity class configuration for given type + * Get entity class configuration for given type. * * @param string $type * @@ -45,9 +43,6 @@ public function getEntityClasses() return $this->config['entity_class']; } - /** - * @return mixed - */ public function getImageDirectory() { return $this->config['upload']['image_directory']; @@ -103,8 +98,6 @@ public function isScopesEnabled() /** * @param string $option - * - * @return mixed */ private function getDefaultOptionValue($option) { diff --git a/Manager/ContentManager.php b/Manager/ContentManager.php index 15bcaf64..a3266602 100644 --- a/Manager/ContentManager.php +++ b/Manager/ContentManager.php @@ -25,15 +25,11 @@ class ContentManager /** * ContentManager constructor. - * - * @param ConfigurationManager $configurationManager - * @param EntityManagerInterface $em - * @param SlugProviderInterface $slugProvider */ public function __construct( ConfigurationManager $configurationManager, EntityManagerInterface $em, - SlugProviderInterface $slugProvider + SlugProviderInterface $slugProvider, ) { $this->configurationManager = $configurationManager; $this->em = $em; @@ -41,11 +37,11 @@ public function __construct( } /** - * Get content by its id + * Get content by its id. * * @param int $id * - * @return null|ContentInterface + * @return ContentInterface|null */ public function getContentById($id) { @@ -53,7 +49,7 @@ public function getContentById($id) } /** - * Get all contents + * Get all contents. * * @return array */ @@ -62,11 +58,6 @@ public function getContents() return $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findAll(); } - /** - * @param ContentInterface $content - * - * @return ContentInterface - */ public function duplicate(ContentInterface $content): ContentInterface { $newContent = clone $content; diff --git a/Manager/ElementManager.php b/Manager/ElementManager.php index 96d7b8f9..0be84e62 100644 --- a/Manager/ElementManager.php +++ b/Manager/ElementManager.php @@ -26,15 +26,13 @@ public function __construct(array $fieldsConfiguration) } /** - * Add field type - * - * @param FieldTypeInterface $fieldType + * Add field type. */ public function addFieldType(FieldTypeInterface $fieldType) { $enabled = true; if (isset($this->fieldsConfiguration[$fieldType->getCode()])) { - if ($this->fieldsConfiguration[$fieldType->getCode()]['enabled'] === false) { + if (false === $this->fieldsConfiguration[$fieldType->getCode()]['enabled']) { $enabled = false; } $fieldType->setConfigData($this->fieldsConfiguration[$fieldType->getCode()]); @@ -45,7 +43,7 @@ public function addFieldType(FieldTypeInterface $fieldType) } /** - * Get available field types + * Get available field types. * * @return array */ @@ -54,7 +52,7 @@ public function getGroupedFieldTypes() $choices = []; foreach ($this->elements as $element) { if ($element instanceof FieldTypeInterface) { - $fieldGroup = 'field_type.group.' . $element->getFieldGroup(); + $fieldGroup = 'field_type.group.'.$element->getFieldGroup(); if (!isset($choices[$fieldGroup])) { $choices[$fieldGroup] = []; } @@ -66,9 +64,7 @@ public function getGroupedFieldTypes() } /** - * Add layout type - * - * @param LayoutTypeInterface $layoutType + * Add layout type. */ public function addLayoutType(LayoutTypeInterface $layoutType) { @@ -76,7 +72,7 @@ public function addLayoutType(LayoutTypeInterface $layoutType) } /** - * Get element + * Get element. * * @param string $elementCode * @@ -89,6 +85,7 @@ public function getElementByCode($elementCode) if (!isset($this->elements[$elementCode])) { throw new InvalidElementException(sprintf('Element "%s" is not handled.', $elementCode)); } + return $this->elements[$elementCode]; } } diff --git a/Manager/ExportManager.php b/Manager/ExportManager.php index 9a712595..75717fad 100644 --- a/Manager/ExportManager.php +++ b/Manager/ExportManager.php @@ -25,13 +25,9 @@ class ExportManager */ private $filesData = []; - /** - * @param PageExport $pageExport - * @param ContentExport $contentExport - */ public function __construct( PageExport $pageExport, - ContentExport $contentExport + ContentExport $contentExport, ) { $this->pageExport = $pageExport; $this->contentExport = $contentExport; @@ -46,7 +42,7 @@ public function generatePagesData($pages) foreach ($pages as $page) { /** @var PageInterface $page */ $data = $this->pageExport->exportData($page); - $this->addToFilesData($data, 'page_' . $page->getPageIdentifier()); + $this->addToFilesData($data, 'page_'.$page->getPageIdentifier()); } } @@ -58,7 +54,7 @@ public function generateContentsData($contents) foreach ($contents as $content) { /** @var ContentInterface $content */ $data = $this->contentExport->exportData($content); - $this->addToFilesData($data, 'content_' . $content->getSlug()); + $this->addToFilesData($data, 'content_'.$content->getSlug()); } } @@ -69,7 +65,7 @@ public function generateContentsData($contents) private function addToFilesData($data, $filename) { $data = Yaml::dump($data, 15); - $this->filesData[$filename . '.yaml'] = $data; + $this->filesData[$filename.'.yaml'] = $data; } /** @@ -83,7 +79,7 @@ public function generateFiles($directory, $useDatePrefix = true) $prefix = date('Ymd-His_'); } foreach ($this->filesData as $filename => $data) { - file_put_contents($directory . $prefix . $filename, $data); + file_put_contents($directory.$prefix.$filename, $data); } } @@ -92,22 +88,21 @@ public function generateFiles($directory, $useDatePrefix = true) */ public function generateZipFile() { - $tmpDir = '/tmp/acb_export_' . time() . '/'; + $tmpDir = '/tmp/acb_export_'.time().'/'; mkdir($tmpDir); $this->generateFiles($tmpDir, false); - $zipFileName = '/tmp/acb_export_' . date('Ymd-His') . '.zip'; + $zipFileName = '/tmp/acb_export_'.date('Ymd-His').'.zip'; $zip = new \ZipArchive(); $zip->open($zipFileName, \ZipArchive::CREATE); $zip->addPattern('/.*/', $tmpDir, ['remove_all_path' => true]); $zip->close(); - foreach (glob($tmpDir . '*') as $file) { + foreach (glob($tmpDir.'*') as $file) { unlink($file); } rmdir($tmpDir); return $zipFileName; } - } diff --git a/Manager/ImportManager.php b/Manager/ImportManager.php index 88976b40..3be5e642 100644 --- a/Manager/ImportManager.php +++ b/Manager/ImportManager.php @@ -3,7 +3,6 @@ namespace Sherlockode\AdvancedContentBundle\Manager; use Sherlockode\AdvancedContentBundle\Import\ContentImport; -use Sherlockode\AdvancedContentBundle\Import\ContentTypeImport; use Sherlockode\AdvancedContentBundle\Import\ImportResult; use Sherlockode\AdvancedContentBundle\Import\PageImport; use Symfony\Component\Console\Style\SymfonyStyle; @@ -12,7 +11,7 @@ class ImportManager { - const ENTITY_MAPPING = [ + public const ENTITY_MAPPING = [ 'pages' => 'Page', 'contents' => 'Content', ]; @@ -42,15 +41,10 @@ class ImportManager */ private $symfonyStyle; - /** - * @param PageImport $pageImport - * @param ContentImport $contentImport - * @param TranslatorInterface $translator - */ public function __construct( PageImport $pageImport, ContentImport $contentImport, - TranslatorInterface $translator + TranslatorInterface $translator, ) { $this->pageImport = $pageImport; $this->contentImport = $contentImport; @@ -70,8 +64,6 @@ public function __construct( } /** - * @param \SplFileInfo $file - * * @throws \Exception */ public function addFileToProcess(\SplFileInfo $file) @@ -104,7 +96,7 @@ public function processData($allowedTypes = []) } $nbEntities = count($dataToProcess['data']); - if ($nbEntities === 0) { + if (0 === $nbEntities) { continue; } @@ -147,9 +139,6 @@ public function setAllowUpdate($allowUpdate) $this->contentImport->setAllowUpdate($allowUpdate); } - /** - * @param SymfonyStyle $symfonyStyle - */ public function setSymfonyStyle(SymfonyStyle $symfonyStyle) { $this->symfonyStyle = $symfonyStyle; diff --git a/Manager/MimeTypeManager.php b/Manager/MimeTypeManager.php index e1326884..669c87e3 100644 --- a/Manager/MimeTypeManager.php +++ b/Manager/MimeTypeManager.php @@ -6,13 +6,13 @@ class MimeTypeManager { - const MIME_TYPE_IMAGE = 10; - const MIME_TYPE_PDF = 20; - const MIME_TYPE_EXE = 30; - const MIME_TYPE_ARCHIVE = 40; - const MIME_TYPE_TEXT = 50; - const MIME_TYPE_SPREADSHEET = 60; - const MIME_TYPE_MULTIMEDIA = 70; + public const MIME_TYPE_IMAGE = 10; + public const MIME_TYPE_PDF = 20; + public const MIME_TYPE_EXE = 30; + public const MIME_TYPE_ARCHIVE = 40; + public const MIME_TYPE_TEXT = 50; + public const MIME_TYPE_SPREADSHEET = 60; + public const MIME_TYPE_MULTIMEDIA = 70; /** * @var array @@ -24,10 +24,6 @@ class MimeTypeManager */ private $translator; - /** - * @param array $mimeTypes - * @param TranslatorInterface $translator - */ public function __construct(array $mimeTypes, TranslatorInterface $translator) { $this->mimeTypes = $mimeTypes; @@ -50,11 +46,6 @@ public function generateMimeTypeChoices(): array ]; } - /** - * @param string $code - * - * @return array - */ public function getMimeTypesByCode(string $code): array { $mimeTypes = [ @@ -64,7 +55,7 @@ public function getMimeTypesByCode(string $code): array self::MIME_TYPE_ARCHIVE => 'sherlockode_advanced_content.mime_type_group.archive', self::MIME_TYPE_TEXT => 'sherlockode_advanced_content.mime_type_group.text_file', self::MIME_TYPE_SPREADSHEET => 'sherlockode_advanced_content.mime_type_group.spreadsheet', - self::MIME_TYPE_MULTIMEDIA => 'sherlockode_advanced_content.mime_type_group.multimedia' + self::MIME_TYPE_MULTIMEDIA => 'sherlockode_advanced_content.mime_type_group.multimedia', ]; if (!isset($mimeTypes[$code])) { @@ -74,21 +65,18 @@ public function getMimeTypesByCode(string $code): array return ['image/*']; } - return ['image/' . $imageMimeTypes[$code]] ?? []; + return ['image/'.$imageMimeTypes[$code]] ?? []; } return $this->mimeTypes[$mimeTypes[$code]]; } - /** - * @return array - */ public function getImageMimeTypesChoices(): array { $types = $this->getMimeTypesByCode(self::MIME_TYPE_IMAGE); $extensions = []; - if (count($types) === 1 && $types[0] === 'image/*') { + if (1 === count($types) && 'image/*' === $types[0]) { $extensions['*'] = $this->translator->trans('field_type.mime_type_restriction.image_all_types', [], 'AdvancedContentBundle'); return $extensions; @@ -101,9 +89,6 @@ public function getImageMimeTypesChoices(): array return array_combine($extensions, $extensions); } - /** - * @return array - */ public function getAllMimeTypes(): array { $mimeTypes = []; diff --git a/Manager/PageManager.php b/Manager/PageManager.php index d96e6612..2abf05ce 100644 --- a/Manager/PageManager.php +++ b/Manager/PageManager.php @@ -12,32 +12,24 @@ class PageManager */ private $slugProvider; - /** - * @param SlugProviderInterface $slugProvider - */ public function __construct( - SlugProviderInterface $slugProvider + SlugProviderInterface $slugProvider, ) { $this->slugProvider = $slugProvider; } - /** - * @param PageInterface $page - * - * @return PageInterface - */ public function duplicate(PageInterface $page): PageInterface { $newPage = clone $page; $this->slugProvider->setPageValidIdentifier($newPage); $pageMeta = $newPage->getPageMeta(); - if ($pageMeta !== null) { + if (null !== $pageMeta) { $this->slugProvider->setPageValidSlug($newPage); } $content = $newPage->getContent(); - if ($content !== null) { + if (null !== $content) { $this->slugProvider->setContentValidSlug($content); } diff --git a/Manager/UploadManager.php b/Manager/UploadManager.php index 95b43895..91eb6df9 100644 --- a/Manager/UploadManager.php +++ b/Manager/UploadManager.php @@ -31,29 +31,24 @@ public function __construct(NamerInterface $fileNamer, $targetDir, $webPath) } /** - * Upload file on server - * - * @param UploadedFile|null $file - * @param string|null $fileName + * Upload file on server. * * @return string */ - public function upload(UploadedFile $file = null, ?string $fileName = null) + public function upload(?UploadedFile $file = null, ?string $fileName = null) { - if ($file === null) { + if (null === $file) { return ''; } - $fileName = $fileName ?? $this->getFileName($file); + $fileName ??= $this->getFileName($file); $file->move($this->getTargetDir(), $fileName); return $fileName; } /** - * Copy file into acb files directory - * - * @param File $file + * Copy file into acb files directory. * * @return string */ @@ -66,19 +61,19 @@ public function copy(File $file) if (!is_writeable($this->getTargetDir())) { throw new \Exception(sprintf('Target directory %s is not writeable', $this->getTargetDir())); } - copy($file->getRealPath(), $this->getTargetDir() . DIRECTORY_SEPARATOR . $fileName); + copy($file->getRealPath(), $this->getTargetDir().DIRECTORY_SEPARATOR.$fileName); return $fileName; } /** - * Remove file + * Remove file. * * @param string $fileName */ public function remove($fileName) { - $fileName = $this->getTargetDir() . DIRECTORY_SEPARATOR . $fileName; + $fileName = $this->getTargetDir().DIRECTORY_SEPARATOR.$fileName; if (!file_exists($fileName)) { return; @@ -88,7 +83,7 @@ public function remove($fileName) } /** - * Get file name + * Get file name. * * @param UploadedFile|File $file * @@ -110,13 +105,13 @@ public function isFileUploaded($src) return false; } - $fileName = $this->getTargetDir() . DIRECTORY_SEPARATOR . $src; + $fileName = $this->getTargetDir().DIRECTORY_SEPARATOR.$src; return file_exists($fileName); } /** - * Get target directory + * Get target directory. * * @return string */ diff --git a/Manager/UrlBuilderManager.php b/Manager/UrlBuilderManager.php index 2f294456..f15eec39 100644 --- a/Manager/UrlBuilderManager.php +++ b/Manager/UrlBuilderManager.php @@ -25,47 +25,37 @@ class UrlBuilderManager public function __construct( UploadManager $uploadManager, Packages $assetPackages, - RequestStack $requestStack + RequestStack $requestStack, ) { $this->uploadManager = $uploadManager; $this->assetPackages = $assetPackages; $this->requestStack = $requestStack; } - /** - * @param string $fileName - * - * @return string - */ public function getFileUrl(string $fileName): string { if (!$fileName) { return ''; } - $filePath = $this->uploadManager->getTargetDir() . DIRECTORY_SEPARATOR . $fileName; + $filePath = $this->uploadManager->getTargetDir().DIRECTORY_SEPARATOR.$fileName; if (!file_exists($filePath)) { return ''; } - return $this->assetPackages->getUrl($this->uploadManager->getWebPath() . '/' . $fileName); + return $this->assetPackages->getUrl($this->uploadManager->getWebPath().'/'.$fileName); } - /** - * @param string $url - * - * @return string - */ public function getFullUrl(string $url): string { if (!$url) { return ''; } - if (substr($url, 0, 1) === '#') { + if ('#' === substr($url, 0, 1)) { return $url; } - if (substr($url, 0, 4) === 'http') { + if ('http' === substr($url, 0, 4)) { return $url; } @@ -80,6 +70,6 @@ public function getFullUrl(string $url): string return $url; } - return $mainRequest->getSchemeAndHttpHost() . '/' . ltrim($url, '/'); + return $mainRequest->getSchemeAndHttpHost().'/'.ltrim($url, '/'); } } diff --git a/Manager/VersionManager.php b/Manager/VersionManager.php index 1075439b..03bb93ec 100644 --- a/Manager/VersionManager.php +++ b/Manager/VersionManager.php @@ -30,33 +30,23 @@ class VersionManager */ private $requestStack; - /** - * @param ConfigurationManager $configurationManager - * @param UserProviderInterface $userProvider - * @param RequestStack $requestStack - */ public function __construct( ConfigurationManager $configurationManager, UserProviderInterface $userProvider, - RequestStack $requestStack + RequestStack $requestStack, ) { $this->configurationManager = $configurationManager; $this->userProvider = $userProvider; $this->requestStack = $requestStack; } - /** - * @param ContentInterface $content - * - * @return array - */ public function getContentData(ContentInterface $content): array { - if ($content->getPage() === null) { + if (null === $content->getPage()) { if ($mainRequest = $this->getRequest()) { if ($contentVersionId = $mainRequest->get('versionId')) { foreach ($content->getVersions() as $version) { - if ($version->getId() === (int)$contentVersionId) { + if ($version->getId() === (int) $contentVersionId) { return $version->getData(); } } @@ -64,19 +54,13 @@ public function getContentData(ContentInterface $content): array } } - if ($content->getContentVersion() !== null && !empty($content->getContentVersion()->getData())) { + if (null !== $content->getContentVersion() && !empty($content->getContentVersion()->getData())) { return $content->getContentVersion()->getData(); } return []; } - /** - * @param ContentInterface $content - * @param bool $linkVersion - * - * @return ContentVersionInterface - */ public function getNewContentVersion(ContentInterface $content, bool $linkVersion = true): ContentVersionInterface { $contentVersion = new ($this->configurationManager->getEntityClass('content_version')); @@ -91,16 +75,11 @@ public function getNewContentVersion(ContentInterface $content, bool $linkVersio return $contentVersion; } - /** - * @param ContentInterface $content - * - * @return ContentVersionInterface - */ public function getDraftContentVersion(ContentInterface $content): ContentVersionInterface { $userId = $this->userProvider->getUserId(); $lastDraft = $this->getLastDraftVersionForUser($content->getVersions()->toArray(), $content->getContentVersion(), $userId); - if ($lastDraft === null || $lastDraft->getCreatedAt() < new \DateTimeImmutable('-1hour')) { + if (null === $lastDraft || $lastDraft->getCreatedAt() < new \DateTimeImmutable('-1hour')) { $lastDraft = new ($this->configurationManager->getEntityClass('content_version')); $lastDraft->setContent($content); $lastDraft->setUserId($userId); @@ -113,14 +92,10 @@ public function getDraftContentVersion(ContentInterface $content): ContentVersio /** * @param array|VersionInterface[] $versions - * @param VersionInterface|null $currentVersion - * @param int|null $userId - * - * @return VersionInterface|null */ private function getLastDraftVersionForUser(array $versions, ?VersionInterface $currentVersion, ?int $userId): ?VersionInterface { - $currentVersionId = $currentVersion === null ? null : $currentVersion->getId(); + $currentVersionId = null === $currentVersion ? null : $currentVersion->getId(); $lastDraft = null; foreach ($versions as $version) { if ($currentVersionId === $version->getId()) { @@ -132,7 +107,7 @@ private function getLastDraftVersionForUser(array $versions, ?VersionInterface $ if (!$version->isAutoSave()) { continue; } - if ($lastDraft === null || $lastDraft->getCreatedAt() < $version->getCreatedAt()) { + if (null === $lastDraft || $lastDraft->getCreatedAt() < $version->getCreatedAt()) { $lastDraft = $version; } } @@ -140,22 +115,17 @@ private function getLastDraftVersionForUser(array $versions, ?VersionInterface $ return $lastDraft; } - /** - * @param PageInterface $page - * - * @return PageVersionInterface - */ public function getNewPageVersion(PageInterface $page): PageVersionInterface { $pageVersion = new ($this->configurationManager->getEntityClass('page_version')); $pageVersion->setCreatedAt(new \DateTimeImmutable()); $pageVersion->setUserId($this->userProvider->getUserId()); - if ($page->getContent() !== null) { + if (null !== $page->getContent()) { $contentVersion = $this->getNewContentVersion($page->getContent(), false); $pageVersion->setContentVersion($contentVersion); } - if ($page->getPageMeta() !== null) { + if (null !== $page->getPageMeta()) { $pageMetaVersion = $this->getNewPageMetaVersion($page->getPageMeta()); $pageVersion->setPageMetaVersion($pageMetaVersion); } @@ -166,11 +136,6 @@ public function getNewPageVersion(PageInterface $page): PageVersionInterface return $pageVersion; } - /** - * @param PageMetaInterface $pageMeta - * - * @return PageMetaVersionInterface - */ private function getNewPageMetaVersion(PageMetaInterface $pageMeta): PageMetaVersionInterface { $pageMetaVersion = new ($this->configurationManager->getEntityClass('page_meta_version')); @@ -185,17 +150,12 @@ private function getNewPageMetaVersion(PageMetaInterface $pageMeta): PageMetaVer return $pageMetaVersion; } - /** - * @param PageInterface $page - * - * @return PageVersionInterface - */ public function getDraftPageVersion(PageInterface $page): PageVersionInterface { $userId = $this->userProvider->getUserId(); /** @var PageVersionInterface $lastDraft */ $lastDraft = $this->getLastDraftVersionForUser($page->getVersions()->toArray(), $page->getPageVersion(), $userId); - if ($lastDraft === null || $lastDraft->getCreatedAt() < new \DateTimeImmutable('-1hour')) { + if (null === $lastDraft || $lastDraft->getCreatedAt() < new \DateTimeImmutable('-1hour')) { $lastDraft = new ($this->configurationManager->getEntityClass('page_version')); $lastDraft->setPage($page); $lastDraft->setUserId($userId); @@ -203,9 +163,9 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface } $lastDraft->setCreatedAt(new \DateTimeImmutable()); - if ($page->getContent() !== null) { + if (null !== $page->getContent()) { $contentVersion = $lastDraft->getContentVersion(); - if ($contentVersion === null) { + if (null === $contentVersion) { $contentVersion = $this->getNewContentVersion($page->getContent(), false); $contentVersion->setAutoSave(true); $lastDraft->setContentVersion($contentVersion); @@ -213,9 +173,9 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface $contentVersion->setCreatedAt(new \DateTimeImmutable()); $contentVersion->setData($page->getContent()->getData()); } - if ($page->getPageMeta() !== null) { + if (null !== $page->getPageMeta()) { $pageMetaVersion = $lastDraft->getPageMetaVersion(); - if ($pageMetaVersion === null) { + if (null === $pageMetaVersion) { $pageMetaVersion = $this->getNewPageMetaVersion($page->getPageMeta()); $pageMetaVersion->setAutoSave(true); $lastDraft->setPageMetaVersion($pageMetaVersion); @@ -230,33 +190,25 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface return $lastDraft; } - /** - * @param PageInterface $page - * - * @return PageVersionInterface|null - */ public function getPageVersionToLoad(PageInterface $page): ?PageVersionInterface { if ($mainRequest = $this->getRequest()) { if ($pageVersionId = $mainRequest->get('versionId')) { foreach ($page->getVersions() as $version) { - if ($version->getId() === (int)$pageVersionId) { + if ($version->getId() === (int) $pageVersionId) { return $version; } } } } - if ($page->getPageVersion() !== null) { + if (null !== $page->getPageVersion()) { return $page->getPageVersion(); } return null; } - /** - * @return Request|null - */ private function getRequest(): ?Request { if (method_exists($this->requestStack, 'getMainRequest')) { diff --git a/Model/Content.php b/Model/Content.php index 9833be40..ac581e53 100644 --- a/Model/Content.php +++ b/Model/Content.php @@ -48,7 +48,7 @@ abstract class Content implements ContentInterface, ScopableInterface protected $scopes; /** - * Content constructor + * Content constructor. */ public function __construct() { @@ -121,9 +121,6 @@ public function getData() } /** - * @param array $data - * @param bool $resetContentVersion - * * @return $this */ public function setData(array $data, bool $resetContentVersion = true) @@ -145,28 +142,21 @@ public function getPage() } /** - * @param PageInterface $page - * * @return $this */ - public function setPage(PageInterface $page = null) + public function setPage(?PageInterface $page = null) { $this->page = $page; return $this; } - /** - * @return ContentVersionInterface|null - */ public function getContentVersion(): ?ContentVersionInterface { return $this->contentVersion; } /** - * @param ContentVersionInterface|null $contentVersion - * * @return $this */ public function setContentVersion(?ContentVersionInterface $contentVersion) @@ -185,8 +175,6 @@ public function getVersions() } /** - * @param ContentVersionInterface $contentVersion - * * @return $this */ public function addVersion(ContentVersionInterface $contentVersion) @@ -198,8 +186,6 @@ public function addVersion(ContentVersionInterface $contentVersion) } /** - * @param ContentVersionInterface $contentVersion - * * @return $this */ public function removeVersion(ContentVersionInterface $contentVersion) @@ -218,8 +204,6 @@ public function getScopes() } /** - * @param ScopeInterface $scope - * * @return $this */ public function addScope(ScopeInterface $scope) @@ -230,8 +214,6 @@ public function addScope(ScopeInterface $scope) } /** - * @param ScopeInterface $scope - * * @return $this */ public function removeScope(ScopeInterface $scope) diff --git a/Model/ContentInterface.php b/Model/ContentInterface.php index cd3e8ef3..03813a1f 100644 --- a/Model/ContentInterface.php +++ b/Model/ContentInterface.php @@ -8,7 +8,7 @@ interface ContentInterface { /** - * Get content id + * Get content id. * * @return int */ @@ -27,14 +27,14 @@ public function getName(); public function setName($name); /** - * Get content's slug + * Get content's slug. * * @return string */ public function getSlug(); /** - * Set content's slug + * Set content's slug. * * @param string $slug * @@ -48,35 +48,25 @@ public function setSlug($slug); public function getData(); /** - * @param array $data - * @param bool $resetContentVersion - * * @return $this */ public function setData(array $data, bool $resetContentVersion = true); /** - * Get content's content page + * Get content's content page. * * @return PageInterface|null */ public function getPage(); /** - * @param PageInterface|null $page - * * @return $this */ - public function setPage(PageInterface $page = null); + public function setPage(?PageInterface $page = null); - /** - * @return ContentVersionInterface|null - */ public function getContentVersion(): ?ContentVersionInterface; /** - * @param ContentVersionInterface|null $contentVersion - * * @return $this */ public function setContentVersion(?ContentVersionInterface $contentVersion); diff --git a/Model/ContentVersion.php b/Model/ContentVersion.php index b767e785..70dc3bba 100644 --- a/Model/ContentVersion.php +++ b/Model/ContentVersion.php @@ -15,7 +15,7 @@ abstract class ContentVersion extends Version implements ContentVersionInterface protected $data; /** - * ContentVersion constructor + * ContentVersion constructor. */ public function __construct() { @@ -23,17 +23,12 @@ public function __construct() parent::__construct(); } - /** - * @return ContentInterface - */ public function getContent(): ContentInterface { return $this->content; } /** - * @param ContentInterface $content - * * @return $this */ public function setContent(ContentInterface $content): self @@ -57,8 +52,6 @@ public function getData() } /** - * @param array $data - * * @return $this */ public function setData(array $data) diff --git a/Model/ContentVersionInterface.php b/Model/ContentVersionInterface.php index 38f35252..00caaf86 100644 --- a/Model/ContentVersionInterface.php +++ b/Model/ContentVersionInterface.php @@ -10,8 +10,6 @@ interface ContentVersionInterface public function getContent(); /** - * @param ContentInterface $content - * * @return $this */ public function setContent(ContentInterface $content); @@ -22,8 +20,6 @@ public function setContent(ContentInterface $content); public function getData(); /** - * @param array $data - * * @return $this */ public function setData(array $data); diff --git a/Model/LocaleScope.php b/Model/LocaleScope.php index c2340f8f..0ee1e192 100644 --- a/Model/LocaleScope.php +++ b/Model/LocaleScope.php @@ -9,9 +9,6 @@ class LocaleScope extends Scope implements LocaleScopeInterface */ protected $locale; - /** - * @return string - */ public function getLocale(): ?string { return $this->locale; @@ -34,7 +31,7 @@ public function setLocale($locale): self */ public function getOptionTitle() { - return (string)$this->locale; + return (string) $this->locale; } /** @@ -42,6 +39,6 @@ public function getOptionTitle() */ public function getUnicityIdentifier() { - return (string)$this->locale; + return (string) $this->locale; } } diff --git a/Model/LocaleScopeInterface.php b/Model/LocaleScopeInterface.php index 5b1eb37a..fc4589fe 100644 --- a/Model/LocaleScopeInterface.php +++ b/Model/LocaleScopeInterface.php @@ -4,14 +4,9 @@ interface LocaleScopeInterface extends ScopeInterface { - /** - * @return string - */ public function getLocale(): ?string; /** - * @param string $locale - * * @return $this */ public function setLocale(string $locale); diff --git a/Model/Page.php b/Model/Page.php index b678bca6..58fadc2c 100644 --- a/Model/Page.php +++ b/Model/Page.php @@ -18,7 +18,7 @@ abstract class Page implements PageInterface, ScopableInterface protected $pageIdentifier; /** - * @var integer + * @var int */ protected $status; @@ -132,13 +132,11 @@ public function getContent() } /** - * @param ContentInterface|null $content - * * @return PageInterface|void */ - public function setContent(ContentInterface $content = null) + public function setContent(?ContentInterface $content = null) { - if ($content !== null) { + if (null !== $content) { $content->setPage($this); } $this->content = $content; @@ -155,11 +153,9 @@ public function getPageType() } /** - * @param PageTypeInterface|null $pageType - * * @return $this */ - public function setPageType(PageTypeInterface $pageType = null) + public function setPageType(?PageTypeInterface $pageType = null) { $this->pageType = $pageType; @@ -175,13 +171,11 @@ public function getPageMeta() } /** - * @param PageMetaInterface|null $pageMeta - * * @return PageInterface|void */ - public function setPageMeta(PageMetaInterface $pageMeta = null) + public function setPageMeta(?PageMetaInterface $pageMeta = null) { - if ($pageMeta !== null) { + if (null !== $pageMeta) { $pageMeta->setPage($this); } $this->pageMeta = $pageMeta; @@ -198,8 +192,6 @@ public function getScopes() } /** - * @param ScopeInterface $scope - * * @return $this */ public function addScope(ScopeInterface $scope) @@ -210,8 +202,6 @@ public function addScope(ScopeInterface $scope) } /** - * @param ScopeInterface $scope - * * @return $this */ public function removeScope(ScopeInterface $scope) @@ -221,17 +211,12 @@ public function removeScope(ScopeInterface $scope) return $this; } - /** - * @return PageVersionInterface|null - */ public function getPageVersion(): ?PageVersionInterface { return $this->pageVersion; } /** - * @param PageVersionInterface|null $pageVersion - * * @return $this */ public function setPageVersion(?PageVersionInterface $pageVersion) @@ -250,8 +235,6 @@ public function getVersions() } /** - * @param PageVersionInterface $pageVersion - * * @return $this */ public function addVersion(PageVersionInterface $pageVersion) @@ -263,8 +246,6 @@ public function addVersion(PageVersionInterface $pageVersion) } /** - * @param PageVersionInterface $pageVersion - * * @return $this */ public function removeVersion(PageVersionInterface $pageVersion) diff --git a/Model/PageInterface.php b/Model/PageInterface.php index 57f7e6c4..82a57496 100644 --- a/Model/PageInterface.php +++ b/Model/PageInterface.php @@ -7,9 +7,9 @@ interface PageInterface { - const STATUS_DRAFT = 0; - const STATUS_PUBLISHED = 10; - const STATUS_TRASH = 20; + public const STATUS_DRAFT = 0; + public const STATUS_PUBLISHED = 10; + public const STATUS_TRASH = 20; /** * @return int @@ -46,11 +46,9 @@ public function setStatus($status); public function getContent(); /** - * @param ContentInterface|null $content - * * @return $this */ - public function setContent(ContentInterface $content = null); + public function setContent(?ContentInterface $content = null); /** * @return PageTypeInterface|null @@ -58,11 +56,9 @@ public function setContent(ContentInterface $content = null); public function getPageType(); /** - * @param PageTypeInterface|null $pageType - * * @return $this */ - public function setPageType(PageTypeInterface $pageType = null); + public function setPageType(?PageTypeInterface $pageType = null); /** * @return PageMetaInterface @@ -70,20 +66,13 @@ public function setPageType(PageTypeInterface $pageType = null); public function getPageMeta(); /** - * @param PageMetaInterface $pageMeta - * * @return $this */ public function setPageMeta(PageMetaInterface $pageMeta); - /** - * @return PageVersionInterface|null - */ public function getPageVersion(): ?PageVersionInterface; /** - * @param PageVersionInterface|null $pageVersion - * * @return $this */ public function setPageVersion(?PageVersionInterface $pageVersion); diff --git a/Model/PageMeta.php b/Model/PageMeta.php index 06333bb7..7a89ad43 100644 --- a/Model/PageMeta.php +++ b/Model/PageMeta.php @@ -150,8 +150,6 @@ public function getPage() } /** - * @param PageInterface $page - * * @return $this */ public function setPage(PageInterface $page) @@ -170,8 +168,6 @@ public function getVersions() } /** - * @param PageMetaVersionInterface $pageMetaVersion - * * @return $this */ public function addVersion(PageMetaVersionInterface $pageMetaVersion) @@ -183,8 +179,6 @@ public function addVersion(PageMetaVersionInterface $pageMetaVersion) } /** - * @param PageMetaVersionInterface $pageMetaVersion - * * @return $this */ public function removeVersion(PageMetaVersionInterface $pageMetaVersion) diff --git a/Model/PageMetaInterface.php b/Model/PageMetaInterface.php index 0cce1ebe..7e5aa90e 100644 --- a/Model/PageMetaInterface.php +++ b/Model/PageMetaInterface.php @@ -66,8 +66,6 @@ public function setMetaDescription($metaDescription); public function getPage(); /** - * @param PageInterface $page - * * @return $this */ public function setPage(PageInterface $page); diff --git a/Model/PageMetaVersion.php b/Model/PageMetaVersion.php index 4b61b4aa..e8c29df0 100644 --- a/Model/PageMetaVersion.php +++ b/Model/PageMetaVersion.php @@ -2,9 +2,6 @@ namespace Sherlockode\AdvancedContentBundle\Model; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Collection; - abstract class PageMetaVersion extends Version implements PageMetaVersionInterface { /** @@ -32,17 +29,12 @@ abstract class PageMetaVersion extends Version implements PageMetaVersionInterfa */ protected $metaDescription; - /** - * @return PageMetaInterface - */ public function getPageMeta(): PageMetaInterface { return $this->pageMeta; } /** - * @param PageMetaInterface $pageMeta - * * @return $this */ public function setPageMeta(PageMetaInterface $pageMeta): self diff --git a/Model/PageMetaVersionInterface.php b/Model/PageMetaVersionInterface.php index 9d962dad..15f073d6 100644 --- a/Model/PageMetaVersionInterface.php +++ b/Model/PageMetaVersionInterface.php @@ -10,8 +10,6 @@ interface PageMetaVersionInterface public function getPageMeta(); /** - * @param PageMetaInterface $pageMeta - * * @return $this */ public function setPageMeta(PageMetaInterface $pageMeta); diff --git a/Model/PageTypeInterface.php b/Model/PageTypeInterface.php index e97ccc8b..3b9ae079 100644 --- a/Model/PageTypeInterface.php +++ b/Model/PageTypeInterface.php @@ -5,21 +5,21 @@ interface PageTypeInterface { /** - * Get field id + * Get field id. * * @return int */ public function getId(); /** - * Get page type's name + * Get page type's name. * * @return string */ public function getName(); /** - * Set page type's name + * Set page type's name. * * @param string $name * diff --git a/Model/PageVersion.php b/Model/PageVersion.php index e78cf8f2..da2fc5c8 100644 --- a/Model/PageVersion.php +++ b/Model/PageVersion.php @@ -19,17 +19,12 @@ abstract class PageVersion extends Version implements PageVersionInterface */ protected $pageMetaVersion; - /** - * @return PageInterface - */ public function getPage(): PageInterface { return $this->page; } /** - * @param PageInterface $page - * * @return $this */ public function setPage(PageInterface $page): self @@ -39,17 +34,12 @@ public function setPage(PageInterface $page): self return $this; } - /** - * @return ContentVersionInterface|null - */ public function getContentVersion(): ?ContentVersionInterface { return $this->contentVersion; } /** - * @param ContentVersionInterface $contentVersion - * * @return $this */ public function setContentVersion(ContentVersionInterface $contentVersion): self @@ -59,17 +49,12 @@ public function setContentVersion(ContentVersionInterface $contentVersion): self return $this; } - /** - * @return PageMetaVersionInterface|null - */ public function getPageMetaVersion(): ?PageMetaVersionInterface { return $this->pageMetaVersion; } /** - * @param PageMetaVersionInterface $pageMetaVersion - * * @return $this */ public function setPageMetaVersion(PageMetaVersionInterface $pageMetaVersion): self diff --git a/Model/PageVersionInterface.php b/Model/PageVersionInterface.php index d3e1f24d..c9173e91 100644 --- a/Model/PageVersionInterface.php +++ b/Model/PageVersionInterface.php @@ -10,8 +10,6 @@ interface PageVersionInterface public function getPage(); /** - * @param PageInterface $page - * * @return $this */ public function setPage(PageInterface $page); @@ -22,8 +20,6 @@ public function setPage(PageInterface $page); public function getContentVersion(); /** - * @param ContentVersionInterface $contentVersion - * * @return $this */ public function setContentVersion(ContentVersionInterface $contentVersion); @@ -34,8 +30,6 @@ public function setContentVersion(ContentVersionInterface $contentVersion); public function getPageMetaVersion(); /** - * @param PageMetaVersionInterface $pageMetaVersion - * * @return $this */ public function setPageMetaVersion(PageMetaVersionInterface $pageMetaVersion); diff --git a/Model/ScopableInterface.php b/Model/ScopableInterface.php index cf049dd8..07ecb0a1 100644 --- a/Model/ScopableInterface.php +++ b/Model/ScopableInterface.php @@ -13,15 +13,11 @@ interface ScopableInterface public function getScopes(); /** - * @param ScopeInterface $scope - * * @return $this */ public function addScope(ScopeInterface $scope); /** - * @param ScopeInterface $scope - * * @return $this */ public function removeScope(ScopeInterface $scope); diff --git a/Model/Scope.php b/Model/Scope.php index cf618c21..8460a915 100644 --- a/Model/Scope.php +++ b/Model/Scope.php @@ -9,9 +9,6 @@ abstract class Scope implements ScopeInterface */ protected $id; - /** - * @return int - */ public function getId(): int { return $this->id; diff --git a/Model/Version.php b/Model/Version.php index 859fb724..69d716be 100644 --- a/Model/Version.php +++ b/Model/Version.php @@ -29,25 +29,17 @@ public function __construct() $this->autoSave = false; } - /** - * @return int - */ public function getId(): int { return $this->id; } - /** - * @return int|null - */ public function getUserId(): ?int { return $this->userId; } /** - * @param int|null $userId - * * @return $this */ public function setUserId(?int $userId): self @@ -57,17 +49,12 @@ public function setUserId(?int $userId): self return $this; } - /** - * @return \DateTimeInterface - */ public function getCreatedAt(): \DateTimeInterface { return $this->createdAt; } /** - * @param \DateTimeInterface $createdAt - * * @return $this */ public function setCreatedAt(\DateTimeInterface $createdAt): self @@ -77,17 +64,12 @@ public function setCreatedAt(\DateTimeInterface $createdAt): self return $this; } - /** - * @return bool - */ public function isAutoSave(): bool { return $this->autoSave; } /** - * @param bool $autoSave - * * @return $this */ public function setAutoSave(bool $autoSave): self diff --git a/Model/VersionInterface.php b/Model/VersionInterface.php index dde9a681..5d5b16fa 100644 --- a/Model/VersionInterface.php +++ b/Model/VersionInterface.php @@ -5,7 +5,7 @@ interface VersionInterface { /** - * Get version id + * Get version id. * * @return int */ @@ -17,8 +17,6 @@ public function getId(); public function getUserId(); /** - * @param int|null $userId - * * @return $this */ public function setUserId(?int $userId); @@ -29,20 +27,13 @@ public function setUserId(?int $userId); public function getCreatedAt(); /** - * @param \DateTimeInterface $createdAt - * * @return $this */ public function setCreatedAt(\DateTimeInterface $createdAt); - /** - * @return bool - */ public function isAutoSave(): bool; /** - * @param bool $autoSave - * * @return $this */ public function setAutoSave(bool $autoSave); diff --git a/Naming/ClientOriginalNamer.php b/Naming/ClientOriginalNamer.php index 0456b0d7..ecd55943 100644 --- a/Naming/ClientOriginalNamer.php +++ b/Naming/ClientOriginalNamer.php @@ -7,11 +7,6 @@ class ClientOriginalNamer implements NamerInterface { - /** - * @param File $file - * - * @return string - */ public function getFilename(File $file): string { $fileName = $file->getFilename(); diff --git a/Naming/NamerInterface.php b/Naming/NamerInterface.php index bfd80fb5..c0957042 100644 --- a/Naming/NamerInterface.php +++ b/Naming/NamerInterface.php @@ -6,10 +6,5 @@ interface NamerInterface { - /** - * @param File $file - * - * @return string - */ public function getFilename(File $file): string; } diff --git a/Naming/UniqueNamer.php b/Naming/UniqueNamer.php index f6f70acf..6196d577 100644 --- a/Naming/UniqueNamer.php +++ b/Naming/UniqueNamer.php @@ -7,11 +7,6 @@ class UniqueNamer implements NamerInterface { - /** - * @param File $file - * - * @return string - */ public function getFilename(File $file): string { $extension = $file->getExtension(); @@ -22,7 +17,7 @@ public function getFilename(File $file): string $fileName = $file->getClientOriginalName(); } - $fileName = str_replace('.' . $extension, '', $fileName); + $fileName = str_replace('.'.$extension, '', $fileName); return sprintf('%s_%s.%s', $fileName, md5(uniqid()), $extension); } diff --git a/Scope/LocaleScopeHandler.php b/Scope/LocaleScopeHandler.php index 66edf86f..873a0f40 100644 --- a/Scope/LocaleScopeHandler.php +++ b/Scope/LocaleScopeHandler.php @@ -4,7 +4,6 @@ use Doctrine\ORM\EntityManagerInterface; use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; -use Sherlockode\AdvancedContentBundle\Model\ScopableInterface; use Sherlockode\AdvancedContentBundle\Model\ScopeInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -15,34 +14,21 @@ class LocaleScopeHandler extends ScopeHandler */ private $requestStack; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - * @param RequestStack $requestStack - */ public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, - RequestStack $requestStack + RequestStack $requestStack, ) { parent::__construct($em, $configurationManager); $this->requestStack = $requestStack; } - /** - * @return string|null - */ public function getScopeGroupBy(): ?string { return null; } - /** - * @param array $data - * - * @return ScopeInterface|null - */ public function getScopeFromData(array $data): ?ScopeInterface { if (empty($data['locale'])) { @@ -54,11 +40,6 @@ public function getScopeFromData(array $data): ?ScopeInterface ]); } - /** - * @param ScopeInterface $scope - * - * @return array - */ public function getDataFromScope(ScopeInterface $scope): array { return [ @@ -66,9 +47,6 @@ public function getDataFromScope(ScopeInterface $scope): array ]; } - /** - * @return ScopeInterface|null - */ public function getCurrentScope(): ?ScopeInterface { if (!$this->configurationManager->isScopesEnabled()) { @@ -82,7 +60,7 @@ public function getCurrentScope(): ?ScopeInterface // compat SF < 5.3 $mainRequest = $this->requestStack->getMasterRequest(); } - if ($mainRequest === null) { + if (null === $mainRequest) { return null; } diff --git a/Scope/ScopeHandler.php b/Scope/ScopeHandler.php index 7f08f747..972364ed 100644 --- a/Scope/ScopeHandler.php +++ b/Scope/ScopeHandler.php @@ -20,21 +20,12 @@ abstract class ScopeHandler implements ScopeHandlerInterface */ protected $configurationManager; - /** - * @param EntityManagerInterface $em - * @param ConfigurationManager $configurationManager - */ public function __construct(EntityManagerInterface $em, ConfigurationManager $configurationManager) { $this->em = $em; $this->configurationManager = $configurationManager; } - /** - * @param ContentInterface $content - * - * @return bool - */ public function isContentSlugValid(ContentInterface $content): bool { $existingContents = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findBy([ @@ -44,21 +35,16 @@ public function isContentSlugValid(ContentInterface $content): bool return $this->validateScopableEntity($content, $existingContents); } - /** - * @param PageInterface $page - * - * @return bool - */ public function isPageSlugValid(PageInterface $page): bool { $existingPages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findAll(); /** @var PageInterface $existingPage */ foreach ($existingPages as $key => $existingPage) { - if ($existingPage->getPageVersion() === null) { + if (null === $existingPage->getPageVersion()) { unset($existingPages[$key]); continue; } - if ($existingPage->getPageVersion()->getPageMetaVersion() === null) { + if (null === $existingPage->getPageVersion()->getPageMetaVersion()) { unset($existingPages[$key]); continue; } @@ -72,11 +58,6 @@ public function isPageSlugValid(PageInterface $page): bool return $this->validateScopableEntity($page, $existingPages); } - /** - * @param PageInterface $page - * - * @return bool - */ public function isPageIdentifierValid(PageInterface $page): bool { $existingPages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findBy([ @@ -89,8 +70,6 @@ public function isPageIdentifierValid(PageInterface $page): bool /** * @param ScopableInterface|ContentInterface|PageInterface $scopable * @param array|ScopableInterface[]|ContentInterface[]|PageInterface[] $existingEntities - * - * @return bool */ private function validateScopableEntity(ScopableInterface $scopable, array $existingEntities): bool { @@ -113,12 +92,6 @@ private function validateScopableEntity(ScopableInterface $scopable, array $exis return true; } - /** - * @param string $entityCode - * @param array $criteria - * - * @return ScopableInterface|null - */ public function getEntityForCurrentScope(string $entityCode, array $criteria): ?ScopableInterface { return $this->filterEntityForCurrentScope( @@ -128,8 +101,6 @@ public function getEntityForCurrentScope(string $entityCode, array $criteria): ? /** * @param array|ScopableInterface[] $entities - * - * @return ScopableInterface|null */ public function filterEntityForCurrentScope(array $entities): ?ScopableInterface { @@ -138,7 +109,7 @@ public function filterEntityForCurrentScope(array $entities): ?ScopableInterface } $currentScope = $this->getCurrentScope(); - if ($currentScope === null) { + if (null === $currentScope) { return null; } diff --git a/Scope/ScopeHandlerInterface.php b/Scope/ScopeHandlerInterface.php index c837f929..576c3157 100644 --- a/Scope/ScopeHandlerInterface.php +++ b/Scope/ScopeHandlerInterface.php @@ -9,63 +9,24 @@ interface ScopeHandlerInterface { - /** - * @return string|null - */ public function getScopeGroupBy(): ?string; - /** - * @param ContentInterface $content - * - * @return bool - */ public function isContentSlugValid(ContentInterface $content): bool; - /** - * @param PageInterface $page - * - * @return bool - */ public function isPageSlugValid(PageInterface $page): bool; - /** - * @param PageInterface $page - * - * @return bool - */ public function isPageIdentifierValid(PageInterface $page): bool; - /** - * @param array $data - * - * @return ScopeInterface|null - */ public function getScopeFromData(array $data): ?ScopeInterface; - /** - * @param ScopeInterface $scope - * - * @return array - */ public function getDataFromScope(ScopeInterface $scope): array; - /** - * @param string $entityCode - * @param array $criteria - * - * @return ScopableInterface|null - */ public function getEntityForCurrentScope(string $entityCode, array $criteria): ?ScopableInterface; /** * @param array|ScopableInterface[] $entities - * - * @return ScopableInterface|null */ public function filterEntityForCurrentScope(array $entities): ?ScopableInterface; - /** - * @return ScopeInterface|null - */ public function getCurrentScope(): ?ScopeInterface; } diff --git a/SherlockodeAdvancedContentBundle.php b/SherlockodeAdvancedContentBundle.php index 886ca190..2b483629 100644 --- a/SherlockodeAdvancedContentBundle.php +++ b/SherlockodeAdvancedContentBundle.php @@ -2,17 +2,14 @@ namespace Sherlockode\AdvancedContentBundle; +use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; use Sherlockode\AdvancedContentBundle\DependencyInjection\Compiler\ElementPass; use Sherlockode\AdvancedContentBundle\DependencyInjection\Compiler\FormThemePass; -use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; +use Symfony\Component\HttpKernel\Bundle\Bundle; class SherlockodeAdvancedContentBundle extends Bundle { - /** - * @param ContainerBuilder $container - */ public function build(ContainerBuilder $container): void { parent::build($container); @@ -21,14 +18,11 @@ public function build(ContainerBuilder $container): void $container->addCompilerPass(new FormThemePass()); } - /** - * @param ContainerBuilder $container - */ private function addRegisterMappingsPass(ContainerBuilder $container) { - $mappings = array( + $mappings = [ realpath(__DIR__.'/Resources/config/doctrine-mapping') => 'Sherlockode\AdvancedContentBundle\Model', - ); + ]; if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings)); diff --git a/Slug/SlugProvider.php b/Slug/SlugProvider.php index 9d1a0f46..bc3a688a 100644 --- a/Slug/SlugProvider.php +++ b/Slug/SlugProvider.php @@ -13,17 +13,11 @@ class SlugProvider implements SlugProviderInterface */ private $scopeHandler; - /** - * @param ScopeHandlerInterface $scopeHandler - */ public function __construct(ScopeHandlerInterface $scopeHandler) { $this->scopeHandler = $scopeHandler; } - /** - * @param PageInterface $page - */ public function setPageValidIdentifier(PageInterface $page): void { while (true) { @@ -34,9 +28,6 @@ public function setPageValidIdentifier(PageInterface $page): void } } - /** - * @param PageInterface $page - */ public function setPageValidSlug(PageInterface $page): void { while (true) { @@ -47,9 +38,6 @@ public function setPageValidSlug(PageInterface $page): void } } - /** - * @param ContentInterface $content - */ public function setContentValidSlug(ContentInterface $content): void { while (true) { @@ -62,15 +50,13 @@ public function setContentValidSlug(ContentInterface $content): void /** * @param string $value - * - * @return string */ private function getNewValue($value): string { if (preg_match('/-(\d+)$/', $value, $matches) && array_key_exists(1, $matches)) { - return preg_replace('/' . $matches[1] . '$/', $matches[1] + 1, $value); + return preg_replace('/'.$matches[1].'$/', $matches[1] + 1, $value); } - return $value . '-1'; + return $value.'-1'; } } diff --git a/Slug/SlugProviderInterface.php b/Slug/SlugProviderInterface.php index d90e1509..a9a651ef 100644 --- a/Slug/SlugProviderInterface.php +++ b/Slug/SlugProviderInterface.php @@ -7,18 +7,9 @@ interface SlugProviderInterface { - /** - * @param PageInterface $page - */ public function setPageValidIdentifier(PageInterface $page): void; - /** - * @param PageInterface $page - */ public function setPageValidSlug(PageInterface $page): void; - /** - * @param ContentInterface $content - */ public function setContentValidSlug(ContentInterface $content): void; } diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index 91e03e26..f6d33444 100644 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -18,7 +18,7 @@ class ContentExtension extends AbstractExtension { /** * @var ElementManager - */ + */ private $elementManager; /** @@ -52,13 +52,7 @@ class ContentExtension extends AbstractExtension private $baseFormTheme; /** - * @param ElementManager $elementManager - * @param Environment $twig - * @param EntityManager $em - * @param UrlBuilderManager $urlBuilderManager - * @param UserProviderInterface $userProvider - * @param ScopeHandlerInterface $scopeHandler - * @param string $baseFormTheme + * @param string $baseFormTheme */ public function __construct( ElementManager $elementManager, @@ -67,7 +61,7 @@ public function __construct( UrlBuilderManager $urlBuilderManager, UserProviderInterface $userProvider, ScopeHandlerInterface $scopeHandler, - $baseFormTheme + $baseFormTheme, ) { $this->elementManager = $elementManager; $this->twig = $twig; @@ -79,7 +73,7 @@ public function __construct( } /** - * Add specific twig function + * Add specific twig function. * * @return TwigFunction[] */ @@ -111,13 +105,7 @@ public function renderElement(array $elementData) return $this->twig->render($element->getFrontTemplate(), $params); } - /** - * @param array $elementData - * @param FormView|null $form - * - * @return string - */ - public function renderElementPreview(array $elementData, FormView $form = null): string + public function renderElementPreview(array $elementData, ?FormView $form = null): string { $element = $this->elementManager->getElementByCode($elementData['elementType']); @@ -130,7 +118,6 @@ public function renderElementPreview(array $elementData, FormView $form = null): return $this->twig->render($template, array_merge($params, ['form' => $form])); } - public function findEntity($identifier, $class) { return $this->em->getRepository($class)->find($identifier); @@ -144,31 +131,16 @@ public function getBaseFormTheme() return $this->baseFormTheme; } - /** - * @param string $fileName - * - * @return string - */ public function getFileUrl(string $fileName): string { return $this->urlBuilderManager->getFileUrl($fileName); } - /** - * @param string $url - * - * @return string - */ public function getFullUrl(string $url): string { return $this->urlBuilderManager->getFullUrl($url); } - /** - * @param string $elementType - * - * @return string - */ public function getElementLabel(string $elementType): string { $element = $this->elementManager->getElementByCode($elementType); @@ -176,19 +148,14 @@ public function getElementLabel(string $elementType): string return $element->getFormFieldLabel(); } - /** - * @param array $config - * - * @return array - */ public function getColumnClasses(array $config): array { $classes = []; $size = $config['size'] ?? 12; - $classes[] = '-' === $size ? 'col' : 'col-' . $size; + $classes[] = '-' === $size ? 'col' : 'col-'.$size; $offset = $config['offset'] ?? 0; if (!empty($offset)) { - $classes[] = 'offset-' . $offset; + $classes[] = 'offset-'.$offset; } $devices = [ @@ -198,26 +165,21 @@ public function getColumnClasses(array $config): array 'xl', ]; foreach ($devices as $device) { - if (isset($config['size_' . $device])) { - $classes[] = '-' === $size ? 'col' : 'col-' . $device . '-' . $config['size_' . $device]; + if (isset($config['size_'.$device])) { + $classes[] = '-' === $size ? 'col' : 'col-'.$device.'-'.$config['size_'.$device]; } - if (isset($config['offset_' . $device])) { - $classes[] = 'offset-' . $device . '-' . $config['offset_' . $device]; + if (isset($config['offset_'.$device])) { + $classes[] = 'offset-'.$device.'-'.$config['offset_'.$device]; } } return $classes; } - /** - * @param array $config - * - * @return array - */ public function getRowClasses(array $config): array { $classes = []; - $classes[] = 'justify-content-' . ($config['justify_content'] ?? 'start'); + $classes[] = 'justify-content-'.($config['justify_content'] ?? 'start'); if ($config['mobile_reverse_columns'] ?? false) { $classes[] = 'flex-row-reverse flex-md-row'; } @@ -225,12 +187,6 @@ public function getRowClasses(array $config): array return $classes; } - /** - * @param array $extra - * @param string $defaultDisplay - * - * @return array - */ public function getElementAttributes(array $extra, string $defaultDisplay = 'block'): array { return [ @@ -240,12 +196,6 @@ public function getElementAttributes(array $extra, string $defaultDisplay = 'blo ]; } - /** - * @param array $extra - * @param string $defaultDisplay - * - * @return array - */ private function getElementClasses(array $extra, string $defaultDisplay = 'block'): array { $classes = []; @@ -272,13 +222,13 @@ private function getElementClasses(array $extra, string $defaultDisplay = 'block foreach ($devices as $key => $device) { if (in_array($device, $hideOn)) { - if ($lastHidden === null || ($lastHidden + 1) !== $key) { - $classes[] = 'd-' . ($device === 'xs' ? '' : $device . '-') . 'none'; + if (null === $lastHidden || ($lastHidden + 1) !== $key) { + $classes[] = 'd-'.('xs' === $device ? '' : $device.'-').'none'; } $lastHidden = $key; } else { - if ($device !== 'xs' && ($lastDisplayed === null || ($lastDisplayed + 1) !== $key)) { - $classes[] = 'd-' . $device . '-' . $defaultDisplay; + if ('xs' !== $device && (null === $lastDisplayed || ($lastDisplayed + 1) !== $key)) { + $classes[] = 'd-'.$device.'-'.$defaultDisplay; } $lastDisplayed = $key; } @@ -288,11 +238,6 @@ private function getElementClasses(array $extra, string $defaultDisplay = 'block return $classes; } - /** - * @param array $extra - * - * @return array - */ private function getElementStyles(array $extra): array { $design = $extra['design'] ?? []; @@ -300,48 +245,39 @@ private function getElementStyles(array $extra): array foreach ($this->getPixelProperties() as $property) { if ($design[$property] ?? null) { - $styles[] = str_replace('_', '-', $property) . ':' . $design[$property] . 'px'; + $styles[] = str_replace('_', '-', $property).':'.$design[$property].'px'; } } $colorProperties = ['border', 'background']; foreach ($colorProperties as $colorProperty) { $color = $this->getColorForProperty($design, $colorProperty); - if ($color !== null) { - $styles[] = $colorProperty . '-color:' . $color; + if (null !== $color) { + $styles[] = $colorProperty.'-color:'.$color; } } $borderStyle = $design['border_style'] ?? 'none'; - if ($borderStyle !== 'none') { - $styles[] = 'border-style:' . $borderStyle; + if ('none' !== $borderStyle) { + $styles[] = 'border-style:'.$borderStyle; } return $styles; } - /** - * @param array $design - * @param string $property - * - * @return string|null - */ private function getColorForProperty(array $design, string $property): ?string { - $selectColor = $design[$property . '_color_select'] ?? 'none'; - if ($selectColor === 'none') { + $selectColor = $design[$property.'_color_select'] ?? 'none'; + if ('none' === $selectColor) { return null; } - if ($selectColor === 'transparent') { + if ('transparent' === $selectColor) { return 'transparent'; } - return $design[$property . '_color'] ?? null; + return $design[$property.'_color'] ?? null; } - /** - * @return array - */ private function getPixelProperties(): array { $directions = ['top', 'right', 'bottom', 'left']; @@ -363,8 +299,6 @@ private function getPixelProperties(): array } /** - * @param FormView $form - * * @return array|mixed */ public function getJsonForm(FormView $form) @@ -390,31 +324,16 @@ public function getJsonForm(FormView $form) return $form->vars['data']; } - /** - * @param VersionInterface $version - * - * @return string - */ public function getVersionUserName(VersionInterface $version): string { return $this->userProvider->getUserName($version->getUserId()); } - /** - * @param string $slug - * - * @return ContentInterface|null - */ public function getContentBySlug(string $slug): ?ContentInterface { return $this->scopeHandler->getEntityForCurrentScope('content', ['slug' => $slug]); } - /** - * @param array $config - * - * @return string - */ public function getColSize(array $config): string { $colSize = $this->cleanColSize($config['size']); @@ -428,7 +347,7 @@ public function getColSize(array $config): string } if (isset($config['offset_'.$device])) { - $colOffset = $config['offset_' . $device]; + $colOffset = $config['offset_'.$device]; } } @@ -439,11 +358,6 @@ public function getColSize(array $config): string return $colSize + $colOffset; } - /** - * @param string $value - * - * @return string - */ private function cleanColSize(string $value): string { if ('auto' === $value || '-' === $value) { diff --git a/Twig/Extension/ScopeExtension.php b/Twig/Extension/ScopeExtension.php index 86b007c7..f3554b63 100644 --- a/Twig/Extension/ScopeExtension.php +++ b/Twig/Extension/ScopeExtension.php @@ -13,17 +13,14 @@ class ScopeExtension extends AbstractExtension */ private $configurationManager; - /** - * @param ConfigurationManager $configurationManager - */ public function __construct( - ConfigurationManager $configurationManager + ConfigurationManager $configurationManager, ) { $this->configurationManager = $configurationManager; } /** - * Add specific twig function + * Add specific twig function. * * @return TwigFunction[] */ @@ -34,9 +31,6 @@ public function getFunctions() ]; } - /** - * @return bool - */ public function isScopesEnabled(): bool { return $this->configurationManager->isScopesEnabled(); diff --git a/User/AnonymousUserProvider.php b/User/AnonymousUserProvider.php index 7a3d46c9..0e4d2cd6 100644 --- a/User/AnonymousUserProvider.php +++ b/User/AnonymousUserProvider.php @@ -11,27 +11,16 @@ class AnonymousUserProvider implements UserProviderInterface */ private $translator; - /** - * @param TranslatorInterface $translator - */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } - /** - * @return int|null - */ public function getUserId(): ?int { return null; } - /** - * @param int|null $userId - * - * @return string - */ public function getUserName(?int $userId): string { return $this->translator->trans('version.user.anonymous', [], 'AdvancedContentBundle'); diff --git a/User/UserProviderInterface.php b/User/UserProviderInterface.php index cd345222..0244ba9e 100644 --- a/User/UserProviderInterface.php +++ b/User/UserProviderInterface.php @@ -4,15 +4,7 @@ interface UserProviderInterface { - /** - * @return int|null - */ public function getUserId(): ?int; - /** - * @param int|null $userId - * - * @return string - */ public function getUserName(?int $userId): string; } diff --git a/composer.json b/composer.json index 9bbc96de..6dc53388 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,12 @@ } ], "require": { - "php": "^7.4 || ^8.1", + "php": "^8.2", "cocur/slugify": "^4.0", - "symfony/form": "^5.3 || ^6.0", - "symfony/framework-bundle": "^5.3 || ^6.0", - "symfony/twig-bundle": "^5.3 || ^6.0", - "twig/twig": "^2.0 || ^3.0" + "symfony/form": "^7.4", + "symfony/framework-bundle": "^7.4", + "symfony/twig-bundle": "^7.4", + "twig/twig": "^3.0" }, "suggest": { "friendsofsymfony/ckeditor-bundle": "Required for the WYSIWYG field type", From 0c96115d2bae6b6398e3afb318b54be9203e0c1c Mon Sep 17 00:00:00 2001 From: simbr Date: Wed, 25 Mar 2026 18:52:00 +0100 Subject: [PATCH 2/6] Rector SF partials rules --- Command/ExportCommand.php | 65 +++-------- Command/ImportCommand.php | 54 +++------ Controller/ContentController.php | 72 ++---------- Controller/Crud/ContentController.php | 35 ++---- Controller/Crud/PageController.php | 33 ++---- Controller/Crud/ScopeController.php | 18 +-- Controller/PageController.php | 44 ++----- Controller/ToolsController.php | 59 +++------- DependencyInjection/Compiler/ElementPass.php | 5 +- .../Compiler/FormThemePass.php | 1 + Doctrine/MigrationHelper.php | 22 +--- Event/AcbFilePreSubmitEvent.php | 18 +-- EventListener/AcbFileListener.php | 8 +- EventListener/ContentListener.php | 20 +--- EventListener/PageListener.php | 22 ++-- EventListener/VersionListener.php | 3 + Export/ContentExport.php | 21 +--- Export/ElementExport.php | 29 ++--- Export/PageExport.php | 9 +- Export/ScopeExport.php | 16 +-- FieldType/AbstractFieldType.php | 8 +- FieldType/AbstractInputType.php | 8 +- FieldType/Content.php | 12 +- FieldType/File.php | 10 +- FieldType/Iframe.php | 1 + FieldType/Image.php | 5 + FieldType/ImageCarousel.php | 6 + FieldType/Link.php | 4 + FieldType/RelativeLink.php | 13 +-- FieldType/Separator.php | 1 + FieldType/TextArea.php | 1 + FieldType/Title.php | 1 + FieldType/Video.php | 1 + FieldType/Wysiwyg.php | 1 + Form/DataTransformer/StringToEntity.php | 25 +--- Form/Type/AcbContentType.php | 18 +-- Form/Type/AcbFileType.php | 36 ++---- Form/Type/ColumnType.php | 1 + Form/Type/ContentDataType.php | 2 + Form/Type/ContentType.php | 37 ++---- Form/Type/ElementHideOnType.php | 1 + Form/Type/ElementType.php | 1 + Form/Type/ElementsType.php | 30 ++--- Form/Type/EntityType.php | 2 + Form/Type/ExportType.php | 20 +--- Form/Type/ImageType.php | 9 +- Form/Type/PageMetaType.php | 9 +- Form/Type/PageType.php | 27 +---- Form/Type/PageTypeType.php | 8 +- Form/Type/PictureEntryType.php | 2 + Form/Type/PictureType.php | 2 +- Form/Type/RepeaterType.php | 13 ++- Form/Type/ScopeChoiceType.php | 17 +-- Form/Type/ScopeType.php | 8 +- Form/Type/WysiwygType.php | 9 +- Import/AbstractImport.php | 18 +-- Import/ContentImport.php | 14 +-- Import/ElementImport.php | 62 +++------- Import/ImportResult.php | 9 +- Import/PageImport.php | 8 +- LayoutType/AbstractLayoutType.php | 5 +- LayoutType/Column.php | 1 + LayoutType/Row.php | 1 + Manager/ContentManager.php | 24 +--- Manager/ElementManager.php | 14 +-- Manager/ExportManager.php | 18 +-- Manager/ImportManager.php | 26 +---- Manager/MimeTypeManager.php | 26 ++--- Manager/PageManager.php | 11 +- Manager/UploadManager.php | 29 ++--- Manager/UrlBuilderManager.php | 30 ++--- Manager/VersionManager.php | 63 ++++------ Model/Content.php | 3 +- Model/ContentVersion.php | 7 +- Model/Page.php | 4 + Model/PageInterface.php | 2 + Model/Version.php | 3 +- Resources/config/routing/content.xml | 8 +- Resources/config/routing/content_crud.xml | 10 +- Resources/config/routing/page.xml | 4 +- Resources/config/routing/page_crud.xml | 8 +- Resources/config/routing/scope_crud.xml | 2 +- Resources/config/routing/tools.xml | 8 +- Scope/LocaleScopeHandler.php | 10 +- Scope/ScopeHandler.php | 19 +-- SherlockodeAdvancedContentBundle.php | 6 +- Slug/SlugProvider.php | 11 +- Twig/Extension/ContentExtension.php | 108 +++++------------- Twig/Extension/ScopeExtension.php | 27 +---- User/AnonymousUserProvider.php | 8 +- 90 files changed, 453 insertions(+), 1057 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 5c6c7837..9e64f87d 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -17,26 +17,6 @@ class ExportCommand extends Command { public const AVAILABLE_ENTITIES = ['Page', 'Content']; - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var string - */ - private $rootDir; - /** * @var SymfonyStyle */ @@ -47,11 +27,6 @@ class ExportCommand extends Command */ private $sourceDirectory; - /** - * @var ExportManager - */ - private $exportManager; - /** * @var array */ @@ -62,19 +37,14 @@ class ExportCommand extends Command * @param string|null $name */ public function __construct( - EntityManagerInterface $em, - ConfigurationManager $configurationManager, - TranslatorInterface $translator, - ExportManager $exportManager, - $rootDir, + private readonly EntityManagerInterface $em, + private readonly ConfigurationManager $configurationManager, + private readonly TranslatorInterface $translator, + private readonly ExportManager $exportManager, + private $rootDir, $name = null, ) { parent::__construct($name); - $this->em = $em; - $this->configurationManager = $configurationManager; - $this->exportManager = $exportManager; - $this->translator = $translator; - $this->rootDir = $rootDir; } protected function configure() @@ -111,6 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $pages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findAll(); $this->exportManager->generatePagesData($pages); } + if (in_array('Content', $this->exportTypes)) { $contents = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findAll(); $contentsToExport = []; @@ -118,27 +89,23 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($content->getPage() instanceof PageInterface) { continue; } + $contentsToExport[] = $content; } + $this->exportManager->generateContentsData($contentsToExport); } $this->exportManager->generateFiles($this->sourceDirectory); $this->symfonyStyle->success($this->translator->trans('init.export_success', ['%dir%' => $this->sourceDirectory], 'AdvancedContentBundle')); - } catch (\Exception $e) { - $this->symfonyStyle->error($e->getMessage()); + } catch (\Exception $exception) { + $this->symfonyStyle->error($exception->getMessage()); - if (defined(sprintf('%s::FAILURE', get_class($this)))) { - return self::FAILURE; - } - - return; + return self::FAILURE; } - if (defined(sprintf('%s::SUCCESS', get_class($this)))) { - return self::SUCCESS; - } + return self::SUCCESS; } /** @@ -150,22 +117,26 @@ private function init(InputInterface $input) if (null === $initDir) { $initDir = $this->configurationManager->getInitDirectory(); } - if (0 !== strpos($initDir, '/')) { + + if (!str_starts_with((string) $initDir, '/')) { $initDir = $this->rootDir.'/'.$initDir; } + $initDir .= '/'; if (!file_exists($initDir)) { throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $initDir], 'AdvancedContentBundle')); } + $this->sourceDirectory = $initDir; $exportTypes = $input->getOption('type'); foreach ($exportTypes as $exportType) { if (!in_array($exportType, self::AVAILABLE_ENTITIES)) { - throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $exportType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); + throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $exportType, '%list%' => implode(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); } } + $this->exportTypes = $exportTypes; } } diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index cddce5d0..2aa38a7d 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -16,21 +16,6 @@ class ImportCommand extends Command { public const AVAILABLE_ENTITIES = ['Page', 'Content']; - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var string - */ - private $rootDir; - /** * @var SymfonyStyle */ @@ -41,11 +26,6 @@ class ImportCommand extends Command */ private $sourceDirectory; - /** - * @var ImportManager - */ - private $importManager; - /** * @var array */ @@ -61,17 +41,13 @@ class ImportCommand extends Command * @param string|null $name */ public function __construct( - ConfigurationManager $configurationManager, - TranslatorInterface $translator, - ImportManager $importManager, - $rootDir, + private readonly ConfigurationManager $configurationManager, + private readonly TranslatorInterface $translator, + private readonly ImportManager $importManager, + private $rootDir, $name = null, ) { parent::__construct($name); - $this->configurationManager = $configurationManager; - $this->translator = $translator; - $this->importManager = $importManager; - $this->rootDir = $rootDir; } protected function configure() @@ -125,19 +101,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->addFilesToProcess(); $this->importManager->setSymfonyStyle($this->symfonyStyle); $this->importManager->processData($this->importTypes); - } catch (\Exception $e) { - $this->symfonyStyle->error($e->getMessage()); - - if (defined(sprintf('%s::FAILURE', get_class($this)))) { - return self::FAILURE; - } + } catch (\Exception $exception) { + $this->symfonyStyle->error($exception->getMessage()); - return; + return self::FAILURE; } - if (defined(sprintf('%s::SUCCESS', get_class($this)))) { - return self::SUCCESS; - } + return self::SUCCESS; } private function addFilesToProcess() @@ -157,6 +127,7 @@ private function addFilesToProcess() } else { $finder->name(['*.yaml', '*.yml']); } + foreach ($finder as $file) { try { $this->importManager->addFileToProcess($file); @@ -175,6 +146,7 @@ private function init(InputInterface $input) if (null === $initDir) { $initDir = $this->configurationManager->getInitDirectory(); } + $initDir = $this->getDirFullPath($initDir); $this->sourceDirectory = $initDir; @@ -199,9 +171,10 @@ private function init(InputInterface $input) $importTypes = $input->getOption('type'); foreach ($importTypes as $importType) { if (!in_array($importType, self::AVAILABLE_ENTITIES)) { - throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $importType, '%list%' => join(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); + throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $importType, '%list%' => implode(', ', self::AVAILABLE_ENTITIES)], 'AdvancedContentBundle')); } } + $this->importTypes = $importTypes; $this->filename = $input->getOption('file'); @@ -216,9 +189,10 @@ private function init(InputInterface $input) */ private function getDirFullPath($dir) { - if (0 !== strpos($dir, '/')) { + if (!str_starts_with($dir, '/')) { $dir = $this->rootDir.'/'.$dir; } + $dir .= '/'; if (!file_exists($dir)) { diff --git a/Controller/ContentController.php b/Controller/ContentController.php index 0e658f04..859b7318 100644 --- a/Controller/ContentController.php +++ b/Controller/ContentController.php @@ -23,70 +23,22 @@ */ class ContentController extends AbstractController { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ContentManager - */ - private $contentManager; - - /** - * @var ElementManager - */ - private $elementManager; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var FormFactoryInterface - */ - private $formFactory; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var VersionManager - */ - private $versionManager; - - /** - * @var EventDispatcherInterface - */ - private $eventDispatcherInterface; - public function __construct( - EntityManagerInterface $em, - ContentManager $contentManager, - ElementManager $elementManager, - ConfigurationManager $configurationManager, - FormFactoryInterface $formFactory, - TranslatorInterface $translator, - VersionManager $versionManager, - EventDispatcherInterface $eventDispatcher, + private readonly EntityManagerInterface $em, + private readonly ContentManager $contentManager, + private readonly ElementManager $elementManager, + private readonly ConfigurationManager $configurationManager, + private readonly FormFactoryInterface $formFactory, + private readonly TranslatorInterface $translator, + private readonly VersionManager $versionManager, + private readonly EventDispatcherInterface $eventDispatcherInterface, ) { - $this->em = $em; - $this->contentManager = $contentManager; - $this->elementManager = $elementManager; - $this->configurationManager = $configurationManager; - $this->formFactory = $formFactory; - $this->translator = $translator; - $this->versionManager = $versionManager; - $this->eventDispatcherInterface = $eventDispatcher; } /** * @return Response */ - public function addFieldAction() + public function addField() { $fields = $this->elementManager->getGroupedFieldTypes(); @@ -101,7 +53,7 @@ public function addFieldAction() /** * @return Response */ - public function fieldFormAction(Request $request) + public function fieldForm(Request $request) { $element = $this->elementManager->getElementByCode($request->get('type')); $elementData = []; @@ -170,7 +122,7 @@ public function fieldFormAction(Request $request) /** * @return JsonResponse */ - public function saveDraftAction(Request $request) + public function saveDraft(Request $request) { $id = $request->get('id'); $content = $this->contentManager->getContentById($id); @@ -216,7 +168,7 @@ public function saveDraftAction(Request $request) /** * @return JsonResponse */ - public function deleteVersionAction(Request $request) + public function deleteVersion(Request $request) { $id = $request->get('id'); $content = $this->contentManager->getContentById($id); diff --git a/Controller/Crud/ContentController.php b/Controller/Crud/ContentController.php index 26d4e563..89259546 100644 --- a/Controller/Crud/ContentController.php +++ b/Controller/Crud/ContentController.php @@ -16,32 +16,14 @@ */ class ContentController extends AbstractController { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ContentManager - */ - private $contentManager; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - /** * ContentController constructor. */ public function __construct( - EntityManagerInterface $em, - ContentManager $contentManager, - ConfigurationManager $configurationManager, + private readonly EntityManagerInterface $em, + private readonly ContentManager $contentManager, + private readonly ConfigurationManager $configurationManager, ) { - $this->em = $em; - $this->contentManager = $contentManager; - $this->configurationManager = $configurationManager; } /** @@ -49,7 +31,7 @@ public function __construct( * * @return Response */ - public function editAction($id, Request $request) + public function edit($id, Request $request) { $content = $this->contentManager->getContentById($id); @@ -78,13 +60,14 @@ public function editAction($id, Request $request) /** * @return Response */ - public function createAction(Request $request) + public function create(Request $request) { if ($id = $request->get('duplicateId')) { $contentToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->find($id); if (!$contentToDuplicate instanceof ContentInterface) { throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('content'), $id)); } + $content = $this->contentManager->duplicate($contentToDuplicate); } else { $contentEntityClass = $this->configurationManager->getEntityClass('content'); @@ -113,7 +96,7 @@ public function createAction(Request $request) /** * @return Response */ - public function listAction() + public function list() { $contents = $this->contentManager->getContents(); @@ -127,7 +110,7 @@ public function listAction() * * @return Response */ - public function deleteAction($id) + public function delete($id) { $content = $this->contentManager->getContentById($id); @@ -146,7 +129,7 @@ public function deleteAction($id) * * @return Response */ - public function showAction($id) + public function show($id) { $content = $this->contentManager->getContentById($id); diff --git a/Controller/Crud/PageController.php b/Controller/Crud/PageController.php index 93d1f9d1..5fd0a0db 100644 --- a/Controller/Crud/PageController.php +++ b/Controller/Crud/PageController.php @@ -13,29 +13,11 @@ class PageController extends AbstractController { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var PageManager - */ - private $pageManager; - public function __construct( - EntityManagerInterface $em, - ConfigurationManager $configurationManager, - PageManager $pageManager, + private readonly EntityManagerInterface $em, + private readonly ConfigurationManager $configurationManager, + private readonly PageManager $pageManager, ) { - $this->em = $em; - $this->configurationManager = $configurationManager; - $this->pageManager = $pageManager; } /** @@ -43,7 +25,7 @@ public function __construct( * * @return Response */ - public function editAction($id, Request $request) + public function edit($id, Request $request) { $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); @@ -71,13 +53,14 @@ public function editAction($id, Request $request) /** * @return Response */ - public function createAction(Request $request) + public function create(Request $request) { if ($id = $request->get('duplicateId')) { $pageToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); if (!$pageToDuplicate instanceof PageInterface) { throw $this->createNotFoundException(sprintf('Entity %s with ID %s not found', $this->configurationManager->getEntityClass('page'), $id)); } + $page = $this->pageManager->duplicate($pageToDuplicate); } else { $pageEntityClass = $this->configurationManager->getEntityClass('page'); @@ -105,7 +88,7 @@ public function createAction(Request $request) /** * @return Response */ - public function listAction() + public function list() { $pages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findAll(); @@ -119,7 +102,7 @@ public function listAction() * * @return Response */ - public function deleteAction($id) + public function delete($id) { $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); diff --git a/Controller/Crud/ScopeController.php b/Controller/Crud/ScopeController.php index c05c2576..b6c49fa9 100644 --- a/Controller/Crud/ScopeController.php +++ b/Controller/Crud/ScopeController.php @@ -10,22 +10,10 @@ class ScopeController extends AbstractController { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - public function __construct( - EntityManagerInterface $em, - ConfigurationManager $configurationManager, + private readonly EntityManagerInterface $em, + private readonly ConfigurationManager $configurationManager, ) { - $this->em = $em; - $this->configurationManager = $configurationManager; } /** @@ -33,7 +21,7 @@ public function __construct( * * @return Response */ - public function deleteAction($id) + public function delete($id) { $scope = $this->em->getRepository($this->configurationManager->getEntityClass('scope'))->find($id); diff --git a/Controller/PageController.php b/Controller/PageController.php index df89e651..03ba3c31 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -15,49 +15,19 @@ class PageController extends AbstractController { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var PageManager - */ - private $pageManager; - - /** - * @var VersionManager - */ - private $versionManager; - - /** - * @var FormFactoryInterface - */ - private $formFactory; - public function __construct( - EntityManagerInterface $em, - ConfigurationManager $configurationManager, - PageManager $pageManager, - VersionManager $versionManager, - FormFactoryInterface $formFactory, + private readonly EntityManagerInterface $em, + private readonly ConfigurationManager $configurationManager, + private readonly PageManager $pageManager, + private readonly VersionManager $versionManager, + private readonly FormFactoryInterface $formFactory, ) { - $this->em = $em; - $this->configurationManager = $configurationManager; - $this->pageManager = $pageManager; - $this->versionManager = $versionManager; - $this->formFactory = $formFactory; } /** * @return JsonResponse */ - public function saveDraftAction(Request $request) + public function saveDraft(Request $request) { $id = $request->get('id'); $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); @@ -109,7 +79,7 @@ public function saveDraftAction(Request $request) /** * @return JsonResponse */ - public function deleteVersionAction(Request $request) + public function deleteVersion(Request $request) { $id = $request->get('id'); $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); diff --git a/Controller/ToolsController.php b/Controller/ToolsController.php index 8797b2e1..114d8044 100644 --- a/Controller/ToolsController.php +++ b/Controller/ToolsController.php @@ -20,56 +20,20 @@ class ToolsController extends AbstractController { - /** - * @var ImportManager - */ - private $importManager; - - /** - * @var ExportManager - */ - private $exportManager; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var string - */ - private $template; - /** * @param string $template */ public function __construct( - ImportManager $importManager, - ExportManager $exportManager, - TranslatorInterface $translator, - ConfigurationManager $configurationManager, - EntityManagerInterface $em, - $template, + private readonly ImportManager $importManager, + private readonly ExportManager $exportManager, + private readonly TranslatorInterface $translator, + private readonly ConfigurationManager $configurationManager, + private readonly EntityManagerInterface $em, + private $template, ) { - $this->importManager = $importManager; - $this->exportManager = $exportManager; - $this->translator = $translator; - $this->configurationManager = $configurationManager; - $this->em = $em; - $this->template = $template; } - public function indexAction(Request $request) + public function index(Request $request) { $importForm = $this->createForm(ImportType::class, null, [ 'action' => $this->generateUrl('sherlockode_acb_tools_import'), @@ -96,6 +60,7 @@ public function indexAction(Request $request) return $this->redirectToRoute('sherlockode_acb_tools_index'); } + $pageTypeForm->addError(new FormError( $this->translator->trans('page_type.errors.unique_name', [], 'AdvancedContentBundle') )); @@ -118,6 +83,7 @@ public function indexAction(Request $request) return $this->redirectToRoute('sherlockode_acb_tools_index'); } + $scopeForm->addError(new FormError( $this->translator->trans('scope.errors.unique_locale', [], 'AdvancedContentBundle') )); @@ -136,7 +102,7 @@ public function indexAction(Request $request) /** * @return Response */ - public function importAction(Request $request) + public function import(Request $request) { $form = $this->createForm(ImportType::class); @@ -152,6 +118,7 @@ public function importAction(Request $request) $this->addFlash('error', $message); } } + $this->addFlash('success', $this->translator->trans('tools.import.success', [], 'AdvancedContentBundle')); } catch (\Exception $e) { $this->addFlash('error', $e->getMessage()); @@ -164,7 +131,7 @@ public function importAction(Request $request) /** * @return Response */ - public function exportAction(Request $request) + public function export(Request $request) { $form = $this->createForm(ExportType::class); @@ -204,7 +171,7 @@ public function exportAction(Request $request) * * @return Response */ - public function deletePageTypeAction($id) + public function deletePageType($id) { $pageType = $this->em->getRepository($this->configurationManager->getEntityClass('page_type'))->find($id); diff --git a/DependencyInjection/Compiler/ElementPass.php b/DependencyInjection/Compiler/ElementPass.php index ae9fa4e7..07547f8c 100644 --- a/DependencyInjection/Compiler/ElementPass.php +++ b/DependencyInjection/Compiler/ElementPass.php @@ -13,14 +13,15 @@ public function process(ContainerBuilder $container) if (!$container->has('sherlockode_advanced_content.element_manager')) { return; } + $definition = $container->findDefinition('sherlockode_advanced_content.element_manager'); $taggedServices = $container->findTaggedServiceIds('sherlockode_advanced_content.fieldtype'); - foreach ($taggedServices as $id => $tags) { + foreach (array_keys($taggedServices) as $id) { $definition->addMethodCall('addFieldType', [new Reference($id)]); } $taggedServices = $container->findTaggedServiceIds('sherlockode_advanced_content.layouttype'); - foreach ($taggedServices as $id => $tags) { + foreach (array_keys($taggedServices) as $id) { $definition->addMethodCall('addLayoutType', [new Reference($id)]); } } diff --git a/DependencyInjection/Compiler/FormThemePass.php b/DependencyInjection/Compiler/FormThemePass.php index bbd77b8c..1d0b2863 100644 --- a/DependencyInjection/Compiler/FormThemePass.php +++ b/DependencyInjection/Compiler/FormThemePass.php @@ -18,6 +18,7 @@ public function process(ContainerBuilder $container) if (Kernel::VERSION_ID < 50300) { $theme = 'bootstrap_4_layout.html.twig'; } + $container->getDefinition('sherlockode_advanced_content.content_extension')->setArgument('$baseFormTheme', $theme); } } diff --git a/Doctrine/MigrationHelper.php b/Doctrine/MigrationHelper.php index 93aedbaf..c1a0881f 100644 --- a/Doctrine/MigrationHelper.php +++ b/Doctrine/MigrationHelper.php @@ -9,20 +9,10 @@ class MigrationHelper implements MigrationHelperInterface { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var array - */ - private $mapping; - - public function __construct(EntityManagerInterface $em, array $mapping) - { - $this->em = $em; - $this->mapping = $mapping; + public function __construct( + private readonly EntityManagerInterface $em, + private array $mapping, + ) { } /** @@ -65,7 +55,7 @@ public function readContent(string $slug): ?array $raw = $row['data'] ?? null; if ($raw) { - return json_decode($raw, true); + return json_decode((string) $raw, true); } return null; @@ -167,7 +157,7 @@ public function readPage(string $identifier): ?array $raw = $row['data'] ?? null; if ($raw) { - return json_decode($raw, true); + return json_decode((string) $raw, true); } return null; diff --git a/Event/AcbFilePreSubmitEvent.php b/Event/AcbFilePreSubmitEvent.php index 5ccf4204..b7b034f1 100644 --- a/Event/AcbFilePreSubmitEvent.php +++ b/Event/AcbFilePreSubmitEvent.php @@ -9,20 +9,10 @@ class AcbFilePreSubmitEvent extends Event { public const NAME = 'acb_file.pre_submit'; - /** - * @var UploadedFile - */ - private $uploadedFile; - - /** - * @var string - */ - private $fileName; - - public function __construct(UploadedFile $uploadedFile, string $fileName) - { - $this->uploadedFile = $uploadedFile; - $this->fileName = $fileName; + public function __construct( + private readonly UploadedFile $uploadedFile, + private readonly string $fileName, + ) { } public function getUploadedFile(): UploadedFile diff --git a/EventListener/AcbFileListener.php b/EventListener/AcbFileListener.php index 40413c77..99f330ac 100644 --- a/EventListener/AcbFileListener.php +++ b/EventListener/AcbFileListener.php @@ -14,14 +14,8 @@ class AcbFileListener implements EventSubscriberInterface */ private $files = []; - /** - * @var UploadManager - */ - private $uploadManager; - - public function __construct(UploadManager $uploadManager) + public function __construct(private readonly UploadManager $uploadManager) { - $this->uploadManager = $uploadManager; } /** diff --git a/EventListener/ContentListener.php b/EventListener/ContentListener.php index 9dc97223..379ae7ec 100644 --- a/EventListener/ContentListener.php +++ b/EventListener/ContentListener.php @@ -10,20 +10,10 @@ class ContentListener { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var VersionManager - */ - private $versionManager; - - public function __construct(ConfigurationManager $configurationManager, VersionManager $versionManager) - { - $this->configurationManager = $configurationManager; - $this->versionManager = $versionManager; + public function __construct( + private readonly ConfigurationManager $configurationManager, + private readonly VersionManager $versionManager, + ) { } public function postLoad(LifecycleEventArgs $args) @@ -33,6 +23,7 @@ public function postLoad(LifecycleEventArgs $args) if (!$entity instanceof ContentInterface) { return; } + if (null !== $entity->getPage()) { return; } @@ -56,6 +47,7 @@ public function onFlush(OnFlushEventArgs $args) if (!$entity instanceof ContentInterface) { continue; } + if (null !== $entity->getPage()) { continue; } diff --git a/EventListener/PageListener.php b/EventListener/PageListener.php index f3d25987..b1db1c91 100644 --- a/EventListener/PageListener.php +++ b/EventListener/PageListener.php @@ -12,20 +12,10 @@ class PageListener { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var VersionManager - */ - private $versionManager; - - public function __construct(ConfigurationManager $configurationManager, VersionManager $versionManager) - { - $this->configurationManager = $configurationManager; - $this->versionManager = $versionManager; + public function __construct( + private readonly ConfigurationManager $configurationManager, + private readonly VersionManager $versionManager, + ) { } public function postLoad(LifecycleEventArgs $args) @@ -94,10 +84,12 @@ public function onFlush(OnFlushEventArgs $args) $pages[$entity->getId()] = $entity; continue; } + if ($entity instanceof PageMetaInterface && null !== $entity->getPage() && $entity->getPage()->getId()) { $pages[$entity->getPage()->getId()] = $entity->getPage(); continue; } + if ($entity instanceof ContentInterface && null !== $entity->getPage() && $entity->getPage()->getId()) { $pages[$entity->getPage()->getId()] = $entity->getPage(); } @@ -115,10 +107,12 @@ public function onFlush(OnFlushEventArgs $args) $em->persist($contentVersion); $uow->computeChangeSet($contentVersionClassMetadata, $contentVersion); } + if ($pageMetaVersion = $pageVersion->getPageMetaVersion()) { $em->persist($pageMetaVersion); $uow->computeChangeSet($pageMetaVersionClassMetadata, $pageMetaVersion); } + $uow->recomputeSingleEntityChangeSet($pageClassMetadata, $page); } } diff --git a/EventListener/VersionListener.php b/EventListener/VersionListener.php index e812e28d..432636a3 100644 --- a/EventListener/VersionListener.php +++ b/EventListener/VersionListener.php @@ -30,12 +30,15 @@ public function prePersist(LifecycleEventArgs $args) if (!$version->isAutoSave()) { continue; } + if ($version->getUserId() !== $entity->getUserId()) { continue; } + if ($version->getCreatedAt() < $entity->getCreatedAt()) { ++$count; } + if ($count >= 10) { // Keep only the last 10 drafts by same user $args->getEntityManager()->remove($version); diff --git a/Export/ContentExport.php b/Export/ContentExport.php index dc9a33ee..332f93f2 100644 --- a/Export/ContentExport.php +++ b/Export/ContentExport.php @@ -6,20 +6,10 @@ class ContentExport { - /** - * @var ElementExport - */ - private $elementExport; - - /** - * @var ScopeExport - */ - private $scopeExport; - - public function __construct(ElementExport $elementExport, ScopeExport $scopeExport) - { - $this->elementExport = $elementExport; - $this->scopeExport = $scopeExport; + public function __construct( + private readonly ElementExport $elementExport, + private readonly ScopeExport $scopeExport, + ) { } /** @@ -53,7 +43,8 @@ public function exportElements($elements) if (!is_array($elements)) { return []; } - if (0 === count($elements)) { + + if ([] === $elements) { return []; } diff --git a/Export/ElementExport.php b/Export/ElementExport.php index e60216a6..98ec50a1 100644 --- a/Export/ElementExport.php +++ b/Export/ElementExport.php @@ -13,20 +13,10 @@ class ElementExport { - /** - * @var ElementManager - */ - private $elementManager; - - /** - * @var TranslatorInterface - */ - private $translator; - - public function __construct(ElementManager $elementManager, TranslatorInterface $translator) - { - $this->elementManager = $elementManager; - $this->translator = $translator; + public function __construct( + private readonly ElementManager $elementManager, + private readonly TranslatorInterface $translator, + ) { } public function getElementExportData(array $elementData): array @@ -41,7 +31,7 @@ public function getElementExportData(array $elementData): array } elseif ($element instanceof LayoutTypeInterface) { $data = $this->getLayoutTypeExportData($element, $elementData); } else { - throw new InvalidElementException(sprintf('Element of type "%s" is not handled in export', get_class($element))); + throw new InvalidElementException(sprintf('Element of type "%s" is not handled in export', $element::class)); } return array_merge([ @@ -59,6 +49,7 @@ private function getFieldTypeExportData(FieldTypeInterface $element, array $elem if (isset($raw['image']['url'])) { unset($raw['image']['url']); } + if (isset($raw['sources']) && is_array($raw['sources'])) { foreach ($raw['sources'] as $key => $source) { if (is_array($source) && isset($source['url'])) { @@ -66,6 +57,7 @@ private function getFieldTypeExportData(FieldTypeInterface $element, array $elem } } } + // Root data is only needed as template variables, no need to export them $rootDataToDelete = ['alt', 'src', 'file', 'mime_type', 'url']; foreach ($rootDataToDelete as $key) { @@ -79,10 +71,9 @@ private function getFieldTypeExportData(FieldTypeInterface $element, array $elem unset($raw['url']); } } - if ($element instanceof Content) { - if (array_key_exists('entity', $raw)) { - unset($raw['entity']); - } + + if ($element instanceof Content && array_key_exists('entity', $raw)) { + unset($raw['entity']); } return ['value' => $raw]; diff --git a/Export/PageExport.php b/Export/PageExport.php index c3bac4f9..551e077d 100644 --- a/Export/PageExport.php +++ b/Export/PageExport.php @@ -12,14 +12,8 @@ class PageExport */ private $contentExport; - /** - * @var ScopeExport - */ - private $scopeExport; - - public function __construct(ScopeExport $scopeExport) + public function __construct(private readonly ScopeExport $scopeExport) { - $this->scopeExport = $scopeExport; } /** @@ -32,6 +26,7 @@ public function exportData(PageInterface $page) if ($page->getPageType() instanceof PageTypeInterface) { $data['pageType'] = $page->getPageType()->getName(); } + $data = array_merge($data, $this->scopeExport->getEntityScopes($page)); if (null !== $page->getContent()) { $data['content'] = $this->contentExport->exportElements($page->getContent()->getData()); diff --git a/Export/ScopeExport.php b/Export/ScopeExport.php index 98d2e2d1..d5812ac3 100644 --- a/Export/ScopeExport.php +++ b/Export/ScopeExport.php @@ -8,22 +8,10 @@ class ScopeExport { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - public function __construct( - ConfigurationManager $configurationManager, - ScopeHandlerInterface $scopeHandler, + private readonly ConfigurationManager $configurationManager, + private readonly ScopeHandlerInterface $scopeHandler, ) { - $this->configurationManager = $configurationManager; - $this->scopeHandler = $scopeHandler; } public function getEntityScopes(ScopableInterface $entity): array diff --git a/FieldType/AbstractFieldType.php b/FieldType/AbstractFieldType.php index 713c1288..f853fa7f 100644 --- a/FieldType/AbstractFieldType.php +++ b/FieldType/AbstractFieldType.php @@ -26,6 +26,7 @@ public function getFormFieldLabel() return 'field_type.'.$this->getCode().'.label'; } + #[\Override] public function getIconClass() { return $this->configData['icon'] ?? $this->getDefaultIconClass(); @@ -60,6 +61,7 @@ public function getPreviewPicture() * * @return void */ + #[\Override] public function buildContentElement(FormBuilderInterface $builder) { parent::buildContentElement($builder); @@ -136,11 +138,7 @@ public function getFieldGroup() public function getRawData($element) { $rawValue = $this->getRawValue($element['value'] ?? null); - if (is_array($rawValue)) { - $rowData = $rawValue; - } else { - $rowData = ['value' => $rawValue]; - } + $rowData = is_array($rawValue) ? $rawValue : ['value' => $rawValue]; return array_merge($rowData, [ 'extra' => $element['extra'] ?? [], diff --git a/FieldType/AbstractInputType.php b/FieldType/AbstractInputType.php index 7ded993f..e3389ab9 100644 --- a/FieldType/AbstractInputType.php +++ b/FieldType/AbstractInputType.php @@ -6,6 +6,7 @@ abstract class AbstractInputType extends AbstractFieldType { + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-font'; @@ -16,16 +17,18 @@ protected function getDefaultIconClass() * * @return array */ + #[\Override] public function getFormElementOptions() { $fieldOptions = []; $formFieldOptions = []; if (isset($fieldOptions['minLength'])) { - $formFieldOptions['constraints'][] = new Length(['min' => $fieldOptions['minLength']]); + $formFieldOptions['constraints'][] = new Length(min: $fieldOptions['minLength']); } + if (isset($fieldOptions['maxLength'])) { - $formFieldOptions['constraints'][] = new Length(['max' => $fieldOptions['maxLength']]); + $formFieldOptions['constraints'][] = new Length(max: $fieldOptions['maxLength']); } return $formFieldOptions; @@ -34,6 +37,7 @@ public function getFormElementOptions() /** * @return string */ + #[\Override] public function getFieldGroup() { return 'simple'; diff --git a/FieldType/Content.php b/FieldType/Content.php index a8b5e31a..b00a5531 100644 --- a/FieldType/Content.php +++ b/FieldType/Content.php @@ -7,15 +7,8 @@ class Content extends AbstractFieldType { - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - - public function __construct( - ScopeHandlerInterface $scopeHandler, - ) { - $this->scopeHandler = $scopeHandler; + public function __construct(private readonly ScopeHandlerInterface $scopeHandler) + { } /** @@ -44,6 +37,7 @@ public function getPreviewPicture(): ?string /** * @return array */ + #[\Override] public function getRawValue($element) { $element['entity'] = null; diff --git a/FieldType/File.php b/FieldType/File.php index b0d8d132..e673d856 100644 --- a/FieldType/File.php +++ b/FieldType/File.php @@ -7,14 +7,8 @@ class File extends AbstractFieldType { - /** - * @var UrlBuilderManager - */ - private $urlBuilderManager; - - public function __construct(UrlBuilderManager $urlBuilderManager) + public function __construct(private readonly UrlBuilderManager $urlBuilderManager) { - $this->urlBuilderManager = $urlBuilderManager; } /** @@ -25,6 +19,7 @@ public function getFormFieldType() return AcbFileType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-paperclip'; @@ -55,6 +50,7 @@ protected function getFilename($value) return $this->urlBuilderManager->getFileUrl($value['src'] ?? ''); } + #[\Override] public function getRawValue($element) { $element['url'] = $this->getFilename($element); diff --git a/FieldType/Iframe.php b/FieldType/Iframe.php index 53e5a0c9..f44a84c0 100644 --- a/FieldType/Iframe.php +++ b/FieldType/Iframe.php @@ -22,6 +22,7 @@ public function getFormFieldType() * * @return void */ + #[\Override] public function buildContentElement(FormBuilderInterface $builder) { parent::buildContentElement($builder); diff --git a/FieldType/Image.php b/FieldType/Image.php index 81047dc1..28bb94ef 100644 --- a/FieldType/Image.php +++ b/FieldType/Image.php @@ -9,16 +9,19 @@ class Image extends File /** * @return string */ + #[\Override] public function getFormFieldType() { return PictureType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-image'; } + #[\Override] public function getPreviewPicture(): ?string { return 'bundles/sherlockodeadvancedcontent/preview_picture/image.svg'; @@ -29,11 +32,13 @@ public function getPreviewPicture(): ?string * * @return string */ + #[\Override] public function getCode() { return 'image'; } + #[\Override] public function getRawValue($element) { $element['image'] = parent::getRawValue($element['image'] ?? []); diff --git a/FieldType/ImageCarousel.php b/FieldType/ImageCarousel.php index ef7d4e67..5a182af7 100644 --- a/FieldType/ImageCarousel.php +++ b/FieldType/ImageCarousel.php @@ -9,11 +9,13 @@ class ImageCarousel extends File /** * @return string */ + #[\Override] public function getFormFieldType() { return ImageCarouselType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-images'; @@ -24,16 +26,19 @@ protected function getDefaultIconClass() * * @return string */ + #[\Override] public function getCode() { return 'image_carousel'; } + #[\Override] public function getPreviewPicture(): ?string { return 'bundles/sherlockodeadvancedcontent/preview_picture/image_carousel.svg'; } + #[\Override] public function getRawValue($element) { $images = $element['images'] ?? []; @@ -48,6 +53,7 @@ public function getRawValue($element) if (isset($imageData['delete'])) { unset($imageData['delete']); } + $element['images'][$key] = $imageData; } diff --git a/FieldType/Link.php b/FieldType/Link.php index 825cf7df..9c708f5e 100644 --- a/FieldType/Link.php +++ b/FieldType/Link.php @@ -15,16 +15,19 @@ public function getFormFieldType() return LinkType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-link'; } + #[\Override] public function getFrontTemplate() { return '@SherlockodeAdvancedContent/Field/front/link.html.twig'; } + #[\Override] public function getFormElementOptions() { return [ @@ -55,6 +58,7 @@ public function getPreviewPicture(): ?string return 'bundles/sherlockodeadvancedcontent/preview_picture/link.svg'; } + #[\Override] public function getRawValue($element) { $url = $this->getUrlValue($element); diff --git a/FieldType/RelativeLink.php b/FieldType/RelativeLink.php index e8d3da56..16b00798 100644 --- a/FieldType/RelativeLink.php +++ b/FieldType/RelativeLink.php @@ -7,16 +7,11 @@ class RelativeLink extends Link { - /** - * @var UrlBuilderManager - */ - private $urlBuilderManager; - - public function __construct(UrlBuilderManager $urlBuilderManager) + public function __construct(private readonly UrlBuilderManager $urlBuilderManager) { - $this->urlBuilderManager = $urlBuilderManager; } + #[\Override] public function getPreviewTemplate() { return '@SherlockodeAdvancedContent/Field/preview/link.html.twig'; @@ -27,11 +22,13 @@ public function getPreviewTemplate() * * @return string */ + #[\Override] public function getCode() { return 'relative_link'; } + #[\Override] public function getPreviewPicture(): ?string { return 'bundles/sherlockodeadvancedcontent/preview_picture/relative_link.svg'; @@ -40,6 +37,7 @@ public function getPreviewPicture(): ?string /** * @return string */ + #[\Override] protected function getUrlFormType() { return TextType::class; @@ -50,6 +48,7 @@ protected function getUrlFormType() * * @return string */ + #[\Override] protected function getUrlValue($value) { return $this->urlBuilderManager->getFullUrl($value['url'] ?? ''); diff --git a/FieldType/Separator.php b/FieldType/Separator.php index 21d1e0d0..ec187dfc 100644 --- a/FieldType/Separator.php +++ b/FieldType/Separator.php @@ -14,6 +14,7 @@ public function getFormFieldType() return FormType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-minus'; diff --git a/FieldType/TextArea.php b/FieldType/TextArea.php index fb271711..b90dd7e7 100644 --- a/FieldType/TextArea.php +++ b/FieldType/TextArea.php @@ -11,6 +11,7 @@ class TextArea extends AbstractInputType * * @return array */ + #[\Override] public function getFormElementOptions() { $fieldOptions = []; diff --git a/FieldType/Title.php b/FieldType/Title.php index dabccfae..dc4deb46 100644 --- a/FieldType/Title.php +++ b/FieldType/Title.php @@ -14,6 +14,7 @@ public function getFormFieldType() return TitleType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-heading'; diff --git a/FieldType/Video.php b/FieldType/Video.php index 3d27eee5..7fef8313 100644 --- a/FieldType/Video.php +++ b/FieldType/Video.php @@ -14,6 +14,7 @@ public function getFormFieldType() return VideoType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-video'; diff --git a/FieldType/Wysiwyg.php b/FieldType/Wysiwyg.php index 468619e0..d5c23ed4 100644 --- a/FieldType/Wysiwyg.php +++ b/FieldType/Wysiwyg.php @@ -14,6 +14,7 @@ public function getFormFieldType() return WysiwygType::class; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-text-height'; diff --git a/Form/DataTransformer/StringToEntity.php b/Form/DataTransformer/StringToEntity.php index 28a5b416..cba8a62f 100644 --- a/Form/DataTransformer/StringToEntity.php +++ b/Form/DataTransformer/StringToEntity.php @@ -8,30 +8,15 @@ class StringToEntity implements DataTransformerInterface { - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var string - */ - private $entityClass; - - /** - * @var string - */ - private $identifierField; - /** * @param string $entityClass * @param string $identifierField */ - public function __construct(EntityManagerInterface $em, $entityClass, $identifierField) - { - $this->em = $em; - $this->entityClass = $entityClass; - $this->identifierField = $identifierField; + public function __construct( + private readonly EntityManagerInterface $em, + private $entityClass, + private $identifierField, + ) { } /** diff --git a/Form/Type/AcbContentType.php b/Form/Type/AcbContentType.php index e46c79c3..b48042db 100644 --- a/Form/Type/AcbContentType.php +++ b/Form/Type/AcbContentType.php @@ -10,20 +10,10 @@ class AcbContentType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var EntityManagerInterface - */ - private $em; - - public function __construct(ConfigurationManager $configurationManager, EntityManagerInterface $em) - { - $this->configurationManager = $configurationManager; - $this->em = $em; + public function __construct( + private readonly ConfigurationManager $configurationManager, + private readonly EntityManagerInterface $em, + ) { } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php index 516bff2b..a54b5cfc 100644 --- a/Form/Type/AcbFileType.php +++ b/Form/Type/AcbFileType.php @@ -23,26 +23,11 @@ class AcbFileType extends AbstractType { - /** - * @var UploadManager - */ - private $uploadManager; - - /** - * @var EventDispatcherInterface - */ - private $eventDispatcher; - - /** - * @var MimeTypeManager - */ - private $mimeTypeManager; - - public function __construct(UploadManager $uploadManager, EventDispatcherInterface $eventDispatcher, MimeTypeManager $mimeTypeManager) - { - $this->uploadManager = $uploadManager; - $this->eventDispatcher = $eventDispatcher; - $this->mimeTypeManager = $mimeTypeManager; + public function __construct( + private readonly UploadManager $uploadManager, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly MimeTypeManager $mimeTypeManager, + ) { } public function buildForm(FormBuilderInterface $builder, array $options) @@ -52,17 +37,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder ->add('title', TextType::class, [ 'label' => 'field_type.file.title', - 'constraints' => !$options['required'] ? [] : [ + 'constraints' => $options['required'] ? [ new NotBlank(null, null, null, null, $options['validation_groups']), - ], + ] : [], ]) ->add('mime_type', ChoiceType::class, [ 'label' => 'field_type.file.restriction_type', 'multiple' => true, 'choices' => is_array($mimeTypeChoices) ? $mimeTypeChoices : [], - 'choice_attr' => function ($choice): array { - return ['data-mime-type' => json_encode($this->mimeTypeManager->getMimeTypesByCode($choice))]; - }, + 'choice_attr' => fn ($choice): array => ['data-mime-type' => json_encode($this->mimeTypeManager->getMimeTypesByCode($choice))], 'attr' => ['data-mime-type-restriction' => ''], ]) ; @@ -91,6 +74,7 @@ function (FormEvent $event) use ($options) { $this->uploadManager->remove($data['src']); unset($data['src']); } + unset($data['delete']); } @@ -164,6 +148,7 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal $mimeTypes = array_merge([], ...$mimeTypes); } + $options['file_constraints'][] = new File(null, null, null, $mimeTypes); $form @@ -219,6 +204,7 @@ public function buildView(FormView $view, FormInterface $form, array $options) /** * @return string */ + #[\Override] public function getBlockPrefix() { return 'acb_file'; diff --git a/Form/Type/ColumnType.php b/Form/Type/ColumnType.php index ef29888d..b6e48391 100644 --- a/Form/Type/ColumnType.php +++ b/Form/Type/ColumnType.php @@ -105,6 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } + #[\Override] public function getBlockPrefix() { return 'acb_column_config'; diff --git a/Form/Type/ContentDataType.php b/Form/Type/ContentDataType.php index ac45a4f9..47fa5c47 100644 --- a/Form/Type/ContentDataType.php +++ b/Form/Type/ContentDataType.php @@ -6,11 +6,13 @@ class ContentDataType extends AbstractType { + #[\Override] public function getParent() { return ElementsType::class; } + #[\Override] public function getBlockPrefix() { return 'acb_content_data'; diff --git a/Form/Type/ContentType.php b/Form/Type/ContentType.php index 4fb5b909..6fd1bf07 100644 --- a/Form/Type/ContentType.php +++ b/Form/Type/ContentType.php @@ -20,36 +20,12 @@ class ContentType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var UrlGeneratorInterface - */ - private $urlGenerator; - - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - - /** - * @var TranslatorInterface - */ - private $translator; - public function __construct( - ConfigurationManager $configurationManager, - UrlGeneratorInterface $urlGenerator, - ScopeHandlerInterface $scopeHandler, - TranslatorInterface $translator, + private readonly ConfigurationManager $configurationManager, + private readonly UrlGeneratorInterface $urlGenerator, + private readonly ScopeHandlerInterface $scopeHandler, + private readonly TranslatorInterface $translator, ) { - $this->configurationManager = $configurationManager; - $this->urlGenerator = $urlGenerator; - $this->scopeHandler = $scopeHandler; - $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -96,6 +72,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (null !== $content && $content->getId()) { $slugClass = ''; } + $form ->add('slug', TextType::class, [ 'label' => 'content.form.slug', @@ -105,7 +82,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ], ]) ; - if ($form->getParent()) { + if (null !== $form->getParent()) { $form->remove('name'); $form->remove('slug'); if ($form->has('scopes')) { @@ -133,7 +110,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { - $event->setData(json_decode($event->getData(), true)); + $event->setData(json_decode((string) $event->getData(), true)); }, 1); $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { diff --git a/Form/Type/ElementHideOnType.php b/Form/Type/ElementHideOnType.php index 40967286..0b472b8e 100644 --- a/Form/Type/ElementHideOnType.php +++ b/Form/Type/ElementHideOnType.php @@ -11,6 +11,7 @@ class ElementHideOnType extends AbstractType /** * @return string */ + #[\Override] public function getParent() { return ChoiceType::class; diff --git a/Form/Type/ElementType.php b/Form/Type/ElementType.php index b7d1b448..3f19c6de 100644 --- a/Form/Type/ElementType.php +++ b/Form/Type/ElementType.php @@ -39,6 +39,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getBlockPrefix() { return 'acb_element'; diff --git a/Form/Type/ElementsType.php b/Form/Type/ElementsType.php index 13dc1bba..54acc788 100644 --- a/Form/Type/ElementsType.php +++ b/Form/Type/ElementsType.php @@ -14,29 +14,11 @@ class ElementsType extends AbstractType { - /** - * @var ElementManager - */ - private $elementManager; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var TranslatorInterface - */ - private $translator; - public function __construct( - ElementManager $elementManager, - ConfigurationManager $configurationManager, - TranslatorInterface $translator, + private readonly ElementManager $elementManager, + private readonly ConfigurationManager $configurationManager, + private readonly TranslatorInterface $translator, ) { - $this->elementManager = $elementManager; - $this->configurationManager = $configurationManager; - $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -72,6 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) foreach ($form as $child) { $form->remove($child->getName()); } + $form->setData([]); foreach ($data as $name => $element) { @@ -89,7 +72,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $data = $event->getData(); $data = array_values($data); - if ($parentForm = $form->getParent()) { + if (($parentForm = $form->getParent()) !== null) { $parentElementType = $parentForm->has('elementType') ? $parentForm->get('elementType')->getData() : 'root'; foreach ($data as $child) { if ('root' === $parentElementType && 'row' !== $child['elementType']) { @@ -99,6 +82,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'AdvancedContentBundle' ))); } + if ('row' === $parentElementType && 'column' !== $child['elementType']) { $form->addError(new FormError($this->translator->trans( 'layout_type.errors.invalid_element_in_row', @@ -106,6 +90,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'AdvancedContentBundle' ))); } + if ('column' === $parentElementType && ('column' === $child['elementType'] || 'row' === $child['elementType']) ) { @@ -130,6 +115,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getBlockPrefix() { return 'acb_elements'; diff --git a/Form/Type/EntityType.php b/Form/Type/EntityType.php index 3e1b08bb..2ff1f00b 100644 --- a/Form/Type/EntityType.php +++ b/Form/Type/EntityType.php @@ -14,11 +14,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addModelTransformer(new StringToEntity($options['em'], $options['class'], 'id')); } + #[\Override] public function getParent() { return SymfonyEntityType::class; } + #[\Override] public function getBlockPrefix() { return 'acb_entity'; diff --git a/Form/Type/ExportType.php b/Form/Type/ExportType.php index f19c169e..2330dc1e 100644 --- a/Form/Type/ExportType.php +++ b/Form/Type/ExportType.php @@ -13,14 +13,8 @@ class ExportType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct(ConfigurationManager $configurationManager) + public function __construct(private readonly ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -29,9 +23,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('page', EntityType::class, [ 'label' => 'tools.export.page', 'class' => $this->configurationManager->getEntityClass('page'), - 'choice_label' => function (PageInterface $page) { - return $page->getPageMeta()->getTitle(); - }, + 'choice_label' => fn (PageInterface $page) => $page->getPageMeta()->getTitle(), 'expanded' => true, 'multiple' => true, 'attr' => ['class' => 'acb-export-entity'], @@ -50,11 +42,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'multiple' => true, 'attr' => ['class' => 'acb-export-entity'], 'required' => false, - 'query_builder' => function (EntityRepository $er) { - return $er->createQueryBuilder('c') - ->leftJoin('c.page', 'p') - ->where('p.id IS NULL'); - }, + 'query_builder' => fn (EntityRepository $er) => $er->createQueryBuilder('c') + ->leftJoin('c.page', 'p') + ->where('p.id IS NULL'), ]) ->add('contentAll', CheckboxType::class, [ 'label' => 'tools.export.all', diff --git a/Form/Type/ImageType.php b/Form/Type/ImageType.php index da11f53a..9c1f45bb 100644 --- a/Form/Type/ImageType.php +++ b/Form/Type/ImageType.php @@ -10,11 +10,8 @@ class ImageType extends AbstractType { - private MimeTypeManager $mimeTypeManager; - - public function __construct(MimeTypeManager $mimeTypeManager) + public function __construct(private readonly MimeTypeManager $mimeTypeManager) { - $this->mimeTypeManager = $mimeTypeManager; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -31,6 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * @return string */ + #[\Override] public function getParent() { return AcbFileType::class; @@ -39,6 +37,7 @@ public function getParent() /** * @return string */ + #[\Override] public function getBlockPrefix() { return 'acb_image'; @@ -48,7 +47,7 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', - 'mime_types' => array_flip(array_map('ucfirst', $this->mimeTypeManager->getImageMimeTypesChoices())), + 'mime_types' => array_flip(array_map(ucfirst(...), $this->mimeTypeManager->getImageMimeTypesChoices())), 'mime_types_constraint' => $this->mimeTypeManager->getMimeTypesByCode(MimeTypeManager::MIME_TYPE_IMAGE), ]); } diff --git a/Form/Type/PageMetaType.php b/Form/Type/PageMetaType.php index de91a9f7..6c417132 100644 --- a/Form/Type/PageMetaType.php +++ b/Form/Type/PageMetaType.php @@ -14,14 +14,8 @@ class PageMetaType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct(ConfigurationManager $configurationManager) + public function __construct(private readonly ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -71,6 +65,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (null !== $pageMeta && $pageMeta->getId()) { $slugClass = ''; } + $form ->add('slug', TextType::class, [ 'label' => 'page.form.slug', diff --git a/Form/Type/PageType.php b/Form/Type/PageType.php index dffd0bd5..17635766 100644 --- a/Form/Type/PageType.php +++ b/Form/Type/PageType.php @@ -19,29 +19,11 @@ class PageType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - - /** - * @var TranslatorInterface - */ - private $translator; - public function __construct( - ConfigurationManager $configurationManager, - ScopeHandlerInterface $scopeHandler, - TranslatorInterface $translator, + private readonly ConfigurationManager $configurationManager, + private readonly ScopeHandlerInterface $scopeHandler, + private readonly TranslatorInterface $translator, ) { - $this->configurationManager = $configurationManager; - $this->scopeHandler = $scopeHandler; - $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -103,6 +85,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $content = new ($this->configurationManager->getEntityClass('content')); $page->setContent($content); } + if (!$content->getId()) { $content->setName('page-'.$page->getPageIdentifier().'-'.bin2hex(random_bytes(6))); $content->setSlug($page->getPageMeta()->getSlug().'-'.bin2hex(random_bytes(6))); @@ -120,6 +103,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) )); } } + if (!$this->scopeHandler->isPageIdentifierValid($page)) { if ($this->configurationManager->isScopesEnabled()) { $form->get('pageIdentifier')->addError(new FormError( @@ -150,6 +134,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getBlockPrefix() { return 'acb_page'; diff --git a/Form/Type/PageTypeType.php b/Form/Type/PageTypeType.php index 30671683..00699702 100644 --- a/Form/Type/PageTypeType.php +++ b/Form/Type/PageTypeType.php @@ -11,14 +11,8 @@ class PageTypeType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct(ConfigurationManager $configurationManager) + public function __construct(private readonly ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/Form/Type/PictureEntryType.php b/Form/Type/PictureEntryType.php index 6f93d7ac..6d4b6051 100644 --- a/Form/Type/PictureEntryType.php +++ b/Form/Type/PictureEntryType.php @@ -32,6 +32,7 @@ function (FormEvent $event) { // Remove mime type data to prevent form extra fields error unset($data['mime_type']); } + $event->setData($data); }, 1 @@ -41,6 +42,7 @@ function (FormEvent $event) { /** * @return string */ + #[\Override] public function getParent() { return ImageType::class; diff --git a/Form/Type/PictureType.php b/Form/Type/PictureType.php index 2f92259c..bfb4705d 100644 --- a/Form/Type/PictureType.php +++ b/Form/Type/PictureType.php @@ -36,7 +36,7 @@ function (FormEvent $event) { $data = $event->getData(); $globalMimeTypes = $data['image']['mime_type'] ?? []; if (isset($data['sources']) && is_array($data['sources'])) { - foreach ($data['sources'] as $key => $source) { + foreach (array_keys($data['sources']) as $key) { $data['sources'][$key]['mime_type'] = $globalMimeTypes; } } diff --git a/Form/Type/RepeaterType.php b/Form/Type/RepeaterType.php index 820dfd84..700e58f6 100644 --- a/Form/Type/RepeaterType.php +++ b/Form/Type/RepeaterType.php @@ -45,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }, ARRAY_FILTER_USE_BOTH); $prototypeOptions = array_merge($prototypeOptions, [ 'child_options' => $prototype->getConfig()->getOptions(), - 'child_form' => get_class($prototype->getConfig()->getType()->getInnerType()), + 'child_form' => $prototype->getConfig()->getType()->getInnerType()::class, 'compound' => true, ]); @@ -64,7 +64,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } else { $form->add($i, RepeatedChildWrappedType::class, [ 'child_options' => $child->getConfig()->getOptions(), - 'child_form' => get_class($child->getConfig()->getType()->getInnerType()), + 'child_form' => $child->getConfig()->getType()->getInnerType()::class, 'position' => $i, ]); } @@ -83,14 +83,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!is_array($item)) { return; } + if (!isset($item['position'])) { $item['position'] = 0; } + $orderedData[] = $item; } - usort($orderedData, function ($a, $b) { - return $a['position'] <=> $b['position']; - }); + + usort($orderedData, fn ($a, $b) => $a['position'] <=> $b['position']); // unset the position key in the saved data $orderedData = array_map(function ($item) { @@ -108,6 +109,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } + #[\Override] public function getParent() { return CollectionType::class; @@ -124,6 +126,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getBlockPrefix() { return 'acb_field_collection'; diff --git a/Form/Type/ScopeChoiceType.php b/Form/Type/ScopeChoiceType.php index b1b49c53..e13da92d 100644 --- a/Form/Type/ScopeChoiceType.php +++ b/Form/Type/ScopeChoiceType.php @@ -10,22 +10,10 @@ class ScopeChoiceType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - public function __construct( - ConfigurationManager $configurationManager, - ScopeHandlerInterface $scopeHandler, + private readonly ConfigurationManager $configurationManager, + private readonly ScopeHandlerInterface $scopeHandler, ) { - $this->configurationManager = $configurationManager; - $this->scopeHandler = $scopeHandler; } public function configureOptions(OptionsResolver $resolver) @@ -41,6 +29,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getParent(): ?string { return EntityType::class; diff --git a/Form/Type/ScopeType.php b/Form/Type/ScopeType.php index f5adf7f6..2165e359 100644 --- a/Form/Type/ScopeType.php +++ b/Form/Type/ScopeType.php @@ -11,14 +11,8 @@ class ScopeType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct(ConfigurationManager $configurationManager) + public function __construct(private readonly ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; } public function buildForm(FormBuilderInterface $builder, array $options) diff --git a/Form/Type/WysiwygType.php b/Form/Type/WysiwygType.php index 6dbe6b8e..e6598cf3 100644 --- a/Form/Type/WysiwygType.php +++ b/Form/Type/WysiwygType.php @@ -9,14 +9,8 @@ class WysiwygType extends AbstractType { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct(ConfigurationManager $configurationManager) + public function __construct(private readonly ConfigurationManager $configurationManager) { - $this->configurationManager = $configurationManager; } public function configureOptions(OptionsResolver $resolver) @@ -27,6 +21,7 @@ public function configureOptions(OptionsResolver $resolver) ]); } + #[\Override] public function getParent() { return CKEditorType::class; diff --git a/Import/AbstractImport.php b/Import/AbstractImport.php index 67357d7c..723e1e1c 100644 --- a/Import/AbstractImport.php +++ b/Import/AbstractImport.php @@ -101,13 +101,14 @@ public function importData($slug, $data) foreach ($this->errors as $error) { $result->addMessage($error); } + if (count($this->errors) > 0) { $result->failure(); } - } catch (\Exception $e) { + } catch (\Exception $exception) { $result ->failure() - ->addMessage($e->getMessage()) + ->addMessage($exception->getMessage()) ; } @@ -138,7 +139,7 @@ public function getErrors() protected function getScopesForEntity(array $scopesData): array { if (!$this->configurationManager->isScopesEnabled()) { - if (count($scopesData) > 0) { + if ([] !== $scopesData) { throw new \Exception($this->translator->trans('init.errors.scopes_disabled', [], 'AdvancedContentBundle')); } @@ -151,6 +152,7 @@ protected function getScopesForEntity(array $scopesData): array if (null === $scope) { throw new \Exception($this->translator->trans('init.errors.unknown_scope', ['%scope%' => json_encode($scopeData)], 'AdvancedContentBundle')); } + $scopes[] = $scope; } @@ -166,24 +168,24 @@ protected function getExistingScopableEntity(string $entityClass, array $criteri if (0 === count($existingEntities)) { return null; } + if (1 === count($existingEntities)) { return reset($existingEntities); } $entity = null; foreach ($existingEntities as $existingEntity) { - $result = array_uintersect($scopes, $existingEntity->getScopes()->toArray(), function ($a, $b) { - return $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier(); - }); + $result = array_uintersect($scopes, $existingEntity->getScopes()->toArray(), fn ($a, $b) => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); if (count($result) === count($scopes)) { return $existingEntity; } - if (count($result) > 0) { + if ([] !== $result) { if (null !== $entity) { throw new \Exception($this->translator->trans('init.errors.multiple_entities_same_scope', [], 'AdvancedContentBundle')); } + $entity = $existingEntity; } } @@ -203,8 +205,10 @@ protected function updateEntityScopes(ScopableInterface $entity, array $scopes): continue 2; } } + $entity->removeScope($existingScope); } + foreach ($scopes as $scope) { $entity->addScope($scope); } diff --git a/Import/ContentImport.php b/Import/ContentImport.php index a8f825dd..a8fc081b 100644 --- a/Import/ContentImport.php +++ b/Import/ContentImport.php @@ -10,21 +10,14 @@ class ContentImport extends AbstractImport { - /** - * @var ElementImport - */ - private $elementImport; - public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, TranslatorInterface $translator, ScopeHandlerInterface $scopeHandler, - ElementImport $elementImport, + private readonly ElementImport $elementImport, ) { parent::__construct($em, $configurationManager, $translator, $scopeHandler); - - $this->elementImport = $elementImport; } /** @@ -42,8 +35,8 @@ protected function importEntity($slug, $contentData) try { $scopes = $this->getScopesForEntity($contentData['scopes'] ?? []); $content = $this->getExistingScopableEntity($this->entityClasses['content'], ['slug' => $slug], $scopes); - } catch (\Exception $e) { - $this->errors[] = $e->getMessage(); + } catch (\Exception $exception) { + $this->errors[] = $exception->getMessage(); return; } @@ -87,6 +80,7 @@ public function createElements(array $elementsData, ContentInterface $content) $this->errors[] = sprintf('%s : %s', $content->getName(), $e->getMessage()); } } + $content->setData($elements); } diff --git a/Import/ElementImport.php b/Import/ElementImport.php index 74e26404..2b79613e 100644 --- a/Import/ElementImport.php +++ b/Import/ElementImport.php @@ -14,36 +14,6 @@ class ElementImport { - /** - * @var ElementManager - */ - private $elementManager; - - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var TranslatorInterface - */ - private $translator; - - /** - * @var UploadManager - */ - private $uploadManager; - - /** - * @var string - */ - private $rootDir; - /** * @var string */ @@ -53,19 +23,13 @@ class ElementImport * @param string $rootDir */ public function __construct( - ElementManager $elementManager, - EntityManagerInterface $em, - ConfigurationManager $configurationManager, - TranslatorInterface $translator, - UploadManager $uploadManager, - $rootDir, + private readonly ElementManager $elementManager, + private readonly EntityManagerInterface $em, + private readonly ConfigurationManager $configurationManager, + private readonly TranslatorInterface $translator, + private readonly UploadManager $uploadManager, + private $rootDir, ) { - $this->elementManager = $elementManager; - $this->em = $em; - $this->configurationManager = $configurationManager; - $this->translator = $translator; - $this->uploadManager = $uploadManager; - $this->rootDir = $rootDir; } public function getElementImportData(array $elementData, int $position = 0) @@ -80,7 +44,7 @@ public function getElementImportData(array $elementData, int $position = 0) } elseif ($element instanceof LayoutTypeInterface) { $data = $this->getLayoutTypeImportData($element, $elementData); } else { - throw new InvalidElementException(sprintf('Element of type "%s" is not handled in import', get_class($element))); + throw new InvalidElementException(sprintf('Element of type "%s" is not handled in import', $element::class)); } return array_merge([ @@ -96,6 +60,7 @@ private function getFieldTypeImportData(FieldTypeInterface $element, array $elem if (null !== $element->getValueModelTransformer()) { $value = []; } + if (isset($elementData['value'])) { $value = $elementData['value']; if (is_array($value)) { @@ -130,6 +95,7 @@ private function processValueArray(array $data) $data = $result; } } + if (isset($data['content'])) { $slug = $data['content']; $content = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findOneBy([ @@ -143,11 +109,7 @@ private function processValueArray(array $data) // browse array $newData = []; foreach ($data as $key => $valueEntry) { - if (is_array($valueEntry)) { - $newData[$key] = $this->processValueArray($valueEntry); - } else { - $newData[$key] = $valueEntry; - } + $newData[$key] = is_array($valueEntry) ? $this->processValueArray($valueEntry) : $valueEntry; } return $newData; @@ -177,12 +139,14 @@ private function getFilesDirectory() { if (null === $this->filesDirectory) { $filesDirectory = $this->configurationManager->getInitFilesDirectory(); - if (0 !== strpos($filesDirectory, '/')) { + if (!str_starts_with($filesDirectory, '/')) { $filesDirectory = $this->rootDir.'/'.$filesDirectory; } + if (!file_exists($filesDirectory)) { throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $filesDirectory], 'AdvancedContentBundle')); } + $this->filesDirectory = $filesDirectory.'/'; } diff --git a/Import/ImportResult.php b/Import/ImportResult.php index bf065c60..5a0a9f68 100644 --- a/Import/ImportResult.php +++ b/Import/ImportResult.php @@ -5,24 +5,21 @@ class ImportResult { public const FAILURE = 0; + public const SUCCESS = 1; + public const UNKNOWN = 2; /** * @var int */ - private $status; + private $status = self::UNKNOWN; /** * @var array */ private $messages = []; - public function __construct() - { - $this->status = self::UNKNOWN; - } - /** * @return int */ diff --git a/Import/PageImport.php b/Import/PageImport.php index f63cf2d0..303b6b12 100644 --- a/Import/PageImport.php +++ b/Import/PageImport.php @@ -29,8 +29,8 @@ protected function importEntity($pageIdentifier, $pageData) try { $scopes = $this->getScopesForEntity($pageData['scopes'] ?? []); $page = $this->getExistingScopableEntity($this->entityClasses['page'], ['pageIdentifier' => $pageIdentifier], $scopes); - } catch (\Exception $e) { - $this->errors[] = $e->getMessage(); + } catch (\Exception $exception) { + $this->errors[] = $exception->getMessage(); return; } @@ -61,6 +61,7 @@ protected function importEntity($pageIdentifier, $pageData) if (count($pageTypes) > 0) { $pageType = $pageTypes[0]; } + if (!$pageType instanceof PageTypeInterface) { /** @var PageTypeInterface $pageType */ $pageType = new $this->entityClasses['page_type'](); @@ -68,6 +69,7 @@ protected function importEntity($pageIdentifier, $pageData) $this->em->persist($pageType); } } + $page->setPageType($pageType); if (!empty($pageData['content'])) { @@ -106,6 +108,7 @@ protected function importEntity($pageIdentifier, $pageData) $pageMeta = new $this->entityClasses['page_meta'](); $page->setPageMeta($pageMeta); } + $pageMeta->setTitle($title); $pageMeta->setSlug($slug); $pageMeta->setMetaTitle($metaData['meta_title'] ?? null); @@ -120,6 +123,7 @@ protected function importEntity($pageIdentifier, $pageData) return; } + if (!$this->scopeHandler->isPageSlugValid($page)) { if ($this->configurationManager->isScopesEnabled()) { $this->errors[] = $this->translator->trans('page.errors.duplicate_slug_scopes', [], 'AdvancedContentBundle'); diff --git a/LayoutType/AbstractLayoutType.php b/LayoutType/AbstractLayoutType.php index 795a96e8..e2f5bdc8 100644 --- a/LayoutType/AbstractLayoutType.php +++ b/LayoutType/AbstractLayoutType.php @@ -37,6 +37,7 @@ public function getPreviewTemplate() * * @return void */ + #[\Override] public function buildContentElement(FormBuilderInterface $builder) { parent::buildContentElement($builder); @@ -64,9 +65,7 @@ public function buildContentElement(FormBuilderInterface $builder) public function getRawData($element) { $elements = $element['elements'] ?? []; - uasort($elements, function ($a, $b) { - return ($a['position'] ?? 0) <=> ($b['position'] ?? 0); - }); + uasort($elements, fn ($a, $b) => ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); return [ 'elements' => $elements, diff --git a/LayoutType/Column.php b/LayoutType/Column.php index ace41fd4..9bef4c35 100644 --- a/LayoutType/Column.php +++ b/LayoutType/Column.php @@ -11,6 +11,7 @@ public function getCode() return 'column'; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-columns'; diff --git a/LayoutType/Row.php b/LayoutType/Row.php index 211db717..422a84ae 100644 --- a/LayoutType/Row.php +++ b/LayoutType/Row.php @@ -11,6 +11,7 @@ public function getCode() return 'row'; } + #[\Override] protected function getDefaultIconClass() { return 'fa-solid fa-bars'; diff --git a/Manager/ContentManager.php b/Manager/ContentManager.php index a3266602..edbaf76c 100644 --- a/Manager/ContentManager.php +++ b/Manager/ContentManager.php @@ -8,32 +8,14 @@ class ContentManager { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var EntityManagerInterface - */ - private $em; - - /** - * @var SlugProviderInterface - */ - private $slugProvider; - /** * ContentManager constructor. */ public function __construct( - ConfigurationManager $configurationManager, - EntityManagerInterface $em, - SlugProviderInterface $slugProvider, + private readonly ConfigurationManager $configurationManager, + private readonly EntityManagerInterface $em, + private readonly SlugProviderInterface $slugProvider, ) { - $this->configurationManager = $configurationManager; - $this->em = $em; - $this->slugProvider = $slugProvider; } /** diff --git a/Manager/ElementManager.php b/Manager/ElementManager.php index 0be84e62..4b1d4f53 100644 --- a/Manager/ElementManager.php +++ b/Manager/ElementManager.php @@ -12,17 +12,10 @@ class ElementManager /** * @var ElementInterface[] */ - private $elements; + private $elements = []; - /** - * @var array - */ - private $fieldsConfiguration; - - public function __construct(array $fieldsConfiguration) + public function __construct(private array $fieldsConfiguration) { - $this->elements = []; - $this->fieldsConfiguration = $fieldsConfiguration; } /** @@ -35,8 +28,10 @@ public function addFieldType(FieldTypeInterface $fieldType) if (false === $this->fieldsConfiguration[$fieldType->getCode()]['enabled']) { $enabled = false; } + $fieldType->setConfigData($this->fieldsConfiguration[$fieldType->getCode()]); } + if ($enabled) { $this->elements[$fieldType->getCode()] = $fieldType; } @@ -56,6 +51,7 @@ public function getGroupedFieldTypes() if (!isset($choices[$fieldGroup])) { $choices[$fieldGroup] = []; } + $choices[$fieldGroup][$element->getFormFieldLabel()] = $element; } } diff --git a/Manager/ExportManager.php b/Manager/ExportManager.php index 75717fad..9d2c050b 100644 --- a/Manager/ExportManager.php +++ b/Manager/ExportManager.php @@ -10,27 +10,15 @@ class ExportManager { - /** - * @var PageExport - */ - private $pageExport; - - /** - * @var ContentExport - */ - private $contentExport; - /** * @var array */ private $filesData = []; public function __construct( - PageExport $pageExport, - ContentExport $contentExport, + private readonly PageExport $pageExport, + private readonly ContentExport $contentExport, ) { - $this->pageExport = $pageExport; - $this->contentExport = $contentExport; $this->pageExport->setContentExport($this->contentExport); } @@ -78,6 +66,7 @@ public function generateFiles($directory, $useDatePrefix = true) if ($useDatePrefix) { $prefix = date('Ymd-His_'); } + foreach ($this->filesData as $filename => $data) { file_put_contents($directory.$prefix.$filename, $data); } @@ -101,6 +90,7 @@ public function generateZipFile() foreach (glob($tmpDir.'*') as $file) { unlink($file); } + rmdir($tmpDir); return $zipFileName; diff --git a/Manager/ImportManager.php b/Manager/ImportManager.php index 3be5e642..20a24d5e 100644 --- a/Manager/ImportManager.php +++ b/Manager/ImportManager.php @@ -16,21 +16,6 @@ class ImportManager 'contents' => 'Content', ]; - /** - * @var ContentImport - */ - private $contentImport; - - /** - * @var PageImport - */ - private $pageImport; - - /** - * @var TranslatorInterface - */ - private $translator; - /** * @var array */ @@ -42,14 +27,11 @@ class ImportManager private $symfonyStyle; public function __construct( - PageImport $pageImport, - ContentImport $contentImport, - TranslatorInterface $translator, + private readonly PageImport $pageImport, + private readonly ContentImport $contentImport, + private readonly TranslatorInterface $translator, ) { - $this->pageImport = $pageImport; - $this->contentImport = $contentImport; $this->pageImport->setContentImport($this->contentImport); - $this->translator = $translator; $this->dataToProcess = [ 'Page' => [ @@ -73,7 +55,7 @@ public function addFileToProcess(\SplFileInfo $file) foreach ($data as $entityType => $entities) { if (!isset(self::ENTITY_MAPPING[$entityType])) { - throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $entityType, '%list%' => join(', ', array_keys(self::ENTITY_MAPPING))], 'AdvancedContentBundle')); + throw new \Exception($this->translator->trans('init.errors.unknown_entity_type', ['%type%' => $entityType, '%list%' => implode(', ', array_keys(self::ENTITY_MAPPING))], 'AdvancedContentBundle')); } foreach ($entities as $slug => $entityData) { diff --git a/Manager/MimeTypeManager.php b/Manager/MimeTypeManager.php index 669c87e3..3279ac65 100644 --- a/Manager/MimeTypeManager.php +++ b/Manager/MimeTypeManager.php @@ -7,27 +7,23 @@ class MimeTypeManager { public const MIME_TYPE_IMAGE = 10; + public const MIME_TYPE_PDF = 20; + public const MIME_TYPE_EXE = 30; + public const MIME_TYPE_ARCHIVE = 40; + public const MIME_TYPE_TEXT = 50; - public const MIME_TYPE_SPREADSHEET = 60; - public const MIME_TYPE_MULTIMEDIA = 70; - /** - * @var array - */ - private $mimeTypes; + public const MIME_TYPE_SPREADSHEET = 60; - /** - * @var TranslatorInterface - */ - private $translator; + public const MIME_TYPE_MULTIMEDIA = 70; - public function __construct(array $mimeTypes, TranslatorInterface $translator) - { - $this->mimeTypes = $mimeTypes; - $this->translator = $translator; + public function __construct( + private array $mimeTypes, + private readonly TranslatorInterface $translator, + ) { } /** @@ -83,7 +79,7 @@ public function getImageMimeTypesChoices(): array } foreach ($types as $type) { - $extensions[] = basename($type); + $extensions[] = basename((string) $type); } return array_combine($extensions, $extensions); diff --git a/Manager/PageManager.php b/Manager/PageManager.php index 2abf05ce..371c9120 100644 --- a/Manager/PageManager.php +++ b/Manager/PageManager.php @@ -7,15 +7,8 @@ class PageManager { - /** - * @var SlugProviderInterface - */ - private $slugProvider; - - public function __construct( - SlugProviderInterface $slugProvider, - ) { - $this->slugProvider = $slugProvider; + public function __construct(private readonly SlugProviderInterface $slugProvider) + { } public function duplicate(PageInterface $page): PageInterface diff --git a/Manager/UploadManager.php b/Manager/UploadManager.php index 91eb6df9..fc3f8635 100644 --- a/Manager/UploadManager.php +++ b/Manager/UploadManager.php @@ -9,25 +9,14 @@ class UploadManager { /** - * @var NamerInterface + * @param string $targetDir + * @param string $webPath */ - private $fileNamer; - - /** - * @var string - */ - private $targetDir; - - /** - * @var string - */ - private $webPath; - - public function __construct(NamerInterface $fileNamer, $targetDir, $webPath) - { - $this->fileNamer = $fileNamer; - $this->targetDir = $targetDir; - $this->webPath = $webPath; + public function __construct( + private readonly NamerInterface $fileNamer, + private $targetDir, + private $webPath, + ) { } /** @@ -58,9 +47,11 @@ public function copy(File $file) if (!$file->isReadable()) { throw new \Exception(sprintf('Source file %s does not exist', $file->getRealPath())); } - if (!is_writeable($this->getTargetDir())) { + + if (!is_writable($this->getTargetDir())) { throw new \Exception(sprintf('Target directory %s is not writeable', $this->getTargetDir())); } + copy($file->getRealPath(), $this->getTargetDir().DIRECTORY_SEPARATOR.$fileName); return $fileName; diff --git a/Manager/UrlBuilderManager.php b/Manager/UrlBuilderManager.php index f15eec39..a5e2b188 100644 --- a/Manager/UrlBuilderManager.php +++ b/Manager/UrlBuilderManager.php @@ -7,29 +7,11 @@ class UrlBuilderManager { - /** - * @var UploadManager - */ - private $uploadManager; - - /** - * @var Packages - */ - private $assetPackages; - - /** - * @var RequestStack - */ - private $requestStack; - public function __construct( - UploadManager $uploadManager, - Packages $assetPackages, - RequestStack $requestStack, + private readonly UploadManager $uploadManager, + private readonly Packages $assetPackages, + private readonly RequestStack $requestStack, ) { - $this->uploadManager = $uploadManager; - $this->assetPackages = $assetPackages; - $this->requestStack = $requestStack; } public function getFileUrl(string $fileName): string @@ -52,10 +34,11 @@ public function getFullUrl(string $url): string return ''; } - if ('#' === substr($url, 0, 1)) { + if (str_starts_with($url, '#')) { return $url; } - if ('http' === substr($url, 0, 4)) { + + if (str_starts_with($url, 'http')) { return $url; } @@ -66,6 +49,7 @@ public function getFullUrl(string $url): string // compat SF < 5.3 $mainRequest = $this->requestStack->getMasterRequest(); } + if (!$mainRequest) { return $url; } diff --git a/Manager/VersionManager.php b/Manager/VersionManager.php index 03bb93ec..62538ca1 100644 --- a/Manager/VersionManager.php +++ b/Manager/VersionManager.php @@ -15,40 +15,20 @@ class VersionManager { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - /** - * @var UserProviderInterface - */ - private $userProvider; - - /** - * @var RequestStack - */ - private $requestStack; - public function __construct( - ConfigurationManager $configurationManager, - UserProviderInterface $userProvider, - RequestStack $requestStack, + private readonly ConfigurationManager $configurationManager, + private readonly UserProviderInterface $userProvider, + private readonly RequestStack $requestStack, ) { - $this->configurationManager = $configurationManager; - $this->userProvider = $userProvider; - $this->requestStack = $requestStack; } public function getContentData(ContentInterface $content): array { - if (null === $content->getPage()) { - if ($mainRequest = $this->getRequest()) { - if ($contentVersionId = $mainRequest->get('versionId')) { - foreach ($content->getVersions() as $version) { - if ($version->getId() === (int) $contentVersionId) { - return $version->getData(); - } + if (null === $content->getPage() && $mainRequest = $this->getRequest()) { + if ($contentVersionId = $mainRequest->get('versionId')) { + foreach ($content->getVersions() as $version) { + if ($version->getId() === (int) $contentVersionId) { + return $version->getData(); } } } @@ -67,6 +47,7 @@ public function getNewContentVersion(ContentInterface $content, bool $linkVersio $contentVersion->setData($content->getData()); $contentVersion->setCreatedAt(new \DateTimeImmutable()); $contentVersion->setUserId($this->userProvider->getUserId()); + $content->addVersion($contentVersion); if ($linkVersion) { $content->setContentVersion($contentVersion); @@ -85,6 +66,7 @@ public function getDraftContentVersion(ContentInterface $content): ContentVersio $lastDraft->setUserId($userId); $lastDraft->setAutoSave(true); } + $lastDraft->setCreatedAt(new \DateTimeImmutable()); return $lastDraft; @@ -101,12 +83,15 @@ private function getLastDraftVersionForUser(array $versions, ?VersionInterface $ if ($currentVersionId === $version->getId()) { continue; } + if ($version->getUserId() !== $userId) { continue; } + if (!$version->isAutoSave()) { continue; } + if (null === $lastDraft || $lastDraft->getCreatedAt() < $version->getCreatedAt()) { $lastDraft = $version; } @@ -125,6 +110,7 @@ public function getNewPageVersion(PageInterface $page): PageVersionInterface $contentVersion = $this->getNewContentVersion($page->getContent(), false); $pageVersion->setContentVersion($contentVersion); } + if (null !== $page->getPageMeta()) { $pageMetaVersion = $this->getNewPageMetaVersion($page->getPageMeta()); $pageVersion->setPageMetaVersion($pageMetaVersion); @@ -145,6 +131,7 @@ private function getNewPageMetaVersion(PageMetaInterface $pageMeta): PageMetaVer $pageMetaVersion->setMetaDescription($pageMeta->getMetaDescription()); $pageMetaVersion->setCreatedAt(new \DateTimeImmutable()); $pageMetaVersion->setUserId($this->userProvider->getUserId()); + $pageMeta->addVersion($pageMetaVersion); return $pageMetaVersion; @@ -161,6 +148,7 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface $lastDraft->setUserId($userId); $lastDraft->setAutoSave(true); } + $lastDraft->setCreatedAt(new \DateTimeImmutable()); if (null !== $page->getContent()) { @@ -170,9 +158,11 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface $contentVersion->setAutoSave(true); $lastDraft->setContentVersion($contentVersion); } + $contentVersion->setCreatedAt(new \DateTimeImmutable()); $contentVersion->setData($page->getContent()->getData()); } + if (null !== $page->getPageMeta()) { $pageMetaVersion = $lastDraft->getPageMetaVersion(); if (null === $pageMetaVersion) { @@ -180,6 +170,7 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface $pageMetaVersion->setAutoSave(true); $lastDraft->setPageMetaVersion($pageMetaVersion); } + $pageMetaVersion->setCreatedAt(new \DateTimeImmutable()); $pageMetaVersion->setTitle($page->getPageMeta()->getTitle()); $pageMetaVersion->setSlug($page->getPageMeta()->getSlug()); @@ -192,21 +183,15 @@ public function getDraftPageVersion(PageInterface $page): PageVersionInterface public function getPageVersionToLoad(PageInterface $page): ?PageVersionInterface { - if ($mainRequest = $this->getRequest()) { - if ($pageVersionId = $mainRequest->get('versionId')) { - foreach ($page->getVersions() as $version) { - if ($version->getId() === (int) $pageVersionId) { - return $version; - } + if (($mainRequest = $this->getRequest()) && $pageVersionId = $mainRequest->get('versionId')) { + foreach ($page->getVersions() as $version) { + if ($version->getId() === (int) $pageVersionId) { + return $version; } } } - if (null !== $page->getPageVersion()) { - return $page->getPageVersion(); - } - - return null; + return $page->getPageVersion(); } private function getRequest(): ?Request diff --git a/Model/Content.php b/Model/Content.php index ac581e53..aacbbaa8 100644 --- a/Model/Content.php +++ b/Model/Content.php @@ -25,7 +25,7 @@ abstract class Content implements ContentInterface, ScopableInterface /** * @var array */ - protected $data; + protected $data = []; /** * @var PageInterface @@ -52,7 +52,6 @@ abstract class Content implements ContentInterface, ScopableInterface */ public function __construct() { - $this->data = []; $this->versions = new ArrayCollection(); $this->scopes = new ArrayCollection(); } diff --git a/Model/ContentVersion.php b/Model/ContentVersion.php index 70dc3bba..5d82e21e 100644 --- a/Model/ContentVersion.php +++ b/Model/ContentVersion.php @@ -12,14 +12,13 @@ abstract class ContentVersion extends Version implements ContentVersionInterface /** * @var array */ - protected $data; + protected $data = []; /** * ContentVersion constructor. */ public function __construct() { - $this->data = []; parent::__construct(); } @@ -44,9 +43,7 @@ public function setContent(ContentInterface $content): self public function getData() { $data = $this->data ?? []; - uasort($data, function ($a, $b) { - return ($a['position'] ?? 0) <=> ($b['position'] ?? 0); - }); + uasort($data, fn ($a, $b) => ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); return $data; } diff --git a/Model/Page.php b/Model/Page.php index 58fadc2c..4dec3515 100644 --- a/Model/Page.php +++ b/Model/Page.php @@ -65,10 +65,12 @@ public function __clone() $newPageMeta = clone $this->pageMeta; $newPageMeta->setPage($this); + $this->pageMeta = $newPageMeta; $newContent = clone $this->content; $newContent->setPage($this); + $this->content = $newContent; $this->versions = new ArrayCollection(); @@ -139,6 +141,7 @@ public function setContent(?ContentInterface $content = null) if (null !== $content) { $content->setPage($this); } + $this->content = $content; return $this; @@ -178,6 +181,7 @@ public function setPageMeta(?PageMetaInterface $pageMeta = null) if (null !== $pageMeta) { $pageMeta->setPage($this); } + $this->pageMeta = $pageMeta; return $this; diff --git a/Model/PageInterface.php b/Model/PageInterface.php index 82a57496..6572ed8e 100644 --- a/Model/PageInterface.php +++ b/Model/PageInterface.php @@ -8,7 +8,9 @@ interface PageInterface { public const STATUS_DRAFT = 0; + public const STATUS_PUBLISHED = 10; + public const STATUS_TRASH = 20; /** diff --git a/Model/Version.php b/Model/Version.php index 69d716be..63c5e596 100644 --- a/Model/Version.php +++ b/Model/Version.php @@ -22,11 +22,10 @@ abstract class Version implements VersionInterface /** * @var bool */ - protected $autoSave; + protected $autoSave = false; public function __construct() { - $this->autoSave = false; } public function getId(): int diff --git a/Resources/config/routing/content.xml b/Resources/config/routing/content.xml index 92051fec..82c23b0a 100644 --- a/Resources/config/routing/content.xml +++ b/Resources/config/routing/content.xml @@ -1,15 +1,15 @@ - sherlockode_advanced_content.controller.content::addFieldAction + sherlockode_advanced_content.controller.content::addField - sherlockode_advanced_content.controller.content::fieldFormAction + sherlockode_advanced_content.controller.content::fieldForm - sherlockode_advanced_content.controller.content::saveDraftAction + sherlockode_advanced_content.controller.content::saveDraft - sherlockode_advanced_content.controller.content::deleteVersionAction + sherlockode_advanced_content.controller.content::deleteVersion diff --git a/Resources/config/routing/content_crud.xml b/Resources/config/routing/content_crud.xml index fe98d4b6..caf7219d 100644 --- a/Resources/config/routing/content_crud.xml +++ b/Resources/config/routing/content_crud.xml @@ -1,18 +1,18 @@ - sherlockode_advanced_content.controller.content_crud::createAction + sherlockode_advanced_content.controller.content_crud::create - sherlockode_advanced_content.controller.content_crud::listAction + sherlockode_advanced_content.controller.content_crud::list - sherlockode_advanced_content.controller.content_crud::editAction + sherlockode_advanced_content.controller.content_crud::edit - sherlockode_advanced_content.controller.content_crud::deleteAction + sherlockode_advanced_content.controller.content_crud::delete - sherlockode_advanced_content.controller.content_crud::showAction + sherlockode_advanced_content.controller.content_crud::show diff --git a/Resources/config/routing/page.xml b/Resources/config/routing/page.xml index b638b4b5..e4fdc639 100644 --- a/Resources/config/routing/page.xml +++ b/Resources/config/routing/page.xml @@ -1,9 +1,9 @@ - sherlockode_advanced_content.controller.page::saveDraftAction + sherlockode_advanced_content.controller.page::saveDraft - sherlockode_advanced_content.controller.page::deleteVersionAction + sherlockode_advanced_content.controller.page::deleteVersion diff --git a/Resources/config/routing/page_crud.xml b/Resources/config/routing/page_crud.xml index 19c1433a..389d3d79 100644 --- a/Resources/config/routing/page_crud.xml +++ b/Resources/config/routing/page_crud.xml @@ -1,15 +1,15 @@ - sherlockode_advanced_content.controller.page_crud::editAction + sherlockode_advanced_content.controller.page_crud::edit - sherlockode_advanced_content.controller.page_crud::createAction + sherlockode_advanced_content.controller.page_crud::create - sherlockode_advanced_content.controller.page_crud::deleteAction + sherlockode_advanced_content.controller.page_crud::delete - sherlockode_advanced_content.controller.page_crud::listAction + sherlockode_advanced_content.controller.page_crud::list diff --git a/Resources/config/routing/scope_crud.xml b/Resources/config/routing/scope_crud.xml index 75fc583a..698fb6e6 100644 --- a/Resources/config/routing/scope_crud.xml +++ b/Resources/config/routing/scope_crud.xml @@ -1,6 +1,6 @@ - sherlockode_advanced_content.controller.scope_crud::deleteAction + sherlockode_advanced_content.controller.scope_crud::delete diff --git a/Resources/config/routing/tools.xml b/Resources/config/routing/tools.xml index 11a88e74..1e5e1500 100644 --- a/Resources/config/routing/tools.xml +++ b/Resources/config/routing/tools.xml @@ -1,15 +1,15 @@ - sherlockode_advanced_content.controller.tools::indexAction + sherlockode_advanced_content.controller.tools::index - sherlockode_advanced_content.controller.tools::importAction + sherlockode_advanced_content.controller.tools::import - sherlockode_advanced_content.controller.tools::exportAction + sherlockode_advanced_content.controller.tools::export - sherlockode_advanced_content.controller.tools::deletePageTypeAction + sherlockode_advanced_content.controller.tools::deletePageType diff --git a/Scope/LocaleScopeHandler.php b/Scope/LocaleScopeHandler.php index 873a0f40..28801137 100644 --- a/Scope/LocaleScopeHandler.php +++ b/Scope/LocaleScopeHandler.php @@ -9,19 +9,12 @@ class LocaleScopeHandler extends ScopeHandler { - /** - * @var RequestStack - */ - private $requestStack; - public function __construct( EntityManagerInterface $em, ConfigurationManager $configurationManager, - RequestStack $requestStack, + private readonly RequestStack $requestStack, ) { parent::__construct($em, $configurationManager); - - $this->requestStack = $requestStack; } public function getScopeGroupBy(): ?string @@ -60,6 +53,7 @@ public function getCurrentScope(): ?ScopeInterface // compat SF < 5.3 $mainRequest = $this->requestStack->getMasterRequest(); } + if (null === $mainRequest) { return null; } diff --git a/Scope/ScopeHandler.php b/Scope/ScopeHandler.php index 972364ed..d26ab674 100644 --- a/Scope/ScopeHandler.php +++ b/Scope/ScopeHandler.php @@ -20,8 +20,10 @@ abstract class ScopeHandler implements ScopeHandlerInterface */ protected $configurationManager; - public function __construct(EntityManagerInterface $em, ConfigurationManager $configurationManager) - { + public function __construct( + EntityManagerInterface $em, + ConfigurationManager $configurationManager, + ) { $this->em = $em; $this->configurationManager = $configurationManager; } @@ -44,15 +46,18 @@ public function isPageSlugValid(PageInterface $page): bool unset($existingPages[$key]); continue; } + if (null === $existingPage->getPageVersion()->getPageMetaVersion()) { unset($existingPages[$key]); continue; } + if ($existingPage->getPageVersion()->getPageMetaVersion()->getSlug() !== $page->getPageMeta()->getSlug()) { unset($existingPages[$key]); continue; } } + $existingPages = array_values($existingPages); return $this->validateScopableEntity($page, $existingPages); @@ -77,14 +82,14 @@ private function validateScopableEntity(ScopableInterface $scopable, array $exis if ($existingEntity->getId() === $scopable->getId()) { continue; } + if (!$this->configurationManager->isScopesEnabled()) { return false; } - $result = array_uintersect($scopable->getScopes()->toArray(), $existingEntity->getScopes()->toArray(), function ($a, $b) { - return $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier(); - }); - if (count($result) > 0) { + $result = array_uintersect($scopable->getScopes()->toArray(), $existingEntity->getScopes()->toArray(), fn ($a, $b) => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); + + if ([] !== $result) { return false; } } @@ -105,7 +110,7 @@ public function getEntityForCurrentScope(string $entityCode, array $criteria): ? public function filterEntityForCurrentScope(array $entities): ?ScopableInterface { if (!$this->configurationManager->isScopesEnabled()) { - return count($entities) > 0 ? reset($entities) : null; + return [] !== $entities ? reset($entities) : null; } $currentScope = $this->getCurrentScope(); diff --git a/SherlockodeAdvancedContentBundle.php b/SherlockodeAdvancedContentBundle.php index 2b483629..d9feed5e 100644 --- a/SherlockodeAdvancedContentBundle.php +++ b/SherlockodeAdvancedContentBundle.php @@ -1,5 +1,7 @@ addCompilerPass(new FormThemePass()); } - private function addRegisterMappingsPass(ContainerBuilder $container) + private function addRegisterMappingsPass(ContainerBuilder $container): void { $mappings = [ realpath(__DIR__.'/Resources/config/doctrine-mapping') => 'Sherlockode\AdvancedContentBundle\Model', ]; - if (class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')) { + if (class_exists(DoctrineOrmMappingsPass::class)) { $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings)); } } diff --git a/Slug/SlugProvider.php b/Slug/SlugProvider.php index bc3a688a..aa61e6f2 100644 --- a/Slug/SlugProvider.php +++ b/Slug/SlugProvider.php @@ -8,14 +8,8 @@ class SlugProvider implements SlugProviderInterface { - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - - public function __construct(ScopeHandlerInterface $scopeHandler) + public function __construct(private readonly ScopeHandlerInterface $scopeHandler) { - $this->scopeHandler = $scopeHandler; } public function setPageValidIdentifier(PageInterface $page): void @@ -24,6 +18,7 @@ public function setPageValidIdentifier(PageInterface $page): void if ($this->scopeHandler->isPageIdentifierValid($page)) { break; } + $page->setPageIdentifier($this->getNewValue($page->getPageIdentifier())); } } @@ -34,6 +29,7 @@ public function setPageValidSlug(PageInterface $page): void if ($this->scopeHandler->isPageSlugValid($page)) { break; } + $page->getPageMeta()->setSlug($this->getNewValue($page->getPageMeta()->getSlug())); } } @@ -44,6 +40,7 @@ public function setContentValidSlug(ContentInterface $content): void if ($this->scopeHandler->isContentSlugValid($content)) { break; } + $content->setSlug($this->getNewValue($content->getSlug())); } } diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index f6d33444..371c2149 100644 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -10,93 +10,26 @@ use Sherlockode\AdvancedContentBundle\Scope\ScopeHandlerInterface; use Sherlockode\AdvancedContentBundle\User\UserProviderInterface; use Symfony\Component\Form\FormView; +use Twig\Attribute\AsTwigFunction; use Twig\Environment; -use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; -class ContentExtension extends AbstractExtension +class ContentExtension { - /** - * @var ElementManager - */ - private $elementManager; - - /** - * @var Environment - */ - private $twig; - - /** - * @var EntityManager - */ - private $em; - - /** - * @var UrlBuilderManager - */ - private $urlBuilderManager; - - /** - * @var UserProviderInterface - */ - private $userProvider; - - /** - * @var ScopeHandlerInterface - */ - private $scopeHandler; - - /** - * @var string - */ - private $baseFormTheme; - /** * @param string $baseFormTheme */ public function __construct( - ElementManager $elementManager, - Environment $twig, - EntityManager $em, - UrlBuilderManager $urlBuilderManager, - UserProviderInterface $userProvider, - ScopeHandlerInterface $scopeHandler, - $baseFormTheme, + private readonly ElementManager $elementManager, + private readonly Environment $twig, + private readonly EntityManager $em, + private readonly UrlBuilderManager $urlBuilderManager, + private readonly UserProviderInterface $userProvider, + private readonly ScopeHandlerInterface $scopeHandler, + private $baseFormTheme, ) { - $this->elementManager = $elementManager; - $this->twig = $twig; - $this->em = $em; - $this->urlBuilderManager = $urlBuilderManager; - $this->userProvider = $userProvider; - $this->scopeHandler = $scopeHandler; - $this->baseFormTheme = $baseFormTheme; - } - - /** - * Add specific twig function. - * - * @return TwigFunction[] - */ - public function getFunctions() - { - return [ - new TwigFunction('acb_render_element', [$this, 'renderElement'], ['is_safe' => ['html']]), - new TwigFunction('acb_element_preview', [$this, 'renderElementPreview'], ['is_safe' => ['html']]), - new TwigFunction('acb_find_entity', [$this, 'findEntity']), - new TwigFunction('acb_base_form_theme', [$this, 'getBaseFormTheme']), - new TwigFunction('acb_get_file_url', [$this, 'getFileUrl']), - new TwigFunction('acb_get_full_url', [$this, 'getFullUrl']), - new TwigFunction('acb_get_element_label', [$this, 'getElementLabel']), - new TwigFunction('acb_get_column_classes', [$this, 'getColumnClasses']), - new TwigFunction('acb_get_row_classes', [$this, 'getRowClasses']), - new TwigFunction('acb_get_element_attributes', [$this, 'getElementAttributes']), - new TwigFunction('acb_get_json_form', [$this, 'getJsonForm']), - new TwigFunction('acb_get_version_user_name', [$this, 'getVersionUserName']), - new TwigFunction('acb_get_content_by_slug', [$this, 'getContentBySlug']), - new TwigFunction('acb_get_col_size', [$this, 'getColSize']), - ]; } + #[AsTwigFunction(name: 'acb_render_element', isSafe: ['html'])] public function renderElement(array $elementData) { $element = $this->elementManager->getElementByCode($elementData['elementType']); @@ -105,6 +38,7 @@ public function renderElement(array $elementData) return $this->twig->render($element->getFrontTemplate(), $params); } + #[AsTwigFunction(name: 'acb_element_preview', isSafe: ['html'])] public function renderElementPreview(array $elementData, ?FormView $form = null): string { $element = $this->elementManager->getElementByCode($elementData['elementType']); @@ -118,6 +52,7 @@ public function renderElementPreview(array $elementData, ?FormView $form = null) return $this->twig->render($template, array_merge($params, ['form' => $form])); } + #[AsTwigFunction(name: 'acb_find_entity')] public function findEntity($identifier, $class) { return $this->em->getRepository($class)->find($identifier); @@ -126,21 +61,25 @@ public function findEntity($identifier, $class) /** * @return string */ + #[AsTwigFunction(name: 'acb_base_form_theme')] public function getBaseFormTheme() { return $this->baseFormTheme; } + #[AsTwigFunction(name: 'acb_get_file_url')] public function getFileUrl(string $fileName): string { return $this->urlBuilderManager->getFileUrl($fileName); } + #[AsTwigFunction(name: 'acb_get_full_url')] public function getFullUrl(string $url): string { return $this->urlBuilderManager->getFullUrl($url); } + #[AsTwigFunction(name: 'acb_get_element_label')] public function getElementLabel(string $elementType): string { $element = $this->elementManager->getElementByCode($elementType); @@ -148,6 +87,7 @@ public function getElementLabel(string $elementType): string return $element->getFormFieldLabel(); } + #[AsTwigFunction(name: 'acb_get_column_classes')] public function getColumnClasses(array $config): array { $classes = []; @@ -168,6 +108,7 @@ public function getColumnClasses(array $config): array if (isset($config['size_'.$device])) { $classes[] = '-' === $size ? 'col' : 'col-'.$device.'-'.$config['size_'.$device]; } + if (isset($config['offset_'.$device])) { $classes[] = 'offset-'.$device.'-'.$config['offset_'.$device]; } @@ -176,6 +117,7 @@ public function getColumnClasses(array $config): array return $classes; } + #[AsTwigFunction(name: 'acb_get_row_classes')] public function getRowClasses(array $config): array { $classes = []; @@ -187,6 +129,7 @@ public function getRowClasses(array $config): array return $classes; } + #[AsTwigFunction(name: 'acb_get_element_attributes')] public function getElementAttributes(array $extra, string $defaultDisplay = 'block'): array { return [ @@ -209,7 +152,8 @@ private function getElementClasses(array $extra, string $defaultDisplay = 'block if (!is_array($hideOn)) { $hideOn = [$hideOn]; } - if (count($hideOn) > 0) { + + if ([] !== $hideOn) { $devices = [ 'xs', 'sm', @@ -225,11 +169,13 @@ private function getElementClasses(array $extra, string $defaultDisplay = 'block if (null === $lastHidden || ($lastHidden + 1) !== $key) { $classes[] = 'd-'.('xs' === $device ? '' : $device.'-').'none'; } + $lastHidden = $key; } else { if ('xs' !== $device && (null === $lastDisplayed || ($lastDisplayed + 1) !== $key)) { $classes[] = 'd-'.$device.'-'.$defaultDisplay; } + $lastDisplayed = $key; } } @@ -271,6 +217,7 @@ private function getColorForProperty(array $design, string $property): ?string if ('none' === $selectColor) { return null; } + if ('transparent' === $selectColor) { return 'transparent'; } @@ -288,6 +235,7 @@ private function getPixelProperties(): array $pixelProperties[] = sprintf($property, $direction); } } + $pixelProperties = array_merge($pixelProperties, [ 'border_top_left_radius', 'border_top_right_radius', @@ -301,6 +249,7 @@ private function getPixelProperties(): array /** * @return array|mixed */ + #[AsTwigFunction(name: 'acb_get_json_form')] public function getJsonForm(FormView $form) { // Looping on multiple choice type children will return an array of all available choices, @@ -324,16 +273,19 @@ public function getJsonForm(FormView $form) return $form->vars['data']; } + #[AsTwigFunction(name: 'acb_get_version_user_name')] public function getVersionUserName(VersionInterface $version): string { return $this->userProvider->getUserName($version->getUserId()); } + #[AsTwigFunction(name: 'acb_get_content_by_slug')] public function getContentBySlug(string $slug): ?ContentInterface { return $this->scopeHandler->getEntityForCurrentScope('content', ['slug' => $slug]); } + #[AsTwigFunction(name: 'acb_get_col_size')] public function getColSize(array $config): string { $colSize = $this->cleanColSize($config['size']); diff --git a/Twig/Extension/ScopeExtension.php b/Twig/Extension/ScopeExtension.php index f3554b63..336f0b11 100644 --- a/Twig/Extension/ScopeExtension.php +++ b/Twig/Extension/ScopeExtension.php @@ -3,34 +3,15 @@ namespace Sherlockode\AdvancedContentBundle\Twig\Extension; use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; -use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; +use Twig\Attribute\AsTwigFunction; -class ScopeExtension extends AbstractExtension +class ScopeExtension { - /** - * @var ConfigurationManager - */ - private $configurationManager; - - public function __construct( - ConfigurationManager $configurationManager, - ) { - $this->configurationManager = $configurationManager; - } - - /** - * Add specific twig function. - * - * @return TwigFunction[] - */ - public function getFunctions() + public function __construct(private readonly ConfigurationManager $configurationManager) { - return [ - new TwigFunction('acb_is_scopes_enabled', [$this, 'isScopesEnabled']), - ]; } + #[AsTwigFunction(name: 'acb_is_scopes_enabled')] public function isScopesEnabled(): bool { return $this->configurationManager->isScopesEnabled(); diff --git a/User/AnonymousUserProvider.php b/User/AnonymousUserProvider.php index 0e4d2cd6..927b0ab6 100644 --- a/User/AnonymousUserProvider.php +++ b/User/AnonymousUserProvider.php @@ -6,14 +6,8 @@ class AnonymousUserProvider implements UserProviderInterface { - /** - * @var TranslatorInterface - */ - private $translator; - - public function __construct(TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } public function getUserId(): ?int From 9668d2ed5af7671d659afe7f35ea61a9b191625e Mon Sep 17 00:00:00 2001 From: simbr Date: Thu, 26 Mar 2026 22:24:03 +0100 Subject: [PATCH 3/6] Rector full rules --- Command/ExportCommand.php | 21 +++++------ Command/ImportCommand.php | 22 +++++------- Controller/ContentController.php | 2 ++ Controller/Crud/ContentController.php | 18 +++++----- Controller/Crud/PageController.php | 14 ++++---- Controller/Crud/ScopeController.php | 5 ++- Controller/PageController.php | 2 ++ Controller/ToolsController.php | 11 +++--- DependencyInjection/Compiler/ElementPass.php | 4 ++- .../Compiler/FormThemePass.php | 4 ++- DependencyInjection/Configuration.php | 6 ++-- .../SherlockodeAdvancedContentExtension.php | 4 ++- Doctrine/MigrationHelper.php | 2 ++ Doctrine/MigrationHelperAwareInterface.php | 2 ++ Doctrine/MigrationHelperInterface.php | 2 ++ Element/AbstractElement.php | 6 ++-- Element/ElementInterface.php | 2 ++ Event/AcbFilePostValidate.php | 2 ++ Event/AcbFilePreSubmitEvent.php | 2 ++ EventListener/AcbFileListener.php | 7 ++-- EventListener/ContentListener.php | 6 ++-- EventListener/PageListener.php | 8 +++-- EventListener/VersionListener.php | 4 ++- Exception/InvalidElementException.php | 2 ++ Export/ContentExport.php | 11 +++--- Export/ElementExport.php | 2 ++ Export/PageExport.php | 14 +++----- Export/ScopeExport.php | 2 ++ FieldType/AbstractFieldType.php | 8 ++--- FieldType/AbstractInputType.php | 2 ++ FieldType/Content.php | 11 +++--- FieldType/FieldTypeInterface.php | 2 ++ FieldType/File.php | 20 ++++------- FieldType/Iframe.php | 15 +++----- FieldType/Image.php | 18 +++++----- FieldType/ImageCarousel.php | 13 +++---- FieldType/Link.php | 26 +++++--------- FieldType/RelativeLink.php | 17 ++++----- FieldType/Separator.php | 13 +++---- FieldType/Text.php | 11 +++--- FieldType/TextArea.php | 11 +++--- FieldType/Title.php | 13 +++---- FieldType/Video.php | 13 +++---- FieldType/Wysiwyg.php | 13 +++---- Form/DataTransformer/StringToEntity.php | 6 ++-- Form/Type/AcbContentType.php | 4 ++- Form/Type/AcbFileType.php | 25 ++++++------- Form/Type/ColumnType.php | 4 ++- Form/Type/ContentDataType.php | 2 ++ Form/Type/ContentType.php | 14 ++++---- Form/Type/ElementAdvancedType.php | 4 ++- Form/Type/ElementDesignType.php | 4 ++- Form/Type/ElementHideOnType.php | 4 ++- Form/Type/ElementType.php | 8 +++-- Form/Type/ElementsType.php | 12 ++++--- Form/Type/EntityType.php | 4 ++- Form/Type/ExportType.php | 6 ++-- Form/Type/ImageCarouselType.php | 4 ++- Form/Type/ImageType.php | 6 ++-- Form/Type/ImportType.php | 6 ++-- Form/Type/LinkType.php | 6 ++-- Form/Type/PageMetaType.php | 8 +++-- Form/Type/PageType.php | 12 ++++--- Form/Type/PageTypeType.php | 6 ++-- Form/Type/PictureEntryType.php | 6 ++-- Form/Type/PictureType.php | 8 +++-- Form/Type/RepeatedChildWrappedType.php | 10 +++--- Form/Type/RepeaterType.php | 14 ++++---- Form/Type/RowType.php | 4 ++- Form/Type/ScopeChoiceType.php | 4 ++- Form/Type/ScopeType.php | 6 ++-- Form/Type/TitleType.php | 6 ++-- Form/Type/VideoType.php | 4 ++- Form/Type/WysiwygType.php | 4 ++- Import/AbstractImport.php | 36 ++++--------------- Import/ContentImport.php | 6 ++-- Import/ElementImport.php | 17 +++++---- Import/ImportResult.php | 18 ++++------ Import/PageImport.php | 9 +++-- LayoutType/AbstractLayoutType.php | 8 ++--- LayoutType/Column.php | 6 ++-- LayoutType/LayoutTypeInterface.php | 2 ++ LayoutType/Row.php | 6 ++-- Manager/ConfigurationManager.php | 9 +++-- Manager/ContentManager.php | 2 ++ Manager/ElementManager.php | 12 +++---- Manager/ExportManager.php | 26 ++++++-------- Manager/ImportManager.php | 22 +++++------- Manager/MimeTypeManager.php | 6 ++-- Manager/PageManager.php | 2 ++ Manager/UploadManager.php | 14 ++++---- Manager/UrlBuilderManager.php | 2 ++ Manager/VersionManager.php | 12 +++---- Model/Content.php | 2 ++ Model/ContentInterface.php | 2 ++ Model/ContentVersion.php | 4 ++- Model/ContentVersionInterface.php | 2 ++ Model/LocaleScope.php | 12 +++---- Model/LocaleScopeInterface.php | 2 ++ Model/Page.php | 2 ++ Model/PageInterface.php | 2 ++ Model/PageMeta.php | 2 ++ Model/PageMetaInterface.php | 2 ++ Model/PageMetaVersion.php | 2 ++ Model/PageMetaVersionInterface.php | 2 ++ Model/PageType.php | 2 ++ Model/PageTypeInterface.php | 2 ++ Model/PageVersion.php | 2 ++ Model/PageVersionInterface.php | 2 ++ Model/ScopableInterface.php | 2 ++ Model/Scope.php | 2 ++ Model/ScopeInterface.php | 2 ++ Model/Version.php | 2 ++ Model/VersionInterface.php | 2 ++ Naming/ClientOriginalNamer.php | 8 ++--- Naming/NamerInterface.php | 2 ++ Naming/UniqueNamer.php | 2 ++ Scope/LocaleScopeHandler.php | 2 ++ Scope/ScopeHandler.php | 20 +++-------- Scope/ScopeHandlerInterface.php | 2 ++ Slug/SlugProvider.php | 7 ++-- Slug/SlugProviderInterface.php | 2 ++ Twig/Extension/ContentExtension.php | 9 +++-- Twig/Extension/ScopeExtension.php | 2 ++ User/AnonymousUserProvider.php | 2 ++ User/UserProviderInterface.php | 2 ++ 126 files changed, 492 insertions(+), 441 deletions(-) diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php index 9e64f87d..f7f882f1 100644 --- a/Command/ExportCommand.php +++ b/Command/ExportCommand.php @@ -1,5 +1,7 @@ symfonyStyle = new SymfonyStyle($input, $output); try { @@ -111,7 +106,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * @throws \Exception */ - private function init(InputInterface $input) + private function init(InputInterface $input): void { $initDir = $input->getOption('dir'); if (null === $initDir) { diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index 2aa38a7d..4b1eb65b 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -1,5 +1,7 @@ symfonyStyle = new SymfonyStyle($input, $output); try { @@ -110,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return self::SUCCESS; } - private function addFilesToProcess() + private function addFilesToProcess(): void { $finder = new Finder(); $finder->files()->in($this->sourceDirectory); @@ -140,7 +138,7 @@ private function addFilesToProcess() /** * @throws \Exception */ - private function init(InputInterface $input) + private function init(InputInterface $input): void { $initDir = $input->getOption('dir'); if (null === $initDir) { @@ -183,11 +181,9 @@ private function init(InputInterface $input) /** * @param string $dir * - * @return string - * * @throws \Exception */ - private function getDirFullPath($dir) + private function getDirFullPath($dir): string { if (!str_starts_with($dir, '/')) { $dir = $this->rootDir.'/'.$dir; diff --git a/Controller/ContentController.php b/Controller/ContentController.php index 859b7318..3612b387 100644 --- a/Controller/ContentController.php +++ b/Controller/ContentController.php @@ -1,5 +1,7 @@ contentManager->getContentById($id); @@ -60,7 +63,7 @@ public function edit($id, Request $request) /** * @return Response */ - public function create(Request $request) + public function create(Request $request): RedirectResponse|Response { if ($id = $request->get('duplicateId')) { $contentToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->find($id); @@ -93,10 +96,7 @@ public function create(Request $request) ]); } - /** - * @return Response - */ - public function list() + public function list(): Response { $contents = $this->contentManager->getContents(); @@ -110,7 +110,7 @@ public function list() * * @return Response */ - public function delete($id) + public function delete($id): RedirectResponse { $content = $this->contentManager->getContentById($id); @@ -126,10 +126,8 @@ public function delete($id) /** * @param int $id - * - * @return Response */ - public function show($id) + public function show($id): Response { $content = $this->contentManager->getContentById($id); diff --git a/Controller/Crud/PageController.php b/Controller/Crud/PageController.php index 5fd0a0db..e11368e7 100644 --- a/Controller/Crud/PageController.php +++ b/Controller/Crud/PageController.php @@ -1,5 +1,7 @@ em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); @@ -53,7 +56,7 @@ public function edit($id, Request $request) /** * @return Response */ - public function create(Request $request) + public function create(Request $request): RedirectResponse|Response { if ($id = $request->get('duplicateId')) { $pageToDuplicate = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); @@ -85,10 +88,7 @@ public function create(Request $request) ]); } - /** - * @return Response - */ - public function list() + public function list(): Response { $pages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findAll(); @@ -102,7 +102,7 @@ public function list() * * @return Response */ - public function delete($id) + public function delete($id): RedirectResponse { $page = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->find($id); diff --git a/Controller/Crud/ScopeController.php b/Controller/Crud/ScopeController.php index b6c49fa9..9364cbe4 100644 --- a/Controller/Crud/ScopeController.php +++ b/Controller/Crud/ScopeController.php @@ -1,11 +1,14 @@ em->getRepository($this->configurationManager->getEntityClass('scope'))->find($id); diff --git a/Controller/PageController.php b/Controller/PageController.php index 03ba3c31..5b631de6 100644 --- a/Controller/PageController.php +++ b/Controller/PageController.php @@ -1,5 +1,7 @@ createForm(ImportType::class, null, [ 'action' => $this->generateUrl('sherlockode_acb_tools_import'), @@ -102,7 +105,7 @@ public function index(Request $request) /** * @return Response */ - public function import(Request $request) + public function import(Request $request): RedirectResponse { $form = $this->createForm(ImportType::class); @@ -131,7 +134,7 @@ public function import(Request $request) /** * @return Response */ - public function export(Request $request) + public function export(Request $request): Response|RedirectResponse { $form = $this->createForm(ExportType::class); @@ -171,7 +174,7 @@ public function export(Request $request) * * @return Response */ - public function deletePageType($id) + public function deletePageType($id): RedirectResponse { $pageType = $this->em->getRepository($this->configurationManager->getEntityClass('page_type'))->find($id); diff --git a/DependencyInjection/Compiler/ElementPass.php b/DependencyInjection/Compiler/ElementPass.php index 07547f8c..00a49344 100644 --- a/DependencyInjection/Compiler/ElementPass.php +++ b/DependencyInjection/Compiler/ElementPass.php @@ -1,5 +1,7 @@ has('sherlockode_advanced_content.element_manager')) { return; diff --git a/DependencyInjection/Compiler/FormThemePass.php b/DependencyInjection/Compiler/FormThemePass.php index 1d0b2863..4fbbbed1 100644 --- a/DependencyInjection/Compiler/FormThemePass.php +++ b/DependencyInjection/Compiler/FormThemePass.php @@ -1,5 +1,7 @@ has('twig')) { return; diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d24d86aa..a2087b77 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -1,5 +1,7 @@ getRootNode(); diff --git a/DependencyInjection/SherlockodeAdvancedContentExtension.php b/DependencyInjection/SherlockodeAdvancedContentExtension.php index e10b2bd5..66d9910e 100644 --- a/DependencyInjection/SherlockodeAdvancedContentExtension.php +++ b/DependencyInjection/SherlockodeAdvancedContentExtension.php @@ -1,5 +1,7 @@ load('services.xml'); diff --git a/Doctrine/MigrationHelper.php b/Doctrine/MigrationHelper.php index c1a0881f..3ab5426c 100644 --- a/Doctrine/MigrationHelper.php +++ b/Doctrine/MigrationHelper.php @@ -1,5 +1,7 @@ add('elementType', HiddenType::class); $builder->add('position', HiddenType::class); diff --git a/Element/ElementInterface.php b/Element/ElementInterface.php index ae98cefe..49c3200a 100644 --- a/Element/ElementInterface.php +++ b/Element/ElementInterface.php @@ -1,5 +1,7 @@ getEntity(); @@ -31,7 +33,7 @@ public function postLoad(LifecycleEventArgs $args) $entity->setData($this->versionManager->getContentData($entity), false); } - public function onFlush(OnFlushEventArgs $args) + public function onFlush(OnFlushEventArgs $args): void { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); diff --git a/EventListener/PageListener.php b/EventListener/PageListener.php index b1db1c91..a8150f8d 100644 --- a/EventListener/PageListener.php +++ b/EventListener/PageListener.php @@ -1,5 +1,7 @@ getEntity(); @@ -55,7 +57,7 @@ public function postLoad(LifecycleEventArgs $args) } } - public function prePersist(LifecycleEventArgs $args) + public function prePersist(LifecycleEventArgs $args): void { $object = $args->getObject(); @@ -68,7 +70,7 @@ public function prePersist(LifecycleEventArgs $args) } } - public function onFlush(OnFlushEventArgs $args) + public function onFlush(OnFlushEventArgs $args): void { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); diff --git a/EventListener/VersionListener.php b/EventListener/VersionListener.php index 432636a3..b93ab8cd 100644 --- a/EventListener/VersionListener.php +++ b/EventListener/VersionListener.php @@ -1,5 +1,7 @@ getEntity(); diff --git a/Exception/InvalidElementException.php b/Exception/InvalidElementException.php index fb054fbc..21df2398 100644 --- a/Exception/InvalidElementException.php +++ b/Exception/InvalidElementException.php @@ -1,5 +1,7 @@ getName(); @@ -35,10 +34,8 @@ public function exportData(ContentInterface $content) /** * @param array|array[] $elements - * - * @return array */ - public function exportElements($elements) + public function exportElements($elements): array { if (!is_array($elements)) { return []; diff --git a/Export/ElementExport.php b/Export/ElementExport.php index 98ec50a1..c234aa29 100644 --- a/Export/ElementExport.php +++ b/Export/ElementExport.php @@ -1,5 +1,7 @@ getStatus(); @@ -51,7 +47,7 @@ public function exportData(PageInterface $page) return $data; } - public function setContentExport(ContentExport $contentExport) + public function setContentExport(ContentExport $contentExport): void { $this->contentExport = $contentExport; } diff --git a/Export/ScopeExport.php b/Export/ScopeExport.php index d5812ac3..771bbb1b 100644 --- a/Export/ScopeExport.php +++ b/Export/ScopeExport.php @@ -1,5 +1,7 @@ addModelTransformer($modelTransformer); } - $builder->get('value')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->get('value')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { $data = $event->getData(); $form = $event->getForm(); if ($form->getConfig()->getCompound()) { diff --git a/FieldType/AbstractInputType.php b/FieldType/AbstractInputType.php index e3389ab9..0dc9d8a0 100644 --- a/FieldType/AbstractInputType.php +++ b/FieldType/AbstractInputType.php @@ -1,5 +1,7 @@ urlBuilderManager->getFileUrl($value['src'] ?? ''); } diff --git a/FieldType/Iframe.php b/FieldType/Iframe.php index f44a84c0..1eac207e 100644 --- a/FieldType/Iframe.php +++ b/FieldType/Iframe.php @@ -1,5 +1,7 @@ $this->getUrlFormType(), ]; } - /** - * @return string - */ - protected function getUrlFormType() + protected function getUrlFormType(): string { return UrlType::class; } /** * Get field's code. - * - * @return string */ - public function getCode() + public function getCode(): string { return 'link'; } @@ -73,11 +67,9 @@ public function getRawValue($element) } /** - * @param array $value - * * @return string */ - protected function getUrlValue($value) + protected function getUrlValue(array $value) { return $value['url'] ?? ''; } diff --git a/FieldType/RelativeLink.php b/FieldType/RelativeLink.php index 16b00798..b12ae019 100644 --- a/FieldType/RelativeLink.php +++ b/FieldType/RelativeLink.php @@ -1,5 +1,7 @@ urlBuilderManager->getFullUrl($value['url'] ?? ''); } diff --git a/FieldType/Separator.php b/FieldType/Separator.php index ec187dfc..31cba856 100644 --- a/FieldType/Separator.php +++ b/FieldType/Separator.php @@ -1,31 +1,28 @@ em->getRepository($this->configurationManager->getEntityClass('content'))->findBy([ 'page' => null, diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php index a54b5cfc..5337da8b 100644 --- a/Form/Type/AcbFileType.php +++ b/Form/Type/AcbFileType.php @@ -1,5 +1,7 @@ mimeTypeManager->generateMimeTypeChoices(); @@ -45,14 +47,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'label' => 'field_type.file.restriction_type', 'multiple' => true, 'choices' => is_array($mimeTypeChoices) ? $mimeTypeChoices : [], - 'choice_attr' => fn ($choice): array => ['data-mime-type' => json_encode($this->mimeTypeManager->getMimeTypesByCode($choice))], + 'choice_attr' => fn (string $choice): array => ['data-mime-type' => json_encode($this->mimeTypeManager->getMimeTypesByCode($choice))], 'attr' => ['data-mime-type-restriction' => ''], ]) ; $builder->addEventListener( FormEvents::POST_SET_DATA, - function (FormEvent $event) use ($options) { + function (FormEvent $event) use ($options): void { $form = $event->getForm(); $data = $event->getData(); if (!is_array($data)) { @@ -65,7 +67,7 @@ function (FormEvent $event) use ($options) { $builder->addEventListener( FormEvents::PRE_SUBMIT, - function (FormEvent $event) use ($options) { + function (FormEvent $event) use ($options): void { $data = $event->getData(); $form = $event->getForm(); @@ -94,7 +96,7 @@ function (FormEvent $event) use ($options) { $event->setData($data); } ); - $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { $data = $event->getData(); $form = $event->getForm(); if ($form->getConfig()->getCompound()) { @@ -111,14 +113,7 @@ function (FormEvent $event) use ($options) { }); } - /** - * @param array $data - * @param array $options - * @param bool $hasFile - * - * @return void - */ - private function updateForm(FormInterface $form, $data, $options, $hasFile = false) + private function updateForm(FormInterface $form, array $data, array $options, bool $hasFile = false): void { if (!isset($data['src'])) { $data['src'] = ''; @@ -173,7 +168,7 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal } } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', @@ -190,7 +185,7 @@ public function configureOptions(OptionsResolver $resolver) * @param FormInterface $form The form * @param array $options The options */ - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options): void { $fileSrc = $form->getData()['src'] ?? ''; if ('' !== $fileSrc && false === $this->uploadManager->isFileUploaded($fileSrc)) { diff --git a/Form/Type/ColumnType.php b/Form/Type/ColumnType.php index b6e48391..1485434c 100644 --- a/Form/Type/ColumnType.php +++ b/Form/Type/ColumnType.php @@ -1,5 +1,7 @@ 1, diff --git a/Form/Type/ContentDataType.php b/Form/Type/ContentDataType.php index 47fa5c47..71dd54b4 100644 --- a/Form/Type/ContentDataType.php +++ b/Form/Type/ContentDataType.php @@ -1,5 +1,7 @@ addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token): void { $form = $event->getForm(); /** @var ContentInterface $content */ $content = $event->getData(); @@ -109,11 +111,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { $event->setData(json_decode((string) $event->getData(), true)); }, 1); - $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { $form = $event->getForm(); if ($form->has('slug')) { $content = $event->getData(); @@ -132,13 +134,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - public function finishView(FormView $view, FormInterface $form, array $options) + public function finishView(FormView $view, FormInterface $form, array $options): void { // ensure the form is working on the first added image (multipart would not be set in this case) $view->vars['multipart'] = true; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/ElementAdvancedType.php b/Form/Type/ElementAdvancedType.php index 85b6c838..b087f1be 100644 --- a/Form/Type/ElementAdvancedType.php +++ b/Form/Type/ElementAdvancedType.php @@ -1,5 +1,7 @@ add('class', TextType::class, [ diff --git a/Form/Type/ElementDesignType.php b/Form/Type/ElementDesignType.php index 2f4fb40b..f336f7c0 100644 --- a/Form/Type/ElementDesignType.php +++ b/Form/Type/ElementDesignType.php @@ -1,5 +1,7 @@ add('margin_top', IntegerType::class, [ diff --git a/Form/Type/ElementHideOnType.php b/Form/Type/ElementHideOnType.php index 0b472b8e..86e29464 100644 --- a/Form/Type/ElementHideOnType.php +++ b/Form/Type/ElementHideOnType.php @@ -1,5 +1,7 @@ setDefaults([ 'choices' => [ diff --git a/Form/Type/ElementType.php b/Form/Type/ElementType.php index 3f19c6de..bb1f8c89 100644 --- a/Form/Type/ElementType.php +++ b/Form/Type/ElementType.php @@ -1,5 +1,7 @@ buildContentElement($builder); $builder->add('extra', FormType::class, [ @@ -25,13 +27,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - public function buildView(FormView $view, FormInterface $form, array $options) + public function buildView(FormView $view, FormInterface $form, array $options): void { $view->vars['panel_label'] = $options['element_type']->getFormFieldLabel(); $view->vars['field_icon'] = $options['element_type']->getIconClass(); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired(['element_type']); $resolver->setDefaults([ diff --git a/Form/Type/ElementsType.php b/Form/Type/ElementsType.php index 54acc788..f2715464 100644 --- a/Form/Type/ElementsType.php +++ b/Form/Type/ElementsType.php @@ -1,5 +1,7 @@ addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { + $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void { $data = $event->getData(); $form = $event->getForm(); if (!$data) { @@ -41,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void { $form = $event->getForm(); $data = $event->getData(); if (!is_array($data)) { @@ -67,7 +69,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { $form = $event->getForm(); $data = $event->getData(); $data = array_values($data); @@ -107,7 +109,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/EntityType.php b/Form/Type/EntityType.php index 2ff1f00b..855f6b30 100644 --- a/Form/Type/EntityType.php +++ b/Form/Type/EntityType.php @@ -1,5 +1,7 @@ addModelTransformer(new StringToEntity($options['em'], $options['class'], 'id')); } diff --git a/Form/Type/ExportType.php b/Form/Type/ExportType.php index 2330dc1e..6709733e 100644 --- a/Form/Type/ExportType.php +++ b/Form/Type/ExportType.php @@ -1,5 +1,7 @@ add('page', EntityType::class, [ @@ -54,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/ImageCarouselType.php b/Form/Type/ImageCarouselType.php index 9c5ae087..b1c14dd2 100644 --- a/Form/Type/ImageCarouselType.php +++ b/Form/Type/ImageCarouselType.php @@ -1,5 +1,7 @@ add('images', RepeaterType::class, [ diff --git a/Form/Type/ImageType.php b/Form/Type/ImageType.php index 9c1f45bb..3a0c1179 100644 --- a/Form/Type/ImageType.php +++ b/Form/Type/ImageType.php @@ -1,5 +1,7 @@ remove('title'); $builder @@ -43,7 +45,7 @@ public function getBlockPrefix() return 'acb_image'; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/ImportType.php b/Form/Type/ImportType.php index 44b4e356..b71c5a9f 100644 --- a/Form/Type/ImportType.php +++ b/Form/Type/ImportType.php @@ -1,5 +1,7 @@ add('file', FileType::class, ['label' => 'tools.import.file']) ; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/LinkType.php b/Form/Type/LinkType.php index 64a974d4..13ec6d5e 100644 --- a/Form/Type/LinkType.php +++ b/Form/Type/LinkType.php @@ -1,5 +1,7 @@ add('url', $options['url_form_type'], [ @@ -29,7 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/PageMetaType.php b/Form/Type/PageMetaType.php index 6c417132..5247c6ba 100644 --- a/Form/Type/PageMetaType.php +++ b/Form/Type/PageMetaType.php @@ -1,5 +1,7 @@ addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) use ($options, $token): void { $form = $event->getForm(); /** @var PageMetaInterface $pageMeta */ $pageMeta = $event->getData(); @@ -82,7 +84,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/PageType.php b/Form/Type/PageType.php index 17635766..cf8b7a27 100644 --- a/Form/Type/PageType.php +++ b/Form/Type/PageType.php @@ -1,5 +1,7 @@ add('pageIdentifier', TextType::class, [ @@ -56,7 +58,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) { + $builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event): void { $form = $event->getForm(); /** @var PageInterface $page */ $page = $event->getData(); @@ -77,7 +79,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); // fill the content name and slug as they are not part of the form in Page context - $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { /** @var PageInterface $page */ $page = $event->getData(); $content = $page->getContent(); @@ -117,7 +119,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } }); - $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event): void { $form = $event->getForm(); if ($form->isValid()) { // Reset page version to make sure that page is flagged as to be updated @@ -126,7 +128,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) }); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => $this->configurationManager->getEntityClass('page'), diff --git a/Form/Type/PageTypeType.php b/Form/Type/PageTypeType.php index 00699702..c75682bb 100644 --- a/Form/Type/PageTypeType.php +++ b/Form/Type/PageTypeType.php @@ -1,5 +1,7 @@ add('name', TextType::class, [ @@ -27,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => $this->configurationManager->getEntityClass('page_type'), diff --git a/Form/Type/PictureEntryType.php b/Form/Type/PictureEntryType.php index 6d4b6051..e9a54597 100644 --- a/Form/Type/PictureEntryType.php +++ b/Form/Type/PictureEntryType.php @@ -1,5 +1,7 @@ remove('alt'); $builder->remove('mime_type'); @@ -26,7 +28,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener( FormEvents::PRE_SUBMIT, - function (FormEvent $event) { + function (FormEvent $event): void { $data = $event->getData(); if (isset($data['mime_type'])) { // Remove mime type data to prevent form extra fields error diff --git a/Form/Type/PictureType.php b/Form/Type/PictureType.php index bfb4705d..864699bc 100644 --- a/Form/Type/PictureType.php +++ b/Form/Type/PictureType.php @@ -1,5 +1,7 @@ add('image', ImageType::class, [ @@ -32,7 +34,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener( FormEvents::PRE_SUBMIT, - function (FormEvent $event) { + function (FormEvent $event): void { $data = $event->getData(); $globalMimeTypes = $data['image']['mime_type'] ?? []; if (isset($data['sources']) && is_array($data['sources'])) { @@ -46,7 +48,7 @@ function (FormEvent $event) { ); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'row_attr' => ['class' => 'picture-field'], diff --git a/Form/Type/RepeatedChildWrappedType.php b/Form/Type/RepeatedChildWrappedType.php index 2f589ca9..fd173bb8 100644 --- a/Form/Type/RepeatedChildWrappedType.php +++ b/Form/Type/RepeatedChildWrappedType.php @@ -1,5 +1,7 @@ add('wrapped_child', $options['child_form'], $options['child_options']) ->add('position', HiddenType::class, ['data' => $options['position']]) ; - $dataCallback = function (FormEvent $event) { + $dataCallback = function (FormEvent $event): void { $data = $event->getData(); $data = ['wrapped_child' => $data]; @@ -34,14 +36,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener(FormEvents::PRE_SET_DATA, $dataCallback, -5); } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'position' => 0, 'child_options' => [], ]); $resolver->setRequired(['child_form']); - $resolver->setNormalizer('child_options', function (Options $options, $value) { + $resolver->setNormalizer('child_options', function (Options $options, array $value): array { unset($value['property_path']); return $value; diff --git a/Form/Type/RepeaterType.php b/Form/Type/RepeaterType.php index 700e58f6..0ce3b877 100644 --- a/Form/Type/RepeaterType.php +++ b/Form/Type/RepeaterType.php @@ -1,5 +1,7 @@ hasAttribute('prototype')) { /** @var FormInterface $prototype */ @@ -23,7 +25,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } else { // rebuild prototype using the RepeatedChildWrappedType $prototypeOptions = $prototype->getConfig()->getOptions(); - $prototypeOptions = array_filter($prototypeOptions, function ($k, $v) { + $prototypeOptions = array_filter($prototypeOptions, function ($k, $v): bool { $whitelist = [ 'data_class', 'empty_data', @@ -55,7 +57,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } // add the position field to all collection children - $positionCallback = function (FormEvent $event) { + $positionCallback = function (FormEvent $event): void { $form = $event->getForm(); foreach ($form->all() as $i => $child) { @@ -75,7 +77,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->addEventListener(FormEvents::PRE_SUBMIT, $positionCallback, -10); // reorder the children array depending on the new position - $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { + $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void { $data = $event->getData(); $orderedData = []; @@ -91,7 +93,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $orderedData[] = $item; } - usort($orderedData, fn ($a, $b) => $a['position'] <=> $b['position']); + usort($orderedData, fn (array $a, array $b): int => $a['position'] <=> $b['position']); // unset the position key in the saved data $orderedData = array_map(function ($item) { @@ -115,7 +117,7 @@ public function getParent() return CollectionType::class; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'allow_add' => true, diff --git a/Form/Type/RowType.php b/Form/Type/RowType.php index ebea3761..f1daab94 100644 --- a/Form/Type/RowType.php +++ b/Form/Type/RowType.php @@ -1,5 +1,7 @@ add('columns_gap', IntegerType::class, [ diff --git a/Form/Type/ScopeChoiceType.php b/Form/Type/ScopeChoiceType.php index e13da92d..70aa3530 100644 --- a/Form/Type/ScopeChoiceType.php +++ b/Form/Type/ScopeChoiceType.php @@ -1,5 +1,7 @@ setDefaults([ 'class' => $this->configurationManager->getEntityClass('scope'), diff --git a/Form/Type/ScopeType.php b/Form/Type/ScopeType.php index 2165e359..ae76b5bb 100644 --- a/Form/Type/ScopeType.php +++ b/Form/Type/ScopeType.php @@ -1,5 +1,7 @@ add('locale', TextType::class, [ @@ -27,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ; } - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'data_class' => $this->configurationManager->getEntityClass('scope'), diff --git a/Form/Type/TitleType.php b/Form/Type/TitleType.php index 9d5ee9fa..e40b8052 100644 --- a/Form/Type/TitleType.php +++ b/Form/Type/TitleType.php @@ -1,5 +1,7 @@ setDefaults([ 'translation_domain' => 'AdvancedContentBundle', diff --git a/Form/Type/VideoType.php b/Form/Type/VideoType.php index d484abd2..f5bffc87 100644 --- a/Form/Type/VideoType.php +++ b/Form/Type/VideoType.php @@ -1,5 +1,7 @@ add('url', UrlType::class, [ diff --git a/Form/Type/WysiwygType.php b/Form/Type/WysiwygType.php index e6598cf3..114663e2 100644 --- a/Form/Type/WysiwygType.php +++ b/Form/Type/WysiwygType.php @@ -1,5 +1,7 @@ configurationManager->getDefaultWysiwygToolbar(); $resolver->setDefaults([ diff --git a/Import/AbstractImport.php b/Import/AbstractImport.php index 723e1e1c..ac7b95d6 100644 --- a/Import/AbstractImport.php +++ b/Import/AbstractImport.php @@ -1,5 +1,7 @@ em = $em; - $this->configurationManager = $configurationManager; - $this->translator = $translator; - $this->scopeHandler = $scopeHandler; $this->init(); } @@ -175,7 +153,7 @@ protected function getExistingScopableEntity(string $entityClass, array $criteri $entity = null; foreach ($existingEntities as $existingEntity) { - $result = array_uintersect($scopes, $existingEntity->getScopes()->toArray(), fn ($a, $b) => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); + $result = array_uintersect($scopes, $existingEntity->getScopes()->toArray(), fn ($a, $b): int => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); if (count($result) === count($scopes)) { return $existingEntity; diff --git a/Import/ContentImport.php b/Import/ContentImport.php index a8fc081b..28cdc56a 100644 --- a/Import/ContentImport.php +++ b/Import/ContentImport.php @@ -1,5 +1,7 @@ em->flush(); } - public function createElements(array $elementsData, ContentInterface $content) + public function createElements(array $elementsData, ContentInterface $content): void { $elements = []; $position = 0; @@ -87,7 +89,7 @@ public function createElements(array $elementsData, ContentInterface $content) /** * @param string $dir */ - public function setFilesDirectory($dir) + public function setFilesDirectory($dir): void { $this->elementImport->setFilesDirectory($dir); } diff --git a/Import/ElementImport.php b/Import/ElementImport.php index 2b79613e..d9fc7125 100644 --- a/Import/ElementImport.php +++ b/Import/ElementImport.php @@ -1,5 +1,7 @@ translator->trans('init.errors.element_missing_type', [], 'AdvancedContentBundle')); @@ -54,7 +56,7 @@ public function getElementImportData(array $elementData, int $position = 0) ], $data); } - private function getFieldTypeImportData(FieldTypeInterface $element, array $elementData) + private function getFieldTypeImportData(FieldTypeInterface $element, array $elementData): array { $value = ''; if (null !== $element->getValueModelTransformer()) { @@ -71,7 +73,7 @@ private function getFieldTypeImportData(FieldTypeInterface $element, array $elem return ['value' => $value]; } - private function getLayoutTypeImportData(LayoutTypeInterface $element, array $elementData) + private function getLayoutTypeImportData(LayoutTypeInterface $element, array $elementData): array { $elements = $elementData['elements'] ?? []; $elementsData = []; @@ -86,7 +88,10 @@ private function getLayoutTypeImportData(LayoutTypeInterface $element, array $el ]; } - private function processValueArray(array $data) + /** + * @return mixed[] + */ + private function processValueArray(array $data): array { if (isset($data['_file'])) { // handle file @@ -115,7 +120,7 @@ private function processValueArray(array $data) return $newData; } - private function processFileUpload(array $data) + private function processFileUpload(array $data): array { $fileName = $this->getFilesDirectory().$data['_file']; if (!file_exists($fileName)) { @@ -156,7 +161,7 @@ private function getFilesDirectory() /** * @param string $dir */ - public function setFilesDirectory($dir) + public function setFilesDirectory($dir): void { $this->filesDirectory = $dir; } diff --git a/Import/ImportResult.php b/Import/ImportResult.php index 5a0a9f68..0d87f8e8 100644 --- a/Import/ImportResult.php +++ b/Import/ImportResult.php @@ -1,5 +1,7 @@ status; } - /** - * @return bool - */ - public function isSuccess() + public function isSuccess(): bool { return self::SUCCESS == $this->status; } @@ -39,7 +35,7 @@ public function isSuccess() /** * @return $this */ - public function success() + public function success(): static { $this->status = self::SUCCESS; @@ -49,7 +45,7 @@ public function success() /** * @return $this */ - public function failure() + public function failure(): static { $this->status = self::FAILURE; @@ -69,7 +65,7 @@ public function getMessages() * * @return $this */ - public function addMessage($message) + public function addMessage($message): static { $this->messages[] = $message; diff --git a/Import/PageImport.php b/Import/PageImport.php index 303b6b12..eaf34c59 100644 --- a/Import/PageImport.php +++ b/Import/PageImport.php @@ -1,5 +1,7 @@ contentImport = $contentImport; diff --git a/LayoutType/AbstractLayoutType.php b/LayoutType/AbstractLayoutType.php index e2f5bdc8..01d8b0b1 100644 --- a/LayoutType/AbstractLayoutType.php +++ b/LayoutType/AbstractLayoutType.php @@ -1,5 +1,7 @@ ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); + uasort($elements, fn ($a, $b): int => ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); return [ 'elements' => $elements, diff --git a/LayoutType/Column.php b/LayoutType/Column.php index 9bef4c35..2785aa63 100644 --- a/LayoutType/Column.php +++ b/LayoutType/Column.php @@ -1,18 +1,20 @@ config = $config; } @@ -96,10 +98,7 @@ public function isScopesEnabled() return $this->config['scopes']['enabled']; } - /** - * @param string $option - */ - private function getDefaultOptionValue($option) + private function getDefaultOptionValue(string $option) { return $this->config['default_options'][$option]; } diff --git a/Manager/ContentManager.php b/Manager/ContentManager.php index edbaf76c..c473357e 100644 --- a/Manager/ContentManager.php +++ b/Manager/ContentManager.php @@ -1,5 +1,7 @@ fieldsConfiguration[$fieldType->getCode()])) { @@ -39,10 +41,8 @@ public function addFieldType(FieldTypeInterface $fieldType) /** * Get available field types. - * - * @return array */ - public function getGroupedFieldTypes() + public function getGroupedFieldTypes(): array { $choices = []; foreach ($this->elements as $element) { @@ -62,7 +62,7 @@ public function getGroupedFieldTypes() /** * Add layout type. */ - public function addLayoutType(LayoutTypeInterface $layoutType) + public function addLayoutType(LayoutTypeInterface $layoutType): void { $this->elements[$layoutType->getCode()] = $layoutType; } diff --git a/Manager/ExportManager.php b/Manager/ExportManager.php index 9d2c050b..b5c51fff 100644 --- a/Manager/ExportManager.php +++ b/Manager/ExportManager.php @@ -1,5 +1,7 @@ filesData[$filename.'.yaml'] = $data; } /** - * @param string $directory - * @param bool $useDatePrefix + * @param bool $useDatePrefix */ - public function generateFiles($directory, $useDatePrefix = true) + public function generateFiles(string $directory, $useDatePrefix = true): void { $prefix = ''; if ($useDatePrefix) { @@ -72,10 +69,7 @@ public function generateFiles($directory, $useDatePrefix = true) } } - /** - * @return string - */ - public function generateZipFile() + public function generateZipFile(): string { $tmpDir = '/tmp/acb_export_'.time().'/'; mkdir($tmpDir); diff --git a/Manager/ImportManager.php b/Manager/ImportManager.php index 20a24d5e..960a1d59 100644 --- a/Manager/ImportManager.php +++ b/Manager/ImportManager.php @@ -1,5 +1,7 @@ 'Content', ]; - /** - * @var array - */ - private $dataToProcess; + private array $dataToProcess; - /** - * @var SymfonyStyle - */ - private $symfonyStyle; + private ?SymfonyStyle $symfonyStyle = null; public function __construct( private readonly PageImport $pageImport, @@ -48,7 +44,7 @@ public function __construct( /** * @throws \Exception */ - public function addFileToProcess(\SplFileInfo $file) + public function addFileToProcess(\SplFileInfo $file): void { $filePath = $file->getRealPath(); $data = Yaml::parseFile($filePath); @@ -69,7 +65,7 @@ public function addFileToProcess(\SplFileInfo $file) * * @return array|ImportResult[] */ - public function processData($allowedTypes = []) + public function processData($allowedTypes = []): array { $results = []; foreach ($this->dataToProcess as $type => $dataToProcess) { @@ -115,13 +111,13 @@ public function processData($allowedTypes = []) /** * @param bool $allowUpdate */ - public function setAllowUpdate($allowUpdate) + public function setAllowUpdate($allowUpdate): void { $this->pageImport->setAllowUpdate($allowUpdate); $this->contentImport->setAllowUpdate($allowUpdate); } - public function setSymfonyStyle(SymfonyStyle $symfonyStyle) + public function setSymfonyStyle(SymfonyStyle $symfonyStyle): void { $this->symfonyStyle = $symfonyStyle; } @@ -129,7 +125,7 @@ public function setSymfonyStyle(SymfonyStyle $symfonyStyle) /** * @param string $dir */ - public function setFilesDirectory($dir) + public function setFilesDirectory($dir): void { $this->contentImport->setFilesDirectory($dir); } diff --git a/Manager/MimeTypeManager.php b/Manager/MimeTypeManager.php index 3279ac65..2bc84b37 100644 --- a/Manager/MimeTypeManager.php +++ b/Manager/MimeTypeManager.php @@ -1,5 +1,7 @@ mimeTypes as $item) { - $mimeTypes[] = $item; - } + $mimeTypes = $this->mimeTypes; return array_merge([], ...$mimeTypes); } diff --git a/Manager/PageManager.php b/Manager/PageManager.php index 371c9120..86a0a92a 100644 --- a/Manager/PageManager.php +++ b/Manager/PageManager.php @@ -1,5 +1,7 @@ getTargetDir().DIRECTORY_SEPARATOR.$fileName; @@ -77,22 +79,18 @@ public function remove($fileName) * Get file name. * * @param UploadedFile|File $file - * - * @return string */ - public function getFileName(File $file) + public function getFileName(File $file): string { return $this->fileNamer->getFilename($file); } /** - * @param string $src - * * @return bool */ - public function isFileUploaded($src) + public function isFileUploaded(?string $src) { - if (empty($src)) { + if (in_array($src, [null, '', '0'], true)) { return false; } diff --git a/Manager/UrlBuilderManager.php b/Manager/UrlBuilderManager.php index a5e2b188..14b61693 100644 --- a/Manager/UrlBuilderManager.php +++ b/Manager/UrlBuilderManager.php @@ -1,5 +1,7 @@ getPage() && $mainRequest = $this->getRequest()) { - if ($contentVersionId = $mainRequest->get('versionId')) { - foreach ($content->getVersions() as $version) { - if ($version->getId() === (int) $contentVersionId) { - return $version->getData(); - } + if (null === $content->getPage() && ($mainRequest = $this->getRequest()) && $contentVersionId = $mainRequest->get('versionId')) { + foreach ($content->getVersions() as $version) { + if ($version->getId() === (int) $contentVersionId) { + return $version->getData(); } } } diff --git a/Model/Content.php b/Model/Content.php index aacbbaa8..a295700f 100644 --- a/Model/Content.php +++ b/Model/Content.php @@ -1,5 +1,7 @@ data ?? []; - uasort($data, fn ($a, $b) => ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); + uasort($data, fn ($a, $b): int => ($a['position'] ?? 0) <=> ($b['position'] ?? 0)); return $data; } diff --git a/Model/ContentVersionInterface.php b/Model/ContentVersionInterface.php index 00caaf86..36de1f1a 100644 --- a/Model/ContentVersionInterface.php +++ b/Model/ContentVersionInterface.php @@ -1,5 +1,7 @@ locale; } - /** - * @return string - */ - public function getUnicityIdentifier() + public function getUnicityIdentifier(): string { return (string) $this->locale; } diff --git a/Model/LocaleScopeInterface.php b/Model/LocaleScopeInterface.php index fc4589fe..84bf6660 100644 --- a/Model/LocaleScopeInterface.php +++ b/Model/LocaleScopeInterface.php @@ -1,5 +1,7 @@ getFilename(); - if ($file instanceof UploadedFile) { - $fileName = $file->getClientOriginalName(); + return $file->getClientOriginalName(); } - return $fileName; + return $file->getFilename(); } } diff --git a/Naming/NamerInterface.php b/Naming/NamerInterface.php index c0957042..c7915673 100644 --- a/Naming/NamerInterface.php +++ b/Naming/NamerInterface.php @@ -1,5 +1,7 @@ em = $em; - $this->configurationManager = $configurationManager; } public function isContentSlugValid(ContentInterface $content): bool @@ -87,7 +77,7 @@ private function validateScopableEntity(ScopableInterface $scopable, array $exis return false; } - $result = array_uintersect($scopable->getScopes()->toArray(), $existingEntity->getScopes()->toArray(), fn ($a, $b) => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); + $result = array_uintersect($scopable->getScopes()->toArray(), $existingEntity->getScopes()->toArray(), fn ($a, $b): int => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier()); if ([] !== $result) { return false; diff --git a/Scope/ScopeHandlerInterface.php b/Scope/ScopeHandlerInterface.php index 576c3157..b94f3c59 100644 --- a/Scope/ScopeHandlerInterface.php +++ b/Scope/ScopeHandlerInterface.php @@ -1,5 +1,7 @@ elementManager->getElementByCode($elementData['elementType']); $params = $element->getRawData($elementData); @@ -259,14 +261,15 @@ public function getJsonForm(FormView $form) && isset($form->vars['multiple']) && true === $form->vars['multiple'] ); - if ($form->vars['compound'] && !$useValueForSerialization) { foreach ($form->children as $child) { $json[$child->vars['name']] = $this->getJsonForm($child); } return $json ?? []; - } elseif ($useValueForSerialization || is_object($form->vars['data'])) { + } + + if ($useValueForSerialization || is_object($form->vars['data'])) { return $form->vars['value']; } diff --git a/Twig/Extension/ScopeExtension.php b/Twig/Extension/ScopeExtension.php index 336f0b11..53c174c4 100644 --- a/Twig/Extension/ScopeExtension.php +++ b/Twig/Extension/ScopeExtension.php @@ -1,5 +1,7 @@ Date: Fri, 27 Mar 2026 09:31:11 +0100 Subject: [PATCH 4/6] Fix feedbacks --- FieldType/Image.php | 3 --- Import/ElementImport.php | 3 --- Manager/ExportManager.php | 5 +---- Manager/UploadManager.php | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/FieldType/Image.php b/FieldType/Image.php index 5a14ed60..9251d68b 100644 --- a/FieldType/Image.php +++ b/FieldType/Image.php @@ -35,9 +35,6 @@ public function getCode(): string return 'image'; } - /** - * @return mixed[] - */ #[\Override] public function getRawValue($element): array { diff --git a/Import/ElementImport.php b/Import/ElementImport.php index d9fc7125..b44f37e0 100644 --- a/Import/ElementImport.php +++ b/Import/ElementImport.php @@ -88,9 +88,6 @@ private function getLayoutTypeImportData(LayoutTypeInterface $element, array $el ]; } - /** - * @return mixed[] - */ private function processValueArray(array $data): array { if (isset($data['_file'])) { diff --git a/Manager/ExportManager.php b/Manager/ExportManager.php index b5c51fff..6d7d284c 100644 --- a/Manager/ExportManager.php +++ b/Manager/ExportManager.php @@ -54,10 +54,7 @@ private function addToFilesData($data, string $filename): void $this->filesData[$filename.'.yaml'] = $data; } - /** - * @param bool $useDatePrefix - */ - public function generateFiles(string $directory, $useDatePrefix = true): void + public function generateFiles(string $directory, bool $useDatePrefix = true): void { $prefix = ''; if ($useDatePrefix) { diff --git a/Manager/UploadManager.php b/Manager/UploadManager.php index d5d14a13..19f1b0b5 100644 --- a/Manager/UploadManager.php +++ b/Manager/UploadManager.php @@ -90,7 +90,7 @@ public function getFileName(File $file): string */ public function isFileUploaded(?string $src) { - if (in_array($src, [null, '', '0'], true)) { + if (empty($src)) { return false; } From e79243efe04184c5d6b1b7a1dd5bff4faf55c39e Mon Sep 17 00:00:00 2001 From: simbr Date: Tue, 14 Apr 2026 22:43:56 +0200 Subject: [PATCH 5/6] Fix twig extention --- Twig/Extension/ContentExtension.php | 40 +++++++++++++++++------------ Twig/Extension/ScopeExtension.php | 13 +++++++--- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index 89052922..2ea9940b 100644 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -12,10 +12,11 @@ use Sherlockode\AdvancedContentBundle\Scope\ScopeHandlerInterface; use Sherlockode\AdvancedContentBundle\User\UserProviderInterface; use Symfony\Component\Form\FormView; -use Twig\Attribute\AsTwigFunction; use Twig\Environment; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; -class ContentExtension +class ContentExtension extends AbstractExtension { /** * @param string $baseFormTheme @@ -31,7 +32,26 @@ public function __construct( ) { } - #[AsTwigFunction(name: 'acb_render_element', isSafe: ['html'])] + public function getFunctions(): array + { + return [ + new TwigFunction('acb_render_element', [$this, 'renderElement'], ['is_safe' => ['html']]), + new TwigFunction('acb_element_preview', [$this, 'renderElementPreview'], ['is_safe' => ['html']]), + new TwigFunction('acb_find_entity', [$this, 'findEntity']), + new TwigFunction('acb_base_form_theme', [$this, 'getBaseFormTheme']), + new TwigFunction('acb_get_file_url', [$this, 'getFileUrl']), + new TwigFunction('acb_get_full_url', [$this, 'getFullUrl']), + new TwigFunction('acb_get_element_label', [$this, 'getElementLabel']), + new TwigFunction('acb_get_column_classes', [$this, 'getColumnClasses']), + new TwigFunction('acb_get_row_classes', [$this, 'getRowClasses']), + new TwigFunction('acb_get_element_attributes', [$this, 'getElementAttributes']), + new TwigFunction('acb_get_json_form', [$this, 'getJsonForm']), + new TwigFunction('acb_get_version_user_name', [$this, 'getVersionUserName']), + new TwigFunction('acb_get_content_by_slug', [$this, 'getContentBySlug']), + new TwigFunction('acb_get_col_size', [$this, 'getColSize']), + ]; + } + public function renderElement(array $elementData): string { $element = $this->elementManager->getElementByCode($elementData['elementType']); @@ -40,7 +60,6 @@ public function renderElement(array $elementData): string return $this->twig->render($element->getFrontTemplate(), $params); } - #[AsTwigFunction(name: 'acb_element_preview', isSafe: ['html'])] public function renderElementPreview(array $elementData, ?FormView $form = null): string { $element = $this->elementManager->getElementByCode($elementData['elementType']); @@ -54,7 +73,6 @@ public function renderElementPreview(array $elementData, ?FormView $form = null) return $this->twig->render($template, array_merge($params, ['form' => $form])); } - #[AsTwigFunction(name: 'acb_find_entity')] public function findEntity($identifier, $class) { return $this->em->getRepository($class)->find($identifier); @@ -63,25 +81,21 @@ public function findEntity($identifier, $class) /** * @return string */ - #[AsTwigFunction(name: 'acb_base_form_theme')] public function getBaseFormTheme() { return $this->baseFormTheme; } - #[AsTwigFunction(name: 'acb_get_file_url')] public function getFileUrl(string $fileName): string { return $this->urlBuilderManager->getFileUrl($fileName); } - #[AsTwigFunction(name: 'acb_get_full_url')] public function getFullUrl(string $url): string { return $this->urlBuilderManager->getFullUrl($url); } - #[AsTwigFunction(name: 'acb_get_element_label')] public function getElementLabel(string $elementType): string { $element = $this->elementManager->getElementByCode($elementType); @@ -89,7 +103,6 @@ public function getElementLabel(string $elementType): string return $element->getFormFieldLabel(); } - #[AsTwigFunction(name: 'acb_get_column_classes')] public function getColumnClasses(array $config): array { $classes = []; @@ -119,7 +132,6 @@ public function getColumnClasses(array $config): array return $classes; } - #[AsTwigFunction(name: 'acb_get_row_classes')] public function getRowClasses(array $config): array { $classes = []; @@ -131,7 +143,6 @@ public function getRowClasses(array $config): array return $classes; } - #[AsTwigFunction(name: 'acb_get_element_attributes')] public function getElementAttributes(array $extra, string $defaultDisplay = 'block'): array { return [ @@ -251,7 +262,6 @@ private function getPixelProperties(): array /** * @return array|mixed */ - #[AsTwigFunction(name: 'acb_get_json_form')] public function getJsonForm(FormView $form) { // Looping on multiple choice type children will return an array of all available choices, @@ -261,6 +271,7 @@ public function getJsonForm(FormView $form) && isset($form->vars['multiple']) && true === $form->vars['multiple'] ); + if ($form->vars['compound'] && !$useValueForSerialization) { foreach ($form->children as $child) { $json[$child->vars['name']] = $this->getJsonForm($child); @@ -276,19 +287,16 @@ public function getJsonForm(FormView $form) return $form->vars['data']; } - #[AsTwigFunction(name: 'acb_get_version_user_name')] public function getVersionUserName(VersionInterface $version): string { return $this->userProvider->getUserName($version->getUserId()); } - #[AsTwigFunction(name: 'acb_get_content_by_slug')] public function getContentBySlug(string $slug): ?ContentInterface { return $this->scopeHandler->getEntityForCurrentScope('content', ['slug' => $slug]); } - #[AsTwigFunction(name: 'acb_get_col_size')] public function getColSize(array $config): string { $colSize = $this->cleanColSize($config['size']); diff --git a/Twig/Extension/ScopeExtension.php b/Twig/Extension/ScopeExtension.php index 53c174c4..d96da7a6 100644 --- a/Twig/Extension/ScopeExtension.php +++ b/Twig/Extension/ScopeExtension.php @@ -5,15 +5,22 @@ namespace Sherlockode\AdvancedContentBundle\Twig\Extension; use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager; -use Twig\Attribute\AsTwigFunction; +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; -class ScopeExtension +class ScopeExtension extends AbstractExtension { public function __construct(private readonly ConfigurationManager $configurationManager) { } - #[AsTwigFunction(name: 'acb_is_scopes_enabled')] + public function getFunctions(): array + { + return [ + new TwigFunction('acb_is_scopes_enabled', [$this, 'isScopesEnabled']), + ]; + } + public function isScopesEnabled(): bool { return $this->configurationManager->isScopesEnabled(); From 711910cdb0e2748af1f908e6287f66b2fa8be913 Mon Sep 17 00:00:00 2001 From: simbr Date: Tue, 14 Apr 2026 22:56:19 +0200 Subject: [PATCH 6/6] Fix strict type --- Form/Type/AcbFileType.php | 2 +- Form/Type/ElementsType.php | 6 +++--- Manager/MimeTypeManager.php | 7 ++----- Twig/Extension/ContentExtension.php | 6 +++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php index 5337da8b..f79602d8 100644 --- a/Form/Type/AcbFileType.php +++ b/Form/Type/AcbFileType.php @@ -141,7 +141,7 @@ private function updateForm(FormInterface $form, array $data, array $options, bo $mimeTypes[] = $this->mimeTypeManager->getMimeTypesByCode($type); } - $mimeTypes = array_merge([], ...$mimeTypes); + $mimeTypes = array_merge([], ...array_values($mimeTypes)); } $options['file_constraints'][] = new File(null, null, null, $mimeTypes); diff --git a/Form/Type/ElementsType.php b/Form/Type/ElementsType.php index f2715464..5aece40e 100644 --- a/Form/Type/ElementsType.php +++ b/Form/Type/ElementsType.php @@ -35,7 +35,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $i = 0; foreach ($data as $name => $element) { $field = $this->elementManager->getElementByCode($element['elementType']); - $form->add($i++, ElementType::class, [ + $form->add((string) $i++, ElementType::class, [ 'label' => $field->getFormFieldLabel(), 'element_type' => $field, 'property_path' => '['.$name.']', @@ -60,8 +60,8 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $form->setData([]); foreach ($data as $name => $element) { - if (!$form->has($name)) { - $form->add($name, ElementType::class, [ + if (!$form->has((string) $name)) { + $form->add((string) $name, ElementType::class, [ 'element_type' => $this->elementManager->getElementByCode($element['elementType'] ?? 'text'), 'property_path' => '['.$name.']', ]); diff --git a/Manager/MimeTypeManager.php b/Manager/MimeTypeManager.php index 2bc84b37..8d9d055f 100644 --- a/Manager/MimeTypeManager.php +++ b/Manager/MimeTypeManager.php @@ -44,7 +44,7 @@ public function generateMimeTypeChoices(): array ]; } - public function getMimeTypesByCode(string $code): array + public function getMimeTypesByCode(int|string $code): array { $mimeTypes = [ self::MIME_TYPE_IMAGE => 'sherlockode_advanced_content.mime_type_group.image', @@ -89,9 +89,6 @@ public function getImageMimeTypesChoices(): array public function getAllMimeTypes(): array { - $mimeTypes = []; - $mimeTypes = $this->mimeTypes; - - return array_merge([], ...$mimeTypes); + return array_merge([], ...array_values($this->mimeTypes)); } } diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index 2ea9940b..d2920c8d 100644 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -318,15 +318,15 @@ public function getColSize(array $config): string return $colSize; } - return $colSize + $colOffset; + return (string) ($colSize + $colOffset); } - private function cleanColSize(string $value): string + private function cleanColSize(int|string $value): string { if ('auto' === $value || '-' === $value) { return str_replace('-', '', $value); } - return min(12, max(1, is_numeric($value) ? $value : 12)); + return (string) min(12, max(1, is_numeric($value) ? $value : 12)); } }