diff --git a/Command/ExportCommand.php b/Command/ExportCommand.php
index 99f61cb2..f7f882f1 100644
--- a/Command/ExportCommand.php
+++ b/Command/ExportCommand.php
@@ -1,5 +1,7 @@
em = $em;
- $this->configurationManager = $configurationManager;
- $this->exportManager = $exportManager;
- $this->translator = $translator;
- $this->rootDir = $rootDir;
}
protected function configure()
@@ -103,12 +64,9 @@ protected function configure()
}
/**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
* @return void
*/
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->symfonyStyle = new SymfonyStyle($input, $output);
try {
@@ -118,6 +76,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 = [];
@@ -125,60 +84,54 @@ 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;
}
/**
- * @param InputInterface $input
- *
* @throws \Exception
*/
- private function init(InputInterface $input)
+ private function init(InputInterface $input): void
{
$initDir = $input->getOption('dir');
- if ($initDir === null) {
+ if (null === $initDir) {
$initDir = $this->configurationManager->getInitDirectory();
}
- if (strpos($initDir, '/') !== 0) {
- $initDir = $this->rootDir . '/' . $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')
- );
+ 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 948589a8..4b1eb65b 100644
--- a/Command/ImportCommand.php
+++ b/Command/ImportCommand.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->translator = $translator;
- $this->importManager = $importManager;
- $this->rootDir = $rootDir;
}
protected function configure()
@@ -117,12 +88,9 @@ protected function configure()
}
/**
- * @param InputInterface $input
- * @param OutputInterface $output
- *
* @return void
*/
- protected function execute(InputInterface $input, OutputInterface $output)
+ protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->symfonyStyle = new SymfonyStyle($input, $output);
try {
@@ -131,28 +99,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->addFilesToProcess();
$this->importManager->setSymfonyStyle($this->symfonyStyle);
$this->importManager->processData($this->importTypes);
+ } catch (\Exception $exception) {
+ $this->symfonyStyle->error($exception->getMessage());
- } catch (\Exception $e) {
- $this->symfonyStyle->error($e->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;
}
- private function addFilesToProcess()
+ private function addFilesToProcess(): void
{
$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(
@@ -164,6 +125,7 @@ private function addFilesToProcess()
} else {
$finder->name(['*.yaml', '*.yml']);
}
+
foreach ($finder as $file) {
try {
$this->importManager->addFileToProcess($file);
@@ -174,36 +136,31 @@ private function addFilesToProcess()
}
/**
- * @param InputInterface $input
- *
* @throws \Exception
*/
- private function init(InputInterface $input)
+ private function init(InputInterface $input): void
{
$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,11 +169,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');
@@ -225,21 +181,18 @@ private function init(InputInterface $input)
/**
* @param string $dir
*
- * @return string
- *
* @throws \Exception
*/
- private function getDirFullPath($dir)
+ private function getDirFullPath($dir): string
{
- if (strpos($dir, '/') !== 0) {
- $dir = $this->rootDir . '/' . $dir;
+ if (!str_starts_with($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 b7ff9655..3612b387 100644
--- a/Controller/ContentController.php
+++ b/Controller/ContentController.php
@@ -1,5 +1,7 @@
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();
@@ -109,11 +53,9 @@ public function addFieldAction()
}
/**
- * @param Request $request
- *
* @return Response
*/
- public function fieldFormAction(Request $request)
+ public function fieldForm(Request $request)
{
$element = $this->elementManager->getElementByCode($request->get('type'));
$elementData = [];
@@ -139,12 +81,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();
}
@@ -158,14 +100,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([
@@ -180,15 +122,14 @@ public function fieldFormAction(Request $request)
}
/**
- * @param Request $request
* @return JsonResponse
*/
- public function saveDraftAction(Request $request)
+ public function saveDraft(Request $request)
{
$id = $request->get('id');
$content = $this->contentManager->getContentById($id);
- if ($content === null) {
+ if (null === $content) {
return new JsonResponse([
'success' => false,
]);
@@ -227,22 +168,20 @@ public function saveDraftAction(Request $request)
}
/**
- * @param Request $request
- *
* @return JsonResponse
*/
- public function deleteVersionAction(Request $request)
+ public function deleteVersion(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..f67a4621 100644
--- a/Controller/Crud/ContentController.php
+++ b/Controller/Crud/ContentController.php
@@ -1,5 +1,7 @@
em = $em;
- $this->contentManager = $contentManager;
- $this->configurationManager = $configurationManager;
}
/**
- * @param int $id
- * @param Request $request
+ * @param int $id
*
* @return Response
*/
- public function editAction($id, Request $request)
+ public function edit($id, Request $request): RedirectResponse|Response
{
$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,29 +55,26 @@ 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)
+ public function create(Request $request): RedirectResponse|Response
{
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, [
@@ -121,10 +96,7 @@ public function createAction(Request $request)
]);
}
- /**
- * @return Response
- */
- public function listAction()
+ public function list(): Response
{
$contents = $this->contentManager->getContents();
@@ -138,14 +110,12 @@ public function listAction()
*
* @return Response
*/
- public function deleteAction($id)
+ public function delete($id): RedirectResponse
{
$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);
@@ -156,17 +126,13 @@ public function deleteAction($id)
/**
* @param int $id
- *
- * @return Response
*/
- public function showAction($id)
+ public function show($id): Response
{
$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..e11368e7 100644
--- a/Controller/Crud/PageController.php
+++ b/Controller/Crud/PageController.php
@@ -1,5 +1,7 @@
em = $em;
- $this->configurationManager = $configurationManager;
- $this->pageManager = $pageManager;
}
/**
- * @param int $id
- * @param Request $request
+ * @param int $id
*
* @return Response
*/
- public function editAction($id, Request $request)
+ public function edit($id, Request $request): RedirectResponse|Response
{
$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,23 +54,20 @@ public function editAction($id, Request $request)
}
/**
- * @param Request $request
- *
* @return Response
*/
- public function createAction(Request $request)
+ public function create(Request $request): RedirectResponse|Response
{
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, [
@@ -114,10 +88,7 @@ public function createAction(Request $request)
]);
}
- /**
- * @return Response
- */
- public function listAction()
+ public function list(): Response
{
$pages = $this->em->getRepository($this->configurationManager->getEntityClass('page'))->findAll();
@@ -131,14 +102,12 @@ public function listAction()
*
* @return Response
*/
- public function deleteAction($id)
+ public function delete($id): RedirectResponse
{
$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 bcb3659f..9364cbe4 100644
--- a/Controller/Crud/ScopeController.php
+++ b/Controller/Crud/ScopeController.php
@@ -1,35 +1,22 @@
em = $em;
- $this->configurationManager = $configurationManager;
}
/**
@@ -37,14 +24,12 @@ public function __construct(
*
* @return Response
*/
- public function deleteAction($id)
+ public function delete($id): RedirectResponse
{
$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..5b631de6 100644
--- a/Controller/PageController.php
+++ b/Controller/PageController.php
@@ -1,5 +1,7 @@
em = $em;
- $this->configurationManager = $configurationManager;
- $this->pageManager = $pageManager;
- $this->versionManager = $versionManager;
- $this->formFactory = $formFactory;
}
/**
- * @param Request $request
* @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);
- if ($page === null) {
+ if (null === $page) {
return new JsonResponse([
'success' => false,
]);
@@ -115,22 +79,20 @@ public function saveDraftAction(Request $request)
}
/**
- * @param 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);
- 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..f8e5efad 100644
--- a/Controller/ToolsController.php
+++ b/Controller/ToolsController.php
@@ -1,5 +1,7 @@
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): RedirectResponse|Response
{
$importForm = $this->createForm(ImportType::class, null, [
'action' => $this->generateUrl('sherlockode_acb_tools_import'),
@@ -86,7 +48,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 +57,21 @@ 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 +80,16 @@ 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,11 +103,9 @@ public function indexAction(Request $request)
}
/**
- * @param Request $request
- *
* @return Response
*/
- public function importAction(Request $request)
+ public function import(Request $request): RedirectResponse
{
$form = $this->createForm(ImportType::class);
@@ -161,6 +121,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());
@@ -171,11 +132,9 @@ public function importAction(Request $request)
}
/**
- * @param Request $request
- *
* @return Response
*/
- public function exportAction(Request $request)
+ public function export(Request $request): Response|RedirectResponse
{
$form = $this->createForm(ExportType::class);
@@ -215,14 +174,12 @@ public function exportAction(Request $request)
*
* @return Response
*/
- public function deletePageTypeAction($id)
+ public function deletePageType($id): RedirectResponse
{
$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 ae9fa4e7..00a49344 100644
--- a/DependencyInjection/Compiler/ElementPass.php
+++ b/DependencyInjection/Compiler/ElementPass.php
@@ -1,5 +1,7 @@
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..4fbbbed1 100644
--- a/DependencyInjection/Compiler/FormThemePass.php
+++ b/DependencyInjection/Compiler/FormThemePass.php
@@ -1,5 +1,7 @@
has('twig')) {
return;
@@ -18,6 +20,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/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 9f7bdb0c..a2087b77 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -1,22 +1,18 @@
getRootNode();
diff --git a/DependencyInjection/SherlockodeAdvancedContentExtension.php b/DependencyInjection/SherlockodeAdvancedContentExtension.php
index 23c5cbce..66d9910e 100644
--- a/DependencyInjection/SherlockodeAdvancedContentExtension.php
+++ b/DependencyInjection/SherlockodeAdvancedContentExtension.php
@@ -1,5 +1,7 @@
load('services.xml');
$loader->load('controllers.xml');
$loader->load('field_types.xml');
@@ -60,12 +62,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..3ab5426c 100644
--- a/Doctrine/MigrationHelper.php
+++ b/Doctrine/MigrationHelper.php
@@ -1,5 +1,7 @@
em = $em;
- $this->mapping = $mapping;
+ public function __construct(
+ private readonly EntityManagerInterface $em,
+ private array $mapping,
+ ) {
}
/**
- * @param string $slug
- *
- * @return int|null
- *
* @throws DriverException
* @throws DBALException
*/
@@ -56,17 +40,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,22 +54,16 @@ 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);
+ return json_decode((string) $raw, true);
}
return null;
}
/**
- * @param string $slug
- * @param array $data
- * @param string|null $name
- *
- * @return int
- *
* @throws DriverException
* @throws DBALException
*/
@@ -103,7 +77,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 +105,6 @@ public function writeContent(string $slug, array $data, ?string $name = null): i
}
/**
- * @param string $slug
- *
- * @return void
- *
* @throws DriverException
* @throws DBALException
*/
@@ -148,10 +118,6 @@ public function removeContent(string $slug): void
}
/**
- * @param string $identifier
- *
- * @return int|null
- *
* @throws DriverException
* @throws DBALException
*/
@@ -174,18 +140,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,23 +156,16 @@ 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);
+ return json_decode((string) $raw, true);
}
return null;
}
/**
- * @param string $identifier
- * @param array $data
- * @param string|null $name
- * @param int $status
- *
- * @return int
- *
* @throws DriverException
* @throws DBALException
*/
@@ -218,7 +173,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 +201,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 +231,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 +253,6 @@ public function writePage(
}
/**
- * @param string $identifier
- *
- * @return void
- *
* @throws DriverException
* @throws DBALException
*/
@@ -342,10 +293,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..a9ecf215 100644
--- a/Doctrine/MigrationHelperAwareInterface.php
+++ b/Doctrine/MigrationHelperAwareInterface.php
@@ -1,12 +1,12 @@
add('elementType', HiddenType::class);
$builder->add('position', HiddenType::class);
diff --git a/Element/ElementInterface.php b/Element/ElementInterface.php
index e92d6081..49c3200a 100644
--- a/Element/ElementInterface.php
+++ b/Element/ElementInterface.php
@@ -1,5 +1,7 @@
uploadedFile = $uploadedFile;
- $this->fileName = $fileName;
+ public function __construct(
+ private readonly UploadedFile $uploadedFile,
+ private readonly string $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 7492e298..8ee11201 100644
--- a/EventListener/AcbFileListener.php
+++ b/EventListener/AcbFileListener.php
@@ -1,9 +1,9 @@
uploadManager = $uploadManager;
}
/**
@@ -40,20 +28,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..36eeb4dd 100644
--- a/EventListener/ContentListener.php
+++ b/EventListener/ContentListener.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private readonly ConfigurationManager $configurationManager,
+ private readonly VersionManager $versionManager,
+ ) {
}
- /**
- * @param LifecycleEventArgs $args
- */
- public function postLoad(LifecycleEventArgs $args)
+ public function postLoad(LifecycleEventArgs $args): void
{
$entity = $args->getEntity();
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)
+ public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$entities = [
...$uow->getScheduledEntityInsertions(),
- ...$uow->getScheduledEntityUpdates()
+ ...$uow->getScheduledEntityUpdates(),
];
$contentVersionClassMetadata = $em->getClassMetadata($this->configurationManager->getEntityClass('content_version'));
@@ -66,7 +49,8 @@ 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..a8150f8d 100644
--- a/EventListener/PageListener.php
+++ b/EventListener/PageListener.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->versionManager = $versionManager;
+ public function __construct(
+ private readonly ConfigurationManager $configurationManager,
+ private readonly VersionManager $versionManager,
+ ) {
}
- /**
- * @param LifecycleEventArgs $args
- */
- public function postLoad(LifecycleEventArgs $args)
+ public function postLoad(LifecycleEventArgs $args): void
{
$entity = $args->getEntity();
@@ -44,12 +29,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 +47,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,10 +57,7 @@ public function postLoad(LifecycleEventArgs $args)
}
}
- /**
- * @param LifecycleEventArgs $args
- */
- public function prePersist(LifecycleEventArgs $args)
+ public function prePersist(LifecycleEventArgs $args): void
{
$object = $args->getObject();
@@ -83,22 +65,19 @@ 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)
+ public function onFlush(OnFlushEventArgs $args): void
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
$entities = [
...$uow->getScheduledEntityInsertions(),
- ...$uow->getScheduledEntityUpdates()
+ ...$uow->getScheduledEntityUpdates(),
];
$pages = [];
@@ -107,11 +86,13 @@ 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();
}
}
@@ -128,10 +109,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 ad676804..b93ab8cd 100644
--- a/EventListener/VersionListener.php
+++ b/EventListener/VersionListener.php
@@ -1,5 +1,7 @@
getEntity();
@@ -20,7 +19,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();
@@ -33,12 +32,15 @@ public function prePersist(LifecycleEventArgs $args)
if (!$version->isAutoSave()) {
continue;
}
+
if ($version->getUserId() !== $entity->getUserId()) {
continue;
}
+
if ($version->getCreatedAt() < $entity->getCreatedAt()) {
- $count++;
+ ++$count;
}
+
if ($count >= 10) {
// Keep only the last 10 drafts by same user
$args->getEntityManager()->remove($version);
diff --git a/Exception/InvalidElementException.php b/Exception/InvalidElementException.php
index 09f95923..21df2398 100644
--- a/Exception/InvalidElementException.php
+++ b/Exception/InvalidElementException.php
@@ -1,9 +1,11 @@
elementExport = $elementExport;
- $this->scopeExport = $scopeExport;
+ public function __construct(
+ private readonly ElementExport $elementExport,
+ private readonly ScopeExport $scopeExport,
+ ) {
}
- /**
- * @param ContentInterface $content
- *
- * @return array
- */
- public function exportData(ContentInterface $content)
+ public function exportData(ContentInterface $content): array
{
$data = [];
$data['name'] = $content->getName();
@@ -51,15 +34,14 @@ 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 [];
}
- if (count($elements) === 0) {
+
+ if ([] === $elements) {
return [];
}
diff --git a/Export/ElementExport.php b/Export/ElementExport.php
index 1715ab0d..c234aa29 100644
--- a/Export/ElementExport.php
+++ b/Export/ElementExport.php
@@ -1,5 +1,7 @@
elementManager = $elementManager;
- $this->translator = $translator;
+ public function __construct(
+ private readonly ElementManager $elementManager,
+ private readonly TranslatorInterface $translator,
+ ) {
}
- /**
- * @param array $elementData
- *
- * @return array
- */
public function getElementExportData(array $elementData): array
{
if (!isset($elementData['elementType'])) {
@@ -50,7 +33,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,12 +42,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);
@@ -74,6 +51,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'])) {
@@ -81,6 +59,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) {
@@ -94,19 +73,15 @@ 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];
}
/**
- * @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..a4d241c6 100644
--- a/Export/PageExport.php
+++ b/Export/PageExport.php
@@ -1,5 +1,7 @@
scopeExport = $scopeExport;
}
- /**
- * @param PageInterface $page
- *
- * @return array
- */
- public function exportData(PageInterface $page)
+ public function exportData(PageInterface $page): array
{
$data = [];
$data['status'] = $page->getStatus();
if ($page->getPageType() instanceof PageTypeInterface) {
$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,10 +47,7 @@ public function exportData(PageInterface $page)
return $data;
}
- /**
- * @param ContentExport $contentExport
- */
- 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 62303d46..771bbb1b 100644
--- a/Export/ScopeExport.php
+++ b/Export/ScopeExport.php
@@ -1,5 +1,7 @@
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 476a40a3..a42767da 100644
--- a/FieldType/AbstractFieldType.php
+++ b/FieldType/AbstractFieldType.php
@@ -1,5 +1,7 @@
getCode() . '.label';
+ return 'field_type.'.$this->getCode().'.label';
}
+ #[\Override]
public function getIconClass()
{
return $this->configData['icon'] ?? $this->getDefaultIconClass();
@@ -36,7 +39,7 @@ public function getIconClass()
*/
public function getFrontTemplate()
{
- return '@SherlockodeAdvancedContent/Field/front/' . $this->getCode() . '.html.twig';
+ return '@SherlockodeAdvancedContent/Field/front/'.$this->getCode().'.html.twig';
}
/**
@@ -44,7 +47,7 @@ public function getFrontTemplate()
*/
public function getPreviewTemplate()
{
- return '@SherlockodeAdvancedContent/Field/preview/'. $this->getCode() .'.html.twig';
+ return '@SherlockodeAdvancedContent/Field/preview/'.$this->getCode().'.html.twig';
}
/**
@@ -56,13 +59,10 @@ public function getPreviewPicture()
}
/**
- * Add element's field(s) to content form
- *
- * @param FormBuilderInterface $builder
- *
- * @return void
+ * Add element's field(s) to content form.
*/
- public function buildContentElement(FormBuilderInterface $builder)
+ #[\Override]
+ public function buildContentElement(FormBuilderInterface $builder): void
{
parent::buildContentElement($builder);
@@ -72,12 +72,12 @@ public function buildContentElement(FormBuilderInterface $builder)
));
$modelTransformer = $this->getValueModelTransformer();
- if ($modelTransformer !== null) {
+ if (null !== $modelTransformer) {
$builder->get('value')
->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()) {
@@ -103,7 +103,7 @@ public function getDefaultFormElementOptions()
}
/**
- * Get model transformer for value field
+ * Get model transformer for value field.
*
* @return null
*/
@@ -113,7 +113,7 @@ public function getValueModelTransformer()
}
/**
- * Get options to apply on element
+ * Get options to apply on element.
*
* @return array
*/
@@ -138,29 +138,20 @@ 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'] ?? [],
]);
}
- /**
- * @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..0dc9d8a0 100644
--- a/FieldType/AbstractInputType.php
+++ b/FieldType/AbstractInputType.php
@@ -1,31 +1,36 @@
$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 +39,7 @@ public function getFormElementOptions()
/**
* @return string
*/
+ #[\Override]
public function getFieldGroup()
{
return 'simple';
diff --git a/FieldType/Content.php b/FieldType/Content.php
index 7c84b899..256a216f 100644
--- a/FieldType/Content.php
+++ b/FieldType/Content.php
@@ -1,5 +1,7 @@
scopeHandler = $scopeHandler;
+ public function __construct(private readonly ScopeHandlerInterface $scopeHandler)
+ {
}
- /**
- * @return string
- */
- public function getFormFieldType()
+ public function getFormFieldType(): string
{
return AcbContentType::class;
}
/**
- * Get field's code
- *
- * @return string
+ * Get field's code.
*/
- public function getCode()
+ public function getCode(): string
{
return 'content';
}
@@ -45,16 +32,15 @@ public function getPreviewPicture(): ?string
}
/**
- * @param mixed $element
- *
* @return array
*/
+ #[\Override]
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..08fe82d6 100644
--- a/FieldType/FieldTypeInterface.php
+++ b/FieldType/FieldTypeInterface.php
@@ -1,5 +1,7 @@
urlBuilderManager = $urlBuilderManager;
}
- /**
- * @return string
- */
- public function getFormFieldType()
+ public function getFormFieldType(): string
{
return AcbFileType::class;
}
- protected function getDefaultIconClass()
+ #[\Override]
+ protected function getDefaultIconClass(): string
{
return 'fa-solid fa-paperclip';
}
/**
- * Get field's code
- *
- * @return string
+ * Get field's code.
*/
- public function getCode()
+ public function getCode(): string
{
return 'file';
}
@@ -48,21 +37,12 @@ public function getPreviewPicture(): ?string
return 'bundles/sherlockodeadvancedcontent/preview_picture/file.svg';
}
- /**
- * @param array $value
- *
- * @return string
- */
- protected function getFilename($value)
+ protected function getFilename(array $value): string
{
return $this->urlBuilderManager->getFileUrl($value['src'] ?? '');
}
- /**
- * @param mixed $element
- *
- * @return mixed
- */
+ #[\Override]
public function getRawValue($element)
{
$element['url'] = $this->getFilename($element);
diff --git a/FieldType/Iframe.php b/FieldType/Iframe.php
index f6fe70ba..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
+ * Get field's code.
*/
- public function getCode()
+ public function getCode(): string
{
return 'link';
}
@@ -55,11 +52,7 @@ public function getPreviewPicture(): ?string
return 'bundles/sherlockodeadvancedcontent/preview_picture/link.svg';
}
- /**
- * @param mixed $element
- *
- * @return mixed
- */
+ #[\Override]
public function getRawValue($element)
{
$url = $this->getUrlValue($element);
@@ -74,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 bf8d46f0..b12ae019 100644
--- a/FieldType/RelativeLink.php
+++ b/FieldType/RelativeLink.php
@@ -1,5 +1,7 @@
urlBuilderManager = $urlBuilderManager;
}
- public function getPreviewTemplate()
+ #[\Override]
+ public function getPreviewTemplate(): string
{
return '@SherlockodeAdvancedContent/Field/preview/link.html.twig';
}
/**
- * Get field's code
- *
- * @return string
+ * Get field's code.
*/
- public function getCode()
+ #[\Override]
+ public function getCode(): string
{
return 'relative_link';
}
+ #[\Override]
public function getPreviewPicture(): ?string
{
return 'bundles/sherlockodeadvancedcontent/preview_picture/relative_link.svg';
}
- /**
- * @return string
- */
- protected function getUrlFormType()
+ #[\Override]
+ protected function getUrlFormType(): string
{
return TextType::class;
}
/**
* @param array $value
- *
- * @return string
*/
- protected function getUrlValue($value)
+ #[\Override]
+ protected function getUrlValue($value): string
{
return $this->urlBuilderManager->getFullUrl($value['url'] ?? '');
}
diff --git a/FieldType/Separator.php b/FieldType/Separator.php
index 3a14abe4..31cba856 100644
--- a/FieldType/Separator.php
+++ b/FieldType/Separator.php
@@ -1,30 +1,28 @@
em = $em;
- $this->entityClass = $entityClass;
- $this->identifierField = $identifierField;
+ public function __construct(
+ private readonly EntityManagerInterface $em,
+ private $entityClass,
+ private $identifierField,
+ ) {
}
/**
- * Transforms a string into an entity
+ * Transforms a string into an entity.
*
* @param string $valueAsString
*
* @return object|null
*/
- public function transform($valueAsString)
+ public function transform($valueAsString): mixed
{
if (empty($valueAsString)) {
return null;
@@ -56,13 +42,13 @@ public function transform($valueAsString)
}
/**
- * Transforms an entity into a string
+ * Transforms an entity into a string.
*
* @param object $entity
*
* @return string
*/
- public function reverseTransform($entity)
+ public function reverseTransform($entity): mixed
{
if (empty($entity)) {
return null;
diff --git a/Form/Type/AcbContentType.php b/Form/Type/AcbContentType.php
index b8ede262..7fea3eef 100644
--- a/Form/Type/AcbContentType.php
+++ b/Form/Type/AcbContentType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->em = $em;
+ public function __construct(
+ private readonly ConfigurationManager $configurationManager,
+ private readonly EntityManagerInterface $em,
+ ) {
}
- /**
- * @param FormBuilderInterface $builder
- * @param array $options
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$contents = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findBy([
'page' => null,
diff --git a/Form/Type/AcbFileType.php b/Form/Type/AcbFileType.php
index b9e35982..f79602d8 100644
--- a/Form/Type/AcbFileType.php
+++ b/Form/Type/AcbFileType.php
@@ -1,5 +1,7 @@
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)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$mimeTypeChoices = $options['mime_types'] ?? $this->mimeTypeManager->generateMimeTypeChoices();
$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))];
- },
- 'attr' => ['data-mime-type-restriction' => '']
+ '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)) {
@@ -87,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();
@@ -96,6 +76,7 @@ function (FormEvent $event) use ($options) {
$this->uploadManager->remove($data['src']);
unset($data['src']);
}
+
unset($data['delete']);
}
@@ -115,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()) {
@@ -132,15 +113,7 @@ function (FormEvent $event) use ($options) {
});
}
- /**
- * @param FormInterface $form
- * @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'] = '';
@@ -168,8 +141,9 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal
$mimeTypes[] = $this->mimeTypeManager->getMimeTypesByCode($type);
}
- $mimeTypes = array_merge([], ...$mimeTypes);
+ $mimeTypes = array_merge([], ...array_values($mimeTypes));
}
+
$options['file_constraints'][] = new File(null, null, null, $mimeTypes);
$form
@@ -177,7 +151,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,10 +168,7 @@ private function updateForm(FormInterface $form, $data, $options, $hasFile = fal
}
}
- /**
- * @param OptionsResolver $resolver
- */
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'translation_domain' => 'AdvancedContentBundle',
@@ -208,13 +179,13 @@ 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
* @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)) {
@@ -228,6 +199,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..1485434c 100644
--- a/Form/Type/ColumnType.php
+++ b/Form/Type/ColumnType.php
@@ -1,5 +1,7 @@
1,
@@ -105,6 +107,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..71dd54b4 100644
--- a/Form/Type/ContentDataType.php
+++ b/Form/Type/ContentDataType.php
@@ -1,16 +1,20 @@
configurationManager = $configurationManager;
- $this->urlGenerator = $urlGenerator;
- $this->scopeHandler = $scopeHandler;
- $this->translator = $translator;
}
- /**
- * @param FormBuilderInterface $builder
- * @param array $options
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$token = uniqid('content_');
@@ -98,14 +66,15 @@ 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): void {
$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
->add('slug', TextType::class, [
'label' => 'content.form.slug',
@@ -115,7 +84,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')) {
@@ -123,7 +92,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 +111,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
});
- $builder->get('data')->addEventListener(FormEvents::PRE_SUBMIT, function(FormEvent $event) {
- $event->setData(json_decode($event->getData(), true));
+ $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();
@@ -165,16 +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;
}
- /**
- * @param OptionsResolver $resolver
- */
- 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 655cfbc6..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 a93a8efe..bb1f8c89 100644
--- a/Form/Type/ElementType.php
+++ b/Form/Type/ElementType.php
@@ -1,5 +1,7 @@
buildContentElement($builder);
$builder->add('extra', FormType::class, [
@@ -29,16 +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();
}
- /**
- * @param OptionsResolver $resolver
- */
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['element_type']);
$resolver->setDefaults([
@@ -46,6 +41,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 2516b7ea..5aece40e 100644
--- a/Form/Type/ElementsType.php
+++ b/Form/Type/ElementsType.php
@@ -1,5 +1,7 @@
elementManager = $elementManager;
- $this->configurationManager = $configurationManager;
- $this->translator = $translator;
}
- /**
- * @param FormBuilderInterface $builder
- * @param array $options
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
- $builder->addEventListener(FormEvents::PRE_SET_DATA, function(FormEvent $event) use ($options) {
+ $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
$data = $event->getData();
$form = $event->getForm();
if (!$data) {
@@ -60,15 +35,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$i = 0;
foreach ($data as $name => $element) {
$field = $this->elementManager->getElementByCode($element['elementType']);
- $form->add($i++, ElementType::class, [
- 'label' => $field->getFormFieldLabel(),
+ $form->add((string) $i++, ElementType::class, [
+ '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): void {
$form = $event->getForm();
$data = $event->getData();
if (!is_array($data)) {
@@ -81,11 +56,12 @@ public function buildForm(FormBuilderInterface $builder, array $options)
foreach ($form as $child) {
$form->remove($child->getName());
}
+
$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.']',
]);
@@ -93,30 +69,32 @@ public function buildForm(FormBuilderInterface $builder, array $options)
}
});
- $builder->addEventListener(FormEvents::SUBMIT, function(FormEvent $event) use ($options) {
+ $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event): void {
$form = $event->getForm();
$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 ($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',
@@ -131,10 +109,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
});
}
- /**
- * @param OptionsResolver $resolver
- */
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'translation_domain' => 'AdvancedContentBundle',
@@ -142,6 +117,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..855f6b30 100644
--- a/Form/Type/EntityType.php
+++ b/Form/Type/EntityType.php
@@ -1,5 +1,7 @@
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 a1f9d7f5..6709733e 100644
--- a/Form/Type/ExportType.php
+++ b/Form/Type/ExportType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
}
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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'],
@@ -53,11 +44,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',
@@ -67,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 b04367a9..3a0c1179 100644
--- a/Form/Type/ImageType.php
+++ b/Form/Type/ImageType.php
@@ -1,5 +1,7 @@
mimeTypeManager = $mimeTypeManager;
}
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->remove('title');
$builder
@@ -37,6 +30,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/**
* @return string
*/
+ #[\Override]
public function getParent()
{
return AcbFileType::class;
@@ -45,19 +39,17 @@ public function getParent()
/**
* @return string
*/
+ #[\Override]
public function getBlockPrefix()
{
return 'acb_image';
}
- /**
- * @param OptionsResolver $resolver
- */
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$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/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 c837b2e2..13ec6d5e 100644
--- a/Form/Type/LinkType.php
+++ b/Form/Type/LinkType.php
@@ -1,5 +1,7 @@
add('url', $options['url_form_type'], [
@@ -29,10 +31,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
;
}
- /**
- * @param OptionsResolver $resolver
- */
- 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 1346364d..5247c6ba 100644
--- a/Form/Type/PageMetaType.php
+++ b/Form/Type/PageMetaType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
}
- /**
- * @inheritDoc
- */
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$token = uniqid('page_meta_');
$builder
@@ -69,14 +59,15 @@ 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): void {
$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
->add('slug', TextType::class, [
'label' => 'page.form.slug',
@@ -93,10 +84,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
});
}
- /**
- * @inheritDoc
- */
- 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 b95a84a3..cf8b7a27 100644
--- a/Form/Type/PageType.php
+++ b/Form/Type/PageType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->scopeHandler = $scopeHandler;
- $this->translator = $translator;
}
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('pageIdentifier', TextType::class, [
@@ -66,7 +45,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 +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();
@@ -100,17 +79,18 @@ 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();
- 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();
@@ -125,6 +105,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
));
}
}
+
if (!$this->scopeHandler->isPageIdentifierValid($page)) {
if ($this->configurationManager->isScopesEnabled()) {
$form->get('pageIdentifier')->addError(new FormError(
@@ -138,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
@@ -147,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'),
@@ -155,6 +136,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 9b2a2a31..c75682bb 100644
--- a/Form/Type/PageTypeType.php
+++ b/Form/Type/PageTypeType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
}
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
@@ -36,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 d1218942..e9a54597 100644
--- a/Form/Type/PictureEntryType.php
+++ b/Form/Type/PictureEntryType.php
@@ -1,5 +1,7 @@
remove('alt');
$builder->remove('mime_type');
@@ -26,12 +28,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
- function (FormEvent $event) use ($options) {
+ function (FormEvent $event): void {
$data = $event->getData();
if (isset($data['mime_type'])) {
// Remove mime type data to prevent form extra fields error
unset($data['mime_type']);
}
+
$event->setData($data);
},
1
@@ -41,6 +44,7 @@ function (FormEvent $event) use ($options) {
/**
* @return string
*/
+ #[\Override]
public function getParent()
{
return ImageType::class;
diff --git a/Form/Type/PictureType.php b/Form/Type/PictureType.php
index f816df5f..864699bc 100644
--- a/Form/Type/PictureType.php
+++ b/Form/Type/PictureType.php
@@ -1,5 +1,7 @@
add('image', ImageType::class, [
@@ -32,11 +34,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addEventListener(
FormEvents::PRE_SUBMIT,
- function (FormEvent $event) use ($options) {
+ function (FormEvent $event): void {
$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;
}
}
@@ -46,10 +48,7 @@ function (FormEvent $event) use ($options) {
);
}
- /**
- * @param OptionsResolver $resolver
- */
- 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 3c6afe15..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'=> [],
+ '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 fe95cfb8..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',
@@ -45,7 +47,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,
]);
@@ -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) {
@@ -64,8 +66,8 @@ 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()),
- 'position' => $i
+ 'child_form' => $child->getConfig()->getType()->getInnerType()::class,
+ 'position' => $i,
]);
}
}
@@ -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 = [];
@@ -83,14 +85,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 (array $a, array $b): int => $a['position'] <=> $b['position']);
// unset the position key in the saved data
$orderedData = array_map(function ($item) {
@@ -100,6 +103,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$item = $item['wrapped_child'];
}
}
+
return $item;
}, $orderedData);
@@ -107,12 +111,13 @@ public function buildForm(FormBuilderInterface $builder, array $options)
});
}
+ #[\Override]
public function getParent()
{
return CollectionType::class;
}
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'allow_add' => true,
@@ -123,6 +128,7 @@ public function configureOptions(OptionsResolver $resolver)
]);
}
+ #[\Override]
public function getBlockPrefix()
{
return 'acb_field_collection';
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 ab68259a..70aa3530 100644
--- a/Form/Type/ScopeChoiceType.php
+++ b/Form/Type/ScopeChoiceType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->scopeHandler = $scopeHandler;
}
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'class' => $this->configurationManager->getEntityClass('scope'),
@@ -48,9 +31,7 @@ public function configureOptions(OptionsResolver $resolver)
]);
}
- /**
- * {@inheritdoc}
- */
+ #[\Override]
public function getParent(): ?string
{
return EntityType::class;
diff --git a/Form/Type/ScopeType.php b/Form/Type/ScopeType.php
index f62664c8..ae76b5bb 100644
--- a/Form/Type/ScopeType.php
+++ b/Form/Type/ScopeType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
}
- public function buildForm(FormBuilderInterface $builder, array $options)
+ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('locale', TextType::class, [
@@ -36,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 222398f1..114663e2 100644
--- a/Form/Type/WysiwygType.php
+++ b/Form/Type/WysiwygType.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
}
- public function configureOptions(OptionsResolver $resolver)
+ public function configureOptions(OptionsResolver $resolver): void
{
$toolbar = $this->configurationManager->getDefaultWysiwygToolbar();
$resolver->setDefaults([
@@ -30,6 +23,7 @@ public function configureOptions(OptionsResolver $resolver)
]);
}
+ #[\Override]
public function getParent()
{
return CKEditorType::class;
diff --git a/Import/AbstractImport.php b/Import/AbstractImport.php
index 44a99fbd..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();
}
@@ -107,13 +79,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())
;
}
@@ -139,35 +112,25 @@ 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'
- ));
+ if ([] !== $scopesData) {
+ 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,42 +138,32 @@ 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);
}
$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): int => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier());
if (count($result) === count($scopes)) {
return $existingEntity;
}
- if (count($result) > 0) {
- if ($entity !== null) {
- throw new \Exception($this->translator->trans(
- 'init.errors.multiple_entities_same_scope',
- [],
- 'AdvancedContentBundle'
- ));
+ if ([] !== $result) {
+ if (null !== $entity) {
+ throw new \Exception($this->translator->trans('init.errors.multiple_entities_same_scope', [], 'AdvancedContentBundle'));
}
+
$entity = $existingEntity;
}
}
@@ -219,7 +172,6 @@ protected function getExistingScopableEntity(string $entityClass, array $criteri
}
/**
- * @param ScopableInterface $entity
* @param array|ScopeInterface[] $scopes
*/
protected function updateEntityScopes(ScopableInterface $entity, array $scopes): void
@@ -231,8 +183,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 5800e965..28cdc56a 100644
--- a/Import/ContentImport.php
+++ b/Import/ContentImport.php
@@ -1,5 +1,7 @@
elementImport = $elementImport;
}
/**
@@ -49,14 +37,14 @@ 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;
}
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 +63,7 @@ protected function importEntity($slug, $contentData)
} else {
$this->errors[] = $this->translator->trans('content.errors.duplicate_slug_no_scope', [], 'AdvancedContentBundle');
}
+
return;
}
@@ -82,11 +71,7 @@ protected function importEntity($slug, $contentData)
$this->em->flush();
}
- /**
- * @param array $elementsData
- * @param ContentInterface $content
- */
- public function createElements(array $elementsData, ContentInterface $content)
+ public function createElements(array $elementsData, ContentInterface $content): void
{
$elements = [];
$position = 0;
@@ -97,13 +82,14 @@ public function createElements(array $elementsData, ContentInterface $content)
$this->errors[] = sprintf('%s : %s', $content->getName(), $e->getMessage());
}
}
+
$content->setData($elements);
}
/**
* @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 9568cb57..b44f37e0 100644
--- a/Import/ElementImport.php
+++ b/Import/ElementImport.php
@@ -1,5 +1,7 @@
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)
+ public function getElementImportData(array $elementData, int $position = 0): array
{
if (!isset($elementData['type'])) {
throw new \Exception($this->translator->trans('init.errors.element_missing_type', [], 'AdvancedContentBundle'));
@@ -85,7 +46,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([
@@ -95,12 +56,13 @@ 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 ($element->getValueModelTransformer() !== null) {
+ if (null !== $element->getValueModelTransformer()) {
$value = [];
}
+
if (isset($elementData['value'])) {
$value = $elementData['value'];
if (is_array($value)) {
@@ -111,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 = [];
@@ -126,43 +88,38 @@ private function getLayoutTypeImportData(LayoutTypeInterface $element, array $el
];
}
- private function processValueArray(array $data)
+ private function processValueArray(array $data): array
{
if (isset($data['_file'])) {
// handle file
$result = $this->processFileUpload($data);
- if ($result !== false) {
+ if (false !== $result) {
$data = $result;
}
}
+
if (isset($data['content'])) {
$slug = $data['content'];
$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'));
}
}
// 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;
}
- private function processFileUpload(array $data)
+ private function processFileUpload(array $data): array
{
- $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'));
}
@@ -182,17 +139,17 @@ 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 (!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')
- );
+ throw new \Exception($this->translator->trans('init.errors.init_dir', ['%dir%' => $filesDirectory], 'AdvancedContentBundle'));
}
- $this->filesDirectory = $filesDirectory . '/';
+
+ $this->filesDirectory = $filesDirectory.'/';
}
return $this->filesDirectory;
@@ -201,7 +158,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 364b87ff..0d87f8e8 100644
--- a/Import/ImportResult.php
+++ b/Import/ImportResult.php
@@ -1,28 +1,24 @@
status = self::UNKNOWN;
- }
-
/**
* @return int
*/
@@ -31,18 +27,15 @@ public function getStatus()
return $this->status;
}
- /**
- * @return bool
- */
- public function isSuccess()
+ public function isSuccess(): bool
{
- return $this->status == self::SUCCESS;
+ return self::SUCCESS == $this->status;
}
/**
* @return $this
*/
- public function success()
+ public function success(): static
{
$this->status = self::SUCCESS;
@@ -52,7 +45,7 @@ public function success()
/**
* @return $this
*/
- public function failure()
+ public function failure(): static
{
$this->status = self::FAILURE;
@@ -72,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 1463836f..eaf34c59 100644
--- a/Import/PageImport.php
+++ b/Import/PageImport.php
@@ -1,5 +1,7 @@
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;
}
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 +48,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');
@@ -61,21 +60,23 @@ 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'];
+ $pageType = new $this->entityClasses['page_type']();
$pageType->setName($pageData['pageType']);
$this->em->persist($pageType);
}
}
+
$page->setPageType($pageType);
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,11 +102,12 @@ 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);
$pageMeta->setSlug($slug);
$pageMeta->setMetaTitle($metaData['meta_title'] ?? null);
@@ -117,14 +119,17 @@ protected function importEntity($pageIdentifier, $pageData)
} else {
$this->errors[] = $this->translator->trans('page.errors.duplicate_identifier_no_scope', [], 'AdvancedContentBundle');
}
+
return;
}
+
if (!$this->scopeHandler->isPageSlugValid($page)) {
if ($this->configurationManager->isScopesEnabled()) {
$this->errors[] = $this->translator->trans('page.errors.duplicate_slug_scopes', [], 'AdvancedContentBundle');
} else {
$this->errors[] = $this->translator->trans('page.errors.duplicate_slug_no_scope', [], 'AdvancedContentBundle');
}
+
return;
}
@@ -135,11 +140,9 @@ protected function importEntity($pageIdentifier, $pageData)
}
/**
- * @param ContentImport $contentImport
- *
* @return $this
*/
- public function setContentImport(ContentImport $contentImport)
+ public function setContentImport(ContentImport $contentImport): static
{
$this->contentImport = $contentImport;
diff --git a/LayoutType/AbstractLayoutType.php b/LayoutType/AbstractLayoutType.php
index 557cac7b..01d8b0b1 100644
--- a/LayoutType/AbstractLayoutType.php
+++ b/LayoutType/AbstractLayoutType.php
@@ -1,5 +1,7 @@
getCode() . '.label';
+ return 'layout_type.'.$this->getCode().'.label';
}
/**
@@ -21,7 +23,7 @@ public function getFormFieldLabel()
*/
public function getFrontTemplate()
{
- return '@SherlockodeAdvancedContent/Layout/front/' . $this->getCode() . '.html.twig';
+ return '@SherlockodeAdvancedContent/Layout/front/'.$this->getCode().'.html.twig';
}
/**
@@ -29,17 +31,14 @@ 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
- *
- * @return void
+ * Add element's field(s) to content form.
*/
- public function buildContentElement(FormBuilderInterface $builder)
+ #[\Override]
+ public function buildContentElement(FormBuilderInterface $builder): void
{
parent::buildContentElement($builder);
@@ -51,7 +50,7 @@ public function buildContentElement(FormBuilderInterface $builder)
]);
$configurationFormType = $this->getConfigurationFormType();
- if ($configurationFormType !== null) {
+ if (null !== $configurationFormType) {
$builder->add('config', $configurationFormType, [
'label' => false,
]);
@@ -66,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): int => ($a['position'] ?? 0) <=> ($b['position'] ?? 0));
return [
'elements' => $elements,
@@ -78,9 +75,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 08c1e0bc..2785aa63 100644
--- a/LayoutType/Column.php
+++ b/LayoutType/Column.php
@@ -1,24 +1,24 @@
config = $config;
}
/**
- * Get entity class configuration for given type
+ * Get entity class configuration for given type.
*
* @param string $type
*
@@ -45,9 +45,6 @@ public function getEntityClasses()
return $this->config['entity_class'];
}
- /**
- * @return mixed
- */
public function getImageDirectory()
{
return $this->config['upload']['image_directory'];
@@ -101,12 +98,7 @@ public function isScopesEnabled()
return $this->config['scopes']['enabled'];
}
- /**
- * @param string $option
- *
- * @return mixed
- */
- 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 15bcaf64..c473357e 100644
--- a/Manager/ContentManager.php
+++ b/Manager/ContentManager.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->em = $em;
- $this->slugProvider = $slugProvider;
}
/**
- * 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 +33,7 @@ public function getContentById($id)
}
/**
- * Get all contents
+ * Get all contents.
*
* @return array
*/
@@ -62,11 +42,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..46ed0b51 100644
--- a/Manager/ElementManager.php
+++ b/Manager/ElementManager.php
@@ -1,5 +1,7 @@
elements = [];
- $this->fieldsConfiguration = $fieldsConfiguration;
}
/**
- * Add field type
- *
- * @param FieldTypeInterface $fieldType
+ * Add field type.
*/
- public function addFieldType(FieldTypeInterface $fieldType)
+ public function addFieldType(FieldTypeInterface $fieldType): void
{
$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()]);
}
+
if ($enabled) {
$this->elements[$fieldType->getCode()] = $fieldType;
}
}
/**
- * Get available field types
- *
- * @return array
+ * Get available field types.
*/
- public function getGroupedFieldTypes()
+ public function getGroupedFieldTypes(): array
{
$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] = [];
}
+
$choices[$fieldGroup][$element->getFormFieldLabel()] = $element;
}
}
@@ -66,17 +60,15 @@ public function getGroupedFieldTypes()
}
/**
- * Add layout type
- *
- * @param LayoutTypeInterface $layoutType
+ * Add layout type.
*/
- public function addLayoutType(LayoutTypeInterface $layoutType)
+ public function addLayoutType(LayoutTypeInterface $layoutType): void
{
$this->elements[$layoutType->getCode()] = $layoutType;
}
/**
- * Get element
+ * Get element.
*
* @param string $elementCode
*
@@ -89,6 +81,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..6d7d284c 100644
--- a/Manager/ExportManager.php
+++ b/Manager/ExportManager.php
@@ -1,5 +1,7 @@
pageExport = $pageExport;
- $this->contentExport = $contentExport;
$this->pageExport->setContentExport($this->contentExport);
}
/**
* @param array|PageInterface[] $pages
*/
- public function generatePagesData($pages)
+ public function generatePagesData($pages): void
{
foreach ($pages as $page) {
/** @var PageInterface $page */
$data = $this->pageExport->exportData($page);
- $this->addToFilesData($data, 'page_' . $page->getPageIdentifier());
+ $this->addToFilesData($data, 'page_'.$page->getPageIdentifier());
}
}
/**
* @param array|ContentInterface[] $contents
*/
- public function generateContentsData($contents)
+ public function generateContentsData($contents): void
{
foreach ($contents as $content) {
/** @var ContentInterface $content */
$data = $this->contentExport->exportData($content);
- $this->addToFilesData($data, 'content_' . $content->getSlug());
+ $this->addToFilesData($data, 'content_'.$content->getSlug());
}
}
/**
- * @param array $data
- * @param string $filename
+ * @param array $data
*/
- private function addToFilesData($data, $filename)
+ private function addToFilesData($data, string $filename): void
{
$data = Yaml::dump($data, 15);
- $this->filesData[$filename . '.yaml'] = $data;
+ $this->filesData[$filename.'.yaml'] = $data;
}
- /**
- * @param string $directory
- * @param bool $useDatePrefix
- */
- public function generateFiles($directory, $useDatePrefix = true)
+ public function generateFiles(string $directory, bool $useDatePrefix = true): void
{
$prefix = '';
if ($useDatePrefix) {
$prefix = date('Ymd-His_');
}
+
foreach ($this->filesData as $filename => $data) {
- file_put_contents($directory . $prefix . $filename, $data);
+ file_put_contents($directory.$prefix.$filename, $data);
}
}
- /**
- * @return string
- */
- public function generateZipFile()
+ public function generateZipFile(): string
{
- $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..960a1d59 100644
--- a/Manager/ImportManager.php
+++ b/Manager/ImportManager.php
@@ -1,9 +1,10 @@
'Page',
'contents' => 'Content',
];
- /**
- * @var ContentImport
- */
- private $contentImport;
-
- /**
- * @var PageImport
- */
- private $pageImport;
+ private array $dataToProcess;
- /**
- * @var TranslatorInterface
- */
- private $translator;
+ private ?SymfonyStyle $symfonyStyle = null;
- /**
- * @var array
- */
- private $dataToProcess;
-
- /**
- * @var SymfonyStyle
- */
- private $symfonyStyle;
-
- /**
- * @param PageImport $pageImport
- * @param ContentImport $contentImport
- * @param TranslatorInterface $translator
- */
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' => [
@@ -70,18 +42,16 @@ public function __construct(
}
/**
- * @param \SplFileInfo $file
- *
* @throws \Exception
*/
- public function addFileToProcess(\SplFileInfo $file)
+ public function addFileToProcess(\SplFileInfo $file): void
{
$filePath = $file->getRealPath();
$data = Yaml::parseFile($filePath);
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) {
@@ -95,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) {
@@ -104,7 +74,7 @@ public function processData($allowedTypes = [])
}
$nbEntities = count($dataToProcess['data']);
- if ($nbEntities === 0) {
+ if (0 === $nbEntities) {
continue;
}
@@ -141,16 +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);
}
- /**
- * @param SymfonyStyle $symfonyStyle
- */
- public function setSymfonyStyle(SymfonyStyle $symfonyStyle)
+ public function setSymfonyStyle(SymfonyStyle $symfonyStyle): void
{
$this->symfonyStyle = $symfonyStyle;
}
@@ -158,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 e1326884..8d9d055f 100644
--- a/Manager/MimeTypeManager.php
+++ b/Manager/MimeTypeManager.php
@@ -1,37 +1,31 @@
mimeTypes = $mimeTypes;
- $this->translator = $translator;
+ public const MIME_TYPE_ARCHIVE = 40;
+
+ public const MIME_TYPE_TEXT = 50;
+
+ public const MIME_TYPE_SPREADSHEET = 60;
+
+ public const MIME_TYPE_MULTIMEDIA = 70;
+
+ public function __construct(
+ private array $mimeTypes,
+ private readonly TranslatorInterface $translator,
+ ) {
}
/**
@@ -50,12 +44,7 @@ public function generateMimeTypeChoices(): array
];
}
- /**
- * @param string $code
- *
- * @return 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',
@@ -64,7 +53,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,43 +63,32 @@ 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;
}
foreach ($types as $type) {
- $extensions[] = basename($type);
+ $extensions[] = basename((string) $type);
}
return array_combine($extensions, $extensions);
}
- /**
- * @return array
- */
public function getAllMimeTypes(): array
{
- $mimeTypes = [];
- foreach ($this->mimeTypes as $item) {
- $mimeTypes[] = $item;
- }
-
- return array_merge([], ...$mimeTypes);
+ return array_merge([], ...array_values($this->mimeTypes));
}
}
diff --git a/Manager/PageManager.php b/Manager/PageManager.php
index d96e6612..86a0a92a 100644
--- a/Manager/PageManager.php
+++ b/Manager/PageManager.php
@@ -1,5 +1,7 @@
slugProvider = $slugProvider;
+ public function __construct(private readonly SlugProviderInterface $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..19f1b0b5 100644
--- a/Manager/UploadManager.php
+++ b/Manager/UploadManager.php
@@ -1,5 +1,7 @@
fileNamer = $fileNamer;
- $this->targetDir = $targetDir;
- $this->webPath = $webPath;
+ public function __construct(
+ private readonly NamerInterface $fileNamer,
+ private $targetDir,
+ private $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
*/
@@ -63,22 +49,24 @@ 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);
+
+ copy($file->getRealPath(), $this->getTargetDir().DIRECTORY_SEPARATOR.$fileName);
return $fileName;
}
/**
- * Remove file
+ * Remove file.
*
* @param string $fileName
*/
- public function remove($fileName)
+ public function remove($fileName): void
{
- $fileName = $this->getTargetDir() . DIRECTORY_SEPARATOR . $fileName;
+ $fileName = $this->getTargetDir().DIRECTORY_SEPARATOR.$fileName;
if (!file_exists($fileName)) {
return;
@@ -88,35 +76,31 @@ public function remove($fileName)
}
/**
- * Get file name
+ * 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)) {
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..14b61693 100644
--- a/Manager/UrlBuilderManager.php
+++ b/Manager/UrlBuilderManager.php
@@ -1,5 +1,7 @@
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 (str_starts_with($url, '#')) {
return $url;
}
- if (substr($url, 0, 4) === 'http') {
+
+ if (str_starts_with($url, 'http')) {
return $url;
}
@@ -76,10 +51,11 @@ public function getFullUrl(string $url): string
// compat SF < 5.3
$mainRequest = $this->requestStack->getMasterRequest();
}
+
if (!$mainRequest) {
return $url;
}
- return $mainRequest->getSchemeAndHttpHost() . '/' . ltrim($url, '/');
+ return $mainRequest->getSchemeAndHttpHost().'/'.ltrim($url, '/');
}
}
diff --git a/Manager/VersionManager.php b/Manager/VersionManager.php
index 1075439b..aef01e82 100644
--- a/Manager/VersionManager.php
+++ b/Manager/VersionManager.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
- $this->userProvider = $userProvider;
- $this->requestStack = $requestStack;
}
- /**
- * @param ContentInterface $content
- *
- * @return array
- */
public function getContentData(ContentInterface $content): array
{
- if ($content->getPage() === null) {
- 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()) && $contentVersionId = $mainRequest->get('versionId')) {
+ foreach ($content->getVersions() as $version) {
+ if ($version->getId() === (int) $contentVersionId) {
+ return $version->getData();
}
}
}
- 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'));
$contentVersion->setData($content->getData());
$contentVersion->setCreatedAt(new \DateTimeImmutable());
$contentVersion->setUserId($this->userProvider->getUserId());
+
$content->addVersion($contentVersion);
if ($linkVersion) {
$content->setContentVersion($contentVersion);
@@ -91,21 +56,17 @@ 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);
$lastDraft->setAutoSave(true);
}
+
$lastDraft->setCreatedAt(new \DateTimeImmutable());
return $lastDraft;
@@ -113,26 +74,25 @@ 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()) {
continue;
}
+
if ($version->getUserId() !== $userId) {
continue;
}
+
if (!$version->isAutoSave()) {
continue;
}
- if ($lastDraft === null || $lastDraft->getCreatedAt() < $version->getCreatedAt()) {
+
+ if (null === $lastDraft || $lastDraft->getCreatedAt() < $version->getCreatedAt()) {
$lastDraft = $version;
}
}
@@ -140,22 +100,18 @@ 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 +122,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'));
@@ -180,46 +131,46 @@ private function getNewPageMetaVersion(PageMetaInterface $pageMeta): PageMetaVer
$pageMetaVersion->setMetaDescription($pageMeta->getMetaDescription());
$pageMetaVersion->setCreatedAt(new \DateTimeImmutable());
$pageMetaVersion->setUserId($this->userProvider->getUserId());
+
$pageMeta->addVersion($pageMetaVersion);
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);
$lastDraft->setAutoSave(true);
}
+
$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);
}
+
$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);
}
+
$pageMetaVersion->setCreatedAt(new \DateTimeImmutable());
$pageMetaVersion->setTitle($page->getPageMeta()->getTitle());
$pageMetaVersion->setSlug($page->getPageMeta()->getSlug());
@@ -230,33 +181,19 @@ 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) {
- return $version;
- }
+ if (($mainRequest = $this->getRequest()) && $pageVersionId = $mainRequest->get('versionId')) {
+ foreach ($page->getVersions() as $version) {
+ if ($version->getId() === (int) $pageVersionId) {
+ return $version;
}
}
}
- if ($page->getPageVersion() !== null) {
- return $page->getPageVersion();
- }
-
- return null;
+ return $page->getPageVersion();
}
- /**
- * @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..a295700f 100644
--- a/Model/Content.php
+++ b/Model/Content.php
@@ -1,5 +1,7 @@
data = [];
$this->versions = new ArrayCollection();
$this->scopes = new ArrayCollection();
}
@@ -121,9 +122,6 @@ public function getData()
}
/**
- * @param array $data
- * @param bool $resetContentVersion
- *
* @return $this
*/
public function setData(array $data, bool $resetContentVersion = true)
@@ -145,28 +143,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 +176,6 @@ public function getVersions()
}
/**
- * @param ContentVersionInterface $contentVersion
- *
* @return $this
*/
public function addVersion(ContentVersionInterface $contentVersion)
@@ -198,8 +187,6 @@ public function addVersion(ContentVersionInterface $contentVersion)
}
/**
- * @param ContentVersionInterface $contentVersion
- *
* @return $this
*/
public function removeVersion(ContentVersionInterface $contentVersion)
@@ -218,8 +205,6 @@ public function getScopes()
}
/**
- * @param ScopeInterface $scope
- *
* @return $this
*/
public function addScope(ScopeInterface $scope)
@@ -230,8 +215,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..34086692 100644
--- a/Model/ContentInterface.php
+++ b/Model/ContentInterface.php
@@ -1,5 +1,7 @@
data = [];
parent::__construct();
}
- /**
- * @return ContentInterface
- */
public function getContent(): ContentInterface
{
return $this->content;
}
/**
- * @param ContentInterface $content
- *
* @return $this
*/
public function setContent(ContentInterface $content): self
@@ -49,16 +45,12 @@ 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): int => ($a['position'] ?? 0) <=> ($b['position'] ?? 0));
return $data;
}
/**
- * @param array $data
- *
* @return $this
*/
public function setData(array $data)
diff --git a/Model/ContentVersionInterface.php b/Model/ContentVersionInterface.php
index 38f35252..36de1f1a 100644
--- a/Model/ContentVersionInterface.php
+++ b/Model/ContentVersionInterface.php
@@ -1,5 +1,7 @@
locale;
@@ -29,19 +28,13 @@ public function setLocale($locale): self
return $this;
}
- /**
- * @return string
- */
- public function getOptionTitle()
+ public function getOptionTitle(): string
{
- return (string)$this->locale;
+ return (string) $this->locale;
}
- /**
- * @return string
- */
- public function getUnicityIdentifier()
+ public function getUnicityIdentifier(): string
{
- return (string)$this->locale;
+ return (string) $this->locale;
}
}
diff --git a/Model/LocaleScopeInterface.php b/Model/LocaleScopeInterface.php
index 5b1eb37a..84bf6660 100644
--- a/Model/LocaleScopeInterface.php
+++ b/Model/LocaleScopeInterface.php
@@ -1,17 +1,14 @@
pageMeta;
$newPageMeta->setPage($this);
+
$this->pageMeta = $newPageMeta;
$newContent = clone $this->content;
$newContent->setPage($this);
+
$this->content = $newContent;
$this->versions = new ArrayCollection();
@@ -132,15 +136,14 @@ 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;
return $this;
@@ -155,11 +158,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,15 +176,14 @@ 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;
return $this;
@@ -198,8 +198,6 @@ public function getScopes()
}
/**
- * @param ScopeInterface $scope
- *
* @return $this
*/
public function addScope(ScopeInterface $scope)
@@ -210,8 +208,6 @@ public function addScope(ScopeInterface $scope)
}
/**
- * @param ScopeInterface $scope
- *
* @return $this
*/
public function removeScope(ScopeInterface $scope)
@@ -221,17 +217,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 +241,6 @@ public function getVersions()
}
/**
- * @param PageVersionInterface $pageVersion
- *
* @return $this
*/
public function addVersion(PageVersionInterface $pageVersion)
@@ -263,8 +252,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..b2082209 100644
--- a/Model/PageInterface.php
+++ b/Model/PageInterface.php
@@ -1,5 +1,7 @@
pageMeta;
}
/**
- * @param PageMetaInterface $pageMeta
- *
* @return $this
*/
public function setPageMeta(PageMetaInterface $pageMeta): self
diff --git a/Model/PageMetaVersionInterface.php b/Model/PageMetaVersionInterface.php
index 9d962dad..15821686 100644
--- a/Model/PageMetaVersionInterface.php
+++ b/Model/PageMetaVersionInterface.php
@@ -1,5 +1,7 @@
page;
}
/**
- * @param PageInterface $page
- *
* @return $this
*/
public function setPage(PageInterface $page): self
@@ -39,17 +36,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 +51,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..c89408d1 100644
--- a/Model/PageVersionInterface.php
+++ b/Model/PageVersionInterface.php
@@ -1,5 +1,7 @@
id;
diff --git a/Model/ScopeInterface.php b/Model/ScopeInterface.php
index a036bafa..3960ca2a 100644
--- a/Model/ScopeInterface.php
+++ b/Model/ScopeInterface.php
@@ -1,5 +1,7 @@
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 +50,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 +65,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..2fbcbab7 100644
--- a/Model/VersionInterface.php
+++ b/Model/VersionInterface.php
@@ -1,11 +1,13 @@
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 bfd80fb5..c7915673 100644
--- a/Naming/NamerInterface.php
+++ b/Naming/NamerInterface.php
@@ -1,15 +1,12 @@
getExtension();
@@ -22,7 +19,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/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 6cb0bc44..1180eba9 100644
--- a/Scope/LocaleScopeHandler.php
+++ b/Scope/LocaleScopeHandler.php
@@ -1,5 +1,7 @@
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'])) {
@@ -53,11 +35,6 @@ public function getScopeFromData(array $data): ?ScopeInterface
]);
}
- /**
- * @param ScopeInterface $scope
- *
- * @return array
- */
public function getDataFromScope(ScopeInterface $scope): array
{
return [
@@ -65,9 +42,6 @@ public function getDataFromScope(ScopeInterface $scope): array
];
}
- /**
- * @return ScopeInterface|null
- */
public function getCurrentScope(): ?ScopeInterface
{
if (!$this->configurationManager->isScopesEnabled()) {
@@ -81,7 +55,8 @@ 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..80d01a06 100644
--- a/Scope/ScopeHandler.php
+++ b/Scope/ScopeHandler.php
@@ -1,5 +1,7 @@
em = $em;
- $this->configurationManager = $configurationManager;
+ public function __construct(
+ protected EntityManagerInterface $em,
+ protected ConfigurationManager $configurationManager,
+ ) {
}
- /**
- * @param ContentInterface $content
- *
- * @return bool
- */
public function isContentSlugValid(ContentInterface $content): bool
{
$existingContents = $this->em->getRepository($this->configurationManager->getEntityClass('content'))->findBy([
@@ -44,39 +27,32 @@ 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;
}
+
if ($existingPage->getPageVersion()->getPageMetaVersion()->getSlug() !== $page->getPageMeta()->getSlug()) {
unset($existingPages[$key]);
continue;
}
}
+
$existingPages = array_values($existingPages);
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 +65,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
{
@@ -98,14 +72,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): int => $a->getUnicityIdentifier() <=> $b->getUnicityIdentifier());
+
+ if ([] !== $result) {
return false;
}
}
@@ -113,12 +87,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,17 +96,15 @@ public function getEntityForCurrentScope(string $entityCode, array $criteria): ?
/**
* @param array|ScopableInterface[] $entities
- *
- * @return ScopableInterface|null
*/
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();
- if ($currentScope === null) {
+ if (null === $currentScope) {
return null;
}
diff --git a/Scope/ScopeHandlerInterface.php b/Scope/ScopeHandlerInterface.php
index c837f929..b94f3c59 100644
--- a/Scope/ScopeHandlerInterface.php
+++ b/Scope/ScopeHandlerInterface.php
@@ -1,5 +1,7 @@
addCompilerPass(new FormThemePass());
}
- /**
- * @param ContainerBuilder $container
- */
- private function addRegisterMappingsPass(ContainerBuilder $container)
+ private function addRegisterMappingsPass(ContainerBuilder $container): void
{
- $mappings = array(
+ $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 9d1a0f46..c2e51b55 100644
--- a/Slug/SlugProvider.php
+++ b/Slug/SlugProvider.php
@@ -1,5 +1,7 @@
scopeHandler = $scopeHandler;
}
- /**
- * @param PageInterface $page
- */
public function setPageValidIdentifier(PageInterface $page): void
{
while (true) {
if ($this->scopeHandler->isPageIdentifierValid($page)) {
break;
}
+
$page->setPageIdentifier($this->getNewValue($page->getPageIdentifier()));
}
}
- /**
- * @param PageInterface $page
- */
public function setPageValidSlug(PageInterface $page): void
{
while (true) {
if ($this->scopeHandler->isPageSlugValid($page)) {
break;
}
+
$page->getPageMeta()->setSlug($this->getNewValue($page->getPageMeta()->getSlug()));
}
}
- /**
- * @param ContentInterface $content
- */
public function setContentValidSlug(ContentInterface $content): void
{
while (true) {
if ($this->scopeHandler->isContentSlugValid($content)) {
break;
}
+
$content->setSlug($this->getNewValue($content->getSlug()));
}
}
- /**
- * @param string $value
- *
- * @return string
- */
- private function getNewValue($value): string
+ private function getNewValue(string $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..2f88a047 100644
--- a/Slug/SlugProviderInterface.php
+++ b/Slug/SlugProviderInterface.php
@@ -1,5 +1,7 @@
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()
+ public function getFunctions(): array
{
return [
new TwigFunction('acb_render_element', [$this, 'renderElement'], ['is_safe' => ['html']]),
@@ -103,7 +52,7 @@ public function getFunctions()
];
}
- public function renderElement(array $elementData)
+ public function renderElement(array $elementData): string
{
$element = $this->elementManager->getElementByCode($elementData['elementType']);
$params = $element->getRawData($elementData);
@@ -111,13 +60,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 +73,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 +86,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 +103,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 +120,22 @@ 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 +143,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 +152,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 = [];
@@ -259,7 +165,8 @@ private function getElementClasses(array $extra, string $defaultDisplay = 'block
if (!is_array($hideOn)) {
$hideOn = [$hideOn];
}
- if (count($hideOn) > 0) {
+
+ if ([] !== $hideOn) {
$devices = [
'xs',
'sm',
@@ -272,14 +179,16 @@ 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 +197,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 +204,40 @@ 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'];
@@ -352,6 +248,7 @@ private function getPixelProperties(): array
$pixelProperties[] = sprintf($property, $direction);
}
}
+
$pixelProperties = array_merge($pixelProperties, [
'border_top_left_radius',
'border_top_right_radius',
@@ -363,8 +260,6 @@ private function getPixelProperties(): array
}
/**
- * @param FormView $form
- *
* @return array|mixed
*/
public function getJsonForm(FormView $form)
@@ -383,38 +278,25 @@ public function getJsonForm(FormView $form)
}
return $json ?? [];
- } elseif ($useValueForSerialization || is_object($form->vars['data'])) {
+ }
+
+ if ($useValueForSerialization || is_object($form->vars['data'])) {
return $form->vars['value'];
}
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 +310,7 @@ public function getColSize(array $config): string
}
if (isset($config['offset_'.$device])) {
- $colOffset = $config['offset_' . $device];
+ $colOffset = $config['offset_'.$device];
}
}
@@ -436,20 +318,15 @@ public function getColSize(array $config): string
return $colSize;
}
- return $colSize + $colOffset;
+ return (string) ($colSize + $colOffset);
}
- /**
- * @param string $value
- *
- * @return string
- */
- 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));
}
}
diff --git a/Twig/Extension/ScopeExtension.php b/Twig/Extension/ScopeExtension.php
index 86b007c7..d96da7a6 100644
--- a/Twig/Extension/ScopeExtension.php
+++ b/Twig/Extension/ScopeExtension.php
@@ -1,5 +1,7 @@
configurationManager = $configurationManager;
+ public function __construct(private readonly ConfigurationManager $configurationManager)
+ {
}
- /**
- * Add specific twig function
- *
- * @return TwigFunction[]
- */
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('acb_is_scopes_enabled', [$this, 'isScopesEnabled']),
];
}
- /**
- * @return bool
- */
public function isScopesEnabled(): bool
{
return $this->configurationManager->isScopesEnabled();
diff --git a/User/AnonymousUserProvider.php b/User/AnonymousUserProvider.php
index 7a3d46c9..17b73d8c 100644
--- a/User/AnonymousUserProvider.php
+++ b/User/AnonymousUserProvider.php
@@ -1,37 +1,22 @@
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..68d3d4f3 100644
--- a/User/UserProviderInterface.php
+++ b/User/UserProviderInterface.php
@@ -1,18 +1,12 @@