diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 41815708e5..60740fe7c8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1422,72 +1422,6 @@ parameters: count: 1 path: src/lib/Behat/Page/TrashPage.php - - - message: '#^Method Ibexa\\AdminUi\\Component\\Content\\PreviewUnavailableTwigComponent\:\:render\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Content/PreviewUnavailableTwigComponent.php - - - - message: '#^Parameter \#1 \$location of method Ibexa\\AdminUi\\Siteaccess\\NonAdminSiteaccessResolver\:\:getSiteAccessesListForLocation\(\) expects Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location, Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|false given\.$#' - identifier: argument.type - count: 1 - path: src/lib/Component/Content/PreviewUnavailableTwigComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Event\\RenderGroupEvent\:\:__construct\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderGroupEvent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Event\\RenderGroupEvent\:\:getComponents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderGroupEvent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Event\\RenderGroupEvent\:\:getParameters\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderGroupEvent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Event\\RenderGroupEvent\:\:setComponents\(\) has parameter \$components with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderGroupEvent.php - - - - message: '#^Property Ibexa\\AdminUi\\Component\\Event\\RenderGroupEvent\:\:\$parameters type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderGroupEvent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Event\\RenderSingleEvent\:\:__construct\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderSingleEvent.php - - - - message: '#^Property Ibexa\\AdminUi\\Component\\Event\\RenderSingleEvent\:\:\$parameters type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Event/RenderSingleEvent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\LinkComponent\:\:render\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/LinkComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\Renderer\\DefaultRenderer\:\:renderGroup\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Renderer/DefaultRenderer.php - - message: '#^Method Ibexa\\AdminUi\\Component\\Renderer\\DefaultRenderer\:\:renderGroup\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -1500,66 +1434,6 @@ parameters: count: 1 path: src/lib/Component/Renderer/DefaultRenderer.php - - - message: '#^Method Ibexa\\AdminUi\\Component\\Renderer\\DefaultRenderer\:\:renderSingle\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/Renderer/DefaultRenderer.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\ScriptComponent\:\:render\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/ScriptComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TabsComponent\:\:__construct\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TabsComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TabsComponent\:\:composeTabParameters\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TabsComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TabsComponent\:\:composeTabParameters\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TabsComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TabsComponent\:\:dispatchTabPreRenderEvent\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TabsComponent.php - - - - message: '#^Property Ibexa\\AdminUi\\Component\\TabsComponent\:\:\$parameters type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TabsComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TwigComponent\:\:__construct\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TwigComponent.php - - - - message: '#^Method Ibexa\\AdminUi\\Component\\TwigComponent\:\:render\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TwigComponent.php - - - - message: '#^Property Ibexa\\AdminUi\\Component\\TwigComponent\:\:\$parameters type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/Component/TwigComponent.php - - message: '#^Offset ''meta'' might not exist on array\{position\: int, meta\?\: bool\}\.$#' identifier: offsetAccess.notFound @@ -1573,51 +1447,9 @@ parameters: path: src/lib/EventListener/AddNewTranslationFieldDefinition.php - - message: '#^Cannot call method log\(\) on Psr\\Log\\LoggerInterface\|null\.$#' + message: '#^Cannot call method isTranslatable\(\) on Ibexa\\Contracts\\Core\\Repository\\Values\\ContentType\\FieldDefinition\|null\.$#' identifier: method.nonObject count: 1 - path: src/lib/EventListener/AdminExceptionListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\AdminExceptionListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/AdminExceptionListener.php - - - - message: '#^PHPDoc tag @param references unknown parameter\: \$kernelRootDir$#' - identifier: parameter.notFound - count: 1 - path: src/lib/EventListener/AdminExceptionListener.php - - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\AdminExceptionListener\:\:\$siteAccessGroups type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/AdminExceptionListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\ContentDownloadRouteReferenceListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/ContentDownloadRouteReferenceListener.php - - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\ContentDownloadRouteReferenceListener\:\:\$siteAccessGroups type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/ContentDownloadRouteReferenceListener.php - - - - message: '#^Cannot access property \$isTranslatable on Ibexa\\Contracts\\Core\\Repository\\Values\\ContentType\\FieldDefinition\|null\.$#' - identifier: property.nonObject - count: 1 - path: src/lib/EventListener/ContentProxyCreateDraftListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\ContentProxyCreateDraftListener\:\:getTranslatedContentFields\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 path: src/lib/EventListener/ContentProxyCreateDraftListener.php - @@ -1626,156 +1458,42 @@ parameters: count: 1 path: src/lib/EventListener/ContentProxyCreateDraftListener.php - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\ContentTranslateViewFilterParametersListener\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/ContentTranslateViewFilterParametersListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\CredentialsExpirationWarningListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/CredentialsExpirationWarningListener.php - - message: '#^Parameter \#1 \$passwordExpiresAt of method Ibexa\\AdminUi\\EventListener\\CredentialsExpirationWarningListener\:\:generateNotification\(\) expects DateTimeInterface, DateTimeImmutable\|null given\.$#' identifier: argument.type count: 1 path: src/lib/EventListener/CredentialsExpirationWarningListener.php - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\CredentialsExpiredListener\:\:\$siteAccessGroups \(array\\>\) does not accept array\\.$#' - identifier: assign.propertyType - count: 1 - path: src/lib/EventListener/CredentialsExpiredListener.php - - message: '#^Call to an undefined method Symfony\\Contracts\\Translation\\TranslatorInterface\:\:setLocale\(\)\.$#' identifier: method.notFound count: 1 path: src/lib/EventListener/InContextTranslationListener.php - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\InContextTranslationListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/InContextTranslationListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\MenuPermissionsListener\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/MenuPermissionsListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\RequestAttributesListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestAttributesListener.php - - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\RequestAttributesListener\:\:\$siteAccessGroups type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestAttributesListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\RequestListener\:\:__construct\(\) has parameter \$groupsBySiteAccess with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\RequestListener\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestListener.php - - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\RequestListener\:\:\$groupsBySiteAccess type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestListener.php - - message: '#^Call to an undefined method Symfony\\Contracts\\Translation\\TranslatorInterface\:\:setLocale\(\)\.$#' identifier: method.notFound count: 1 path: src/lib/EventListener/RequestLocaleListener.php - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\RequestLocaleListener\:\:__construct\(\) has parameter \$availableTranslations with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestLocaleListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\RequestLocaleListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestLocaleListener.php - - message: '#^Parameter \#1 \$locale of method Symfony\\Component\\HttpFoundation\\Request\:\:setLocale\(\) expects string, string\|false given\.$#' identifier: argument.type count: 1 path: src/lib/EventListener/RequestLocaleListener.php - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\RequestLocaleListener\:\:\$availableTranslations type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestLocaleListener.php - - - - message: '#^Property Ibexa\\AdminUi\\EventListener\\RequestLocaleListener\:\:\$siteAccessGroups type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/RequestLocaleListener.php - - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\SearchViewFilterParametersListener\:\:__construct\(\) has parameter \$siteAccessGroups with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/SearchViewFilterParametersListener.php - - - - message: '#^Parameter \#1 \$request of method Ibexa\\AdminUi\\EventListener\\SearchViewFilterParametersListener\:\:isAdminSiteAccess\(\) expects Symfony\\Component\\HttpFoundation\\Request, Symfony\\Component\\HttpFoundation\\Request\|null given\.$#' - identifier: argument.type - count: 1 - path: src/lib/EventListener/SearchViewFilterParametersListener.php - - message: '#^Method Ibexa\\AdminUi\\EventListener\\SetViewParametersListener\:\:getIgnoredContentFields\(\) has parameter \$fieldsData with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#' identifier: missingType.generics count: 1 path: src/lib/EventListener/SetViewParametersListener.php - - - message: '#^Method Ibexa\\AdminUi\\EventListener\\SetViewParametersListener\:\:getSubscribedEvents\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: src/lib/EventListener/SetViewParametersListener.php - - message: '#^Method Ibexa\\AdminUi\\EventListener\\SetViewParametersListener\:\:resolveParentLocation\(\) should return Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location but returns Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|false\.$#' identifier: return.type count: 1 path: src/lib/EventListener/SetViewParametersListener.php - - - message: '#^Method Ibexa\\AdminUi\\Exception\\ContentTypeIconNotFoundException\:\:__construct\(\) has parameter \$code with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/Exception/ContentTypeIconNotFoundException.php - - - - message: '#^Method Ibexa\\AdminUi\\Exception\\ContentTypeIconNotFoundException\:\:__construct\(\) has parameter \$contentType with no type specified\.$#' - identifier: missingType.parameter - count: 1 - path: src/lib/Exception/ContentTypeIconNotFoundException.php - - message: '#^Method Ibexa\\AdminUi\\Exception\\ValueMapperNotFoundException\:\:__construct\(\) has parameter \$code with no type specified\.$#' identifier: missingType.parameter @@ -1795,7 +1513,7 @@ parameters: path: src/lib/FieldType/FieldDefinitionFormMapperInterface.php - - message: '#^Method Ibexa\\AdminUi\\FieldType\\FieldTypeDefinitionFormMapperDispatcher\:\:map\(\) has parameter \$fieldForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#' + message: '#^Method Ibexa\\AdminUi\\FieldType\\FieldTypeDefinitionFormMapperDispatcher\:\:map\(\) has parameter \$form with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#' identifier: missingType.generics count: 1 path: src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcher.php @@ -1818,12 +1536,6 @@ parameters: count: 1 path: src/lib/FieldType/Mapper/AuthorFormMapper.php - - - message: '#^Constructor of class Ibexa\\AdminUi\\FieldType\\Mapper\\BinaryFileFormMapper has an unused parameter \$fieldTypeService\.$#' - identifier: constructor.unusedParameter - count: 1 - path: src/lib/FieldType/Mapper/BinaryFileFormMapper.php - - message: '#^Method Ibexa\\AdminUi\\FieldType\\Mapper\\BinaryFileFormMapper\:\:mapFieldDefinitionForm\(\) has parameter \$fieldDefinitionForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#' identifier: missingType.generics @@ -1878,12 +1590,6 @@ parameters: count: 1 path: src/lib/FieldType/Mapper/IntegerFormMapper.php - - - message: '#^Constructor of class Ibexa\\AdminUi\\FieldType\\Mapper\\MediaFormMapper has an unused parameter \$fieldTypeService\.$#' - identifier: constructor.unusedParameter - count: 1 - path: src/lib/FieldType/Mapper/MediaFormMapper.php - - message: '#^Method Ibexa\\AdminUi\\FieldType\\Mapper\\MediaFormMapper\:\:mapFieldDefinitionForm\(\) has parameter \$fieldDefinitionForm with generic interface Symfony\\Component\\Form\\FormInterface but does not specify its types\: TData$#' identifier: missingType.generics @@ -5196,24 +4902,12 @@ parameters: count: 1 path: src/lib/Limitation/Mapper/ChangeOwnerLimitationMapper.php - - - message: '#^Cannot call method error\(\) on Psr\\Log\\LoggerInterface\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/lib/Limitation/Mapper/ContentTypeLimitationMapper.php - - message: '#^Method Ibexa\\AdminUi\\Limitation\\Mapper\\GroupLimitationMapper\:\:getSelectionChoices\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue count: 1 path: src/lib/Limitation/Mapper/GroupLimitationMapper.php - - - message: '#^Cannot call method error\(\) on Psr\\Log\\LoggerInterface\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/lib/Limitation/Mapper/LanguageLimitationMapper.php - - message: '#^Method Ibexa\\AdminUi\\Limitation\\Mapper\\MemberOfLimitationMapper\:\:getSelectionChoices\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -5280,12 +4974,6 @@ parameters: count: 2 path: src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php - - - message: '#^Cannot call method error\(\) on Psr\\Log\\LoggerInterface\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php - - message: '#^Method Ibexa\\AdminUi\\Limitation\\Mapper\\OwnerLimitationMapper\:\:getSelectionChoices\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -5304,12 +4992,6 @@ parameters: count: 1 path: src/lib/Limitation/Mapper/RoleLimitationMapper.php - - - message: '#^Cannot call method error\(\) on Psr\\Log\\LoggerInterface\|null\.$#' - identifier: method.nonObject - count: 1 - path: src/lib/Limitation/Mapper/SectionLimitationMapper.php - - message: '#^Call to function is_array\(\) with array\ will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -6372,12 +6054,6 @@ parameters: count: 2 path: src/lib/Translation/Extractor/JavaScriptFileVisitor.php - - - message: '#^Cannot call method error\(\) on Psr\\Log\\LoggerInterface\|null\.$#' - identifier: method.nonObject - count: 3 - path: src/lib/Translation/Extractor/JavaScriptFileVisitor.php - - message: '#^Method Ibexa\\AdminUi\\Translation\\Extractor\\JavaScriptFileVisitor\:\:visitPhpFile\(\) has no return type specified\.$#' identifier: missingType.return @@ -7704,18 +7380,6 @@ parameters: count: 1 path: tests/lib/Config/AdminUiForms/ContentTypeFieldTypesResolverTest.php - - - message: '#^Method Ibexa\\Tests\\AdminUi\\EventListener\\ContentProxyCreateDraftListenerTest\:\:getContentType\(\) has parameter \$fieldDefs with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: tests/lib/EventListener/ContentProxyCreateDraftListenerTest.php - - - - message: '#^Method Ibexa\\Tests\\AdminUi\\EventListener\\SetViewParametersListenerTest\:\:createFieldMock\(\) should return Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Field&PHPUnit\\Framework\\MockObject\\MockObject but returns PHPUnit\\Framework\\MockObject\\MockObject&Symfony\\Component\\Form\\FormInterface\.$#' - identifier: return.type - count: 1 - path: tests/lib/EventListener/SetViewParametersListenerTest.php - - message: '#^Method Ibexa\\Tests\\AdminUi\\Form\\Data\\AbstractFormDataValidationTestCase\:\:getForm\(\) return type with generic interface Symfony\\Component\\Form\\FormInterface does not specify its types\: TData$#' identifier: missingType.generics diff --git a/src/bundle/Resources/config/services/events.yaml b/src/bundle/Resources/config/services/events.yaml index 28316fa85b..cc3759ae86 100644 --- a/src/bundle/Resources/config/services/events.yaml +++ b/src/bundle/Resources/config/services/events.yaml @@ -32,7 +32,7 @@ services: Ibexa\AdminUi\EventListener\AdminExceptionListener: arguments: $siteAccessGroups: '%ibexa.site_access.groups%' - $kernelProjectDir: '%kernel.project_dir%' + $rootDir: '%kernel.project_dir%' $kernelEnvironment: '%kernel.environment%' $encoreTagRenderer: '@webpack_encore.tag_renderer' $entrypointLookupCollection: '@webpack_encore.entrypoint_lookup_collection' diff --git a/src/lib/Component/Content/ContentEditMetaFieldsComponent.php b/src/lib/Component/Content/ContentEditMetaFieldsComponent.php index eded49ad20..f0b8f4894b 100644 --- a/src/lib/Component/Content/ContentEditMetaFieldsComponent.php +++ b/src/lib/Component/Content/ContentEditMetaFieldsComponent.php @@ -15,26 +15,18 @@ use Ibexa\Core\Repository\Values\ContentType\FieldDefinition; use Twig\Environment; -class ContentEditMetaFieldsComponent implements ComponentInterface +final readonly class ContentEditMetaFieldsComponent implements ComponentInterface { - private const NO_CONTENT = ''; - - private Environment $twig; - - private ConfigResolverInterface $configResolver; + private const string NO_CONTENT = ''; public function __construct( - Environment $twig, - ConfigResolverInterface $configResolver + private Environment $twig, + private ConfigResolverInterface $configResolver ) { - $this->twig = $twig; - $this->configResolver = $configResolver; } /** * @param array $parameters - * - * @return string */ public function render(array $parameters = []): string { @@ -84,8 +76,8 @@ private function getMetaFieldDefinitionCollection(ContentType $contentType): Fie 'admin_ui_forms.content_edit.meta_field_groups_list' ); - return $contentType->fieldDefinitions->filter( - static fn (FieldDefinition $field): bool => in_array($field->fieldGroup, $metaFieldGroups, true), + return $contentType->getFieldDefinitions()->filter( + static fn (FieldDefinition $field): bool => in_array($field->getFieldGroup(), $metaFieldGroups, true), ); } diff --git a/src/lib/Component/Content/PreviewUnavailableTwigComponent.php b/src/lib/Component/Content/PreviewUnavailableTwigComponent.php index 41d1e177a5..35f5f79fe8 100644 --- a/src/lib/Component/Content/PreviewUnavailableTwigComponent.php +++ b/src/lib/Component/Content/PreviewUnavailableTwigComponent.php @@ -16,34 +16,17 @@ use Ibexa\Contracts\TwigComponents\ComponentInterface; use Twig\Environment; -class PreviewUnavailableTwigComponent implements ComponentInterface +final readonly class PreviewUnavailableTwigComponent implements ComponentInterface { - private Environment $twig; - - /** @var \Ibexa\AdminUi\Siteaccess\NonAdminSiteaccessResolver */ - private SiteaccessResolverInterface $siteaccessResolver; - - private LocationService $locationService; - - /** - * @param \Twig\Environment $twig - * @param \Ibexa\AdminUi\Siteaccess\NonAdminSiteaccessResolver $siteaccessResolver - * @param \Ibexa\Contracts\Core\Repository\LocationService $locationService - */ public function __construct( - Environment $twig, - SiteaccessResolverInterface $siteaccessResolver, - LocationService $locationService + private Environment $twig, + private SiteaccessResolverInterface $siteaccessResolver, + private LocationService $locationService ) { - $this->twig = $twig; - $this->siteaccessResolver = $siteaccessResolver; - $this->locationService = $locationService; } /** - * @param array $parameters - * - * @return string + * @param array $parameters */ public function render(array $parameters = []): string { @@ -56,9 +39,17 @@ public function render(array $parameters = []): string $versionNo = $content->getVersionInfo()->versionNo; // nonpublished content should use parent location instead because location doesn't exist yet - if (!$content->contentInfo->published && null === $content->contentInfo->mainLocationId) { - $parentLocations = $this->locationService->loadParentLocationsForDraftContent($content->getVersionInfo()); + $contentInfo = $content->getContentInfo(); + if (!$contentInfo->isPublished() && null === $contentInfo->getMainLocationId()) { + $parentLocations = $this->locationService->loadParentLocationsForDraftContent( + $content->getVersionInfo() + ); + $location = reset($parentLocations); + if ($location === false) { + return ''; + } + $versionNo = null; } @@ -68,7 +59,7 @@ public function render(array $parameters = []): string $versionNo, $language->languageCode ); - } catch (UnauthorizedException $e) { + } catch (UnauthorizedException) { $siteaccesses = []; } diff --git a/src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php b/src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php index cc58efedd9..47c1370e5d 100644 --- a/src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php +++ b/src/lib/Component/ContentType/ContentTypeEditMetaFieldsComponent.php @@ -12,20 +12,14 @@ use Ibexa\Contracts\TwigComponents\ComponentInterface; use Twig\Environment; -final class ContentTypeEditMetaFieldsComponent implements ComponentInterface +final readonly class ContentTypeEditMetaFieldsComponent implements ComponentInterface { - private const NO_CONTENT = ''; - - private ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver; - - private Environment $twig; + private const string NO_CONTENT = ''; public function __construct( - ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver, - Environment $twig + private ContentTypeFieldTypesResolverInterface $contentTypeFieldTypesResolver, + private Environment $twig ) { - $this->contentTypeFieldTypesResolver = $contentTypeFieldTypesResolver; - $this->twig = $twig; } /** diff --git a/src/lib/Component/Event/RenderGroupEvent.php b/src/lib/Component/Event/RenderGroupEvent.php index 0cad0c0a18..af8438e4af 100644 --- a/src/lib/Component/Event/RenderGroupEvent.php +++ b/src/lib/Component/Event/RenderGroupEvent.php @@ -15,38 +15,27 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Event\RenderGroupEvent} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\Contracts\TwigComponents\Event\RenderGroupEvent} instead */ -class RenderGroupEvent extends Event +final class RenderGroupEvent extends Event { - public const NAME = 'ezplatform_admin_ui.component.render_group'; - - private Registry $registry; - - private string $groupName; - - private array $parameters; + public const string NAME = 'ezplatform_admin_ui.component.render_group'; /** - * @param \Ibexa\AdminUi\Component\Registry $registry - * @param string $groupName - * @param array $parameters + * @param array $parameters */ - public function __construct(Registry $registry, string $groupName, array $parameters = []) - { - $this->registry = $registry; - $this->groupName = $groupName; - $this->parameters = $parameters; + public function __construct( + private readonly Registry $registry, + private readonly string $groupName, + private readonly array $parameters = [] + ) { } - /** - * @return string - */ public function getGroupName(): string { return $this->groupName; } /** - * @return array + * @return \Ibexa\Contracts\TwigComponents\ComponentInterface[] */ public function getComponents(): array { @@ -54,7 +43,7 @@ public function getComponents(): array } /** - * @param array $components + * @param \Ibexa\Contracts\TwigComponents\ComponentInterface[] $components */ public function setComponents(array $components): void { @@ -62,7 +51,7 @@ public function setComponents(array $components): void } /** - * @return array + * @return array */ public function getParameters(): array { diff --git a/src/lib/Component/Event/RenderSingleEvent.php b/src/lib/Component/Event/RenderSingleEvent.php index e4f2e99791..a2925c6938 100644 --- a/src/lib/Component/Event/RenderSingleEvent.php +++ b/src/lib/Component/Event/RenderSingleEvent.php @@ -16,50 +16,31 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Event\RenderSingleEvent} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\Contracts\TwigComponents\Event\RenderSingleEvent} instead */ -class RenderSingleEvent extends Event +final class RenderSingleEvent extends Event { - public const NAME = 'ezplatform_admin_ui.component.render_single'; - - private Registry $registry; - - private string $groupName; - - private string $serviceId; - - private array $parameters; + public const string NAME = 'ezplatform_admin_ui.component.render_single'; /** - * @param \Ibexa\AdminUi\Component\Registry $registry - * @param string $groupName - * @param array $parameters + * @param array $parameters */ - public function __construct(Registry $registry, string $groupName, string $serviceId, array $parameters = []) - { - $this->registry = $registry; - $this->groupName = $groupName; - $this->serviceId = $serviceId; - $this->parameters = $parameters; + public function __construct( + private readonly Registry $registry, + private readonly string $groupName, + private readonly string $serviceId, + private readonly array $parameters = [] + ) { } - /** - * @return string - */ public function getGroupName(): string { return $this->groupName; } - /** - * @return string - */ public function getName(): string { return $this->serviceId; } - /** - * @return \Ibexa\Contracts\TwigComponents\ComponentInterface - */ public function getComponent(): ComponentInterface { $group = $this->registry->getComponents($this->getGroupName()); @@ -67,9 +48,6 @@ public function getComponent(): ComponentInterface return $group[$this->serviceId]; } - /** - * @param \Ibexa\Contracts\TwigComponents\ComponentInterface $component - */ public function setComponent(ComponentInterface $component): void { $this->registry->addComponent($this->getGroupName(), $this->getName(), $component); diff --git a/src/lib/Component/EventSubscriber/RenderEventSubscriber.php b/src/lib/Component/EventSubscriber/RenderEventSubscriber.php index 2282b2ea85..254334bfb5 100644 --- a/src/lib/Component/EventSubscriber/RenderEventSubscriber.php +++ b/src/lib/Component/EventSubscriber/RenderEventSubscriber.php @@ -16,18 +16,12 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -final class RenderEventSubscriber implements EventSubscriberInterface +final readonly class RenderEventSubscriber implements EventSubscriberInterface { - private Registry $registry; - - private EventDispatcherInterface $eventDispatcher; - public function __construct( - EventDispatcherInterface $eventDispatcher, - Registry $registry + private EventDispatcherInterface $eventDispatcher, + private Registry $registry ) { - $this->registry = $registry; - $this->eventDispatcher = $eventDispatcher; } public static function getSubscribedEvents(): array diff --git a/src/lib/Component/LinkComponent.php b/src/lib/Component/LinkComponent.php index af09347b9d..ffdb513d02 100644 --- a/src/lib/Component/LinkComponent.php +++ b/src/lib/Component/LinkComponent.php @@ -15,40 +15,20 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\LinkComponent} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\TwigComponents\Component\LinkComponent} instead */ -class LinkComponent implements ComponentInterface +readonly class LinkComponent implements ComponentInterface { - protected Environment $twig; - - protected string $href; - - protected string $type; - - protected string $rel; - - protected ?string $crossorigin; - - protected ?string $integrity; - public function __construct( - Environment $twig, - string $href, - string $type = 'text/css', - string $rel = 'stylesheet', - ?string $crossorigin = null, - ?string $integrity = null + protected Environment $twig, + protected string $href, + protected string $type = 'text/css', + protected string $rel = 'stylesheet', + protected ?string $crossorigin = null, + protected ?string $integrity = null ) { - $this->twig = $twig; - $this->href = $href; - $this->type = $type; - $this->rel = $rel; - $this->crossorigin = $crossorigin; - $this->integrity = $integrity; } /** - * @param array $parameters - * - * @return string + * @param array $parameters */ public function render(array $parameters = []): string { diff --git a/src/lib/Component/Registry.php b/src/lib/Component/Registry.php index a47e34f846..5ee2995976 100644 --- a/src/lib/Component/Registry.php +++ b/src/lib/Component/Registry.php @@ -15,12 +15,9 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Registry} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\TwigComponents\Component\Registry} instead */ -class Registry +readonly class Registry { - /** - * @var string[] - */ - private const COMPONENTS_WHITELIST = + private const array COMPONENTS_WHITELIST = [ 'action-configuration-tabs', 'attribute-definition-block', @@ -80,13 +77,10 @@ class Registry 'user-profile-blocks', ]; - private const GROUP_PREFIX = 'admin-ui-'; - - protected TwigComponentsRegistry $inner; + private const string GROUP_PREFIX = 'admin-ui-'; - public function __construct(TwigComponentsRegistry $inner) + public function __construct(protected TwigComponentsRegistry $inner) { - $this->inner = $inner; } public function addComponent(string $group, string $serviceId, ComponentInterface $component): void diff --git a/src/lib/Component/Renderer/DefaultRenderer.php b/src/lib/Component/Renderer/DefaultRenderer.php index b3a9e762a7..1ae3cc5fd4 100644 --- a/src/lib/Component/Renderer/DefaultRenderer.php +++ b/src/lib/Component/Renderer/DefaultRenderer.php @@ -15,20 +15,24 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\Renderer\DefaultRenderer} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\TwigComponents\Component\Renderer\DefaultRenderer} instead */ -class DefaultRenderer implements RendererInterface +readonly class DefaultRenderer implements RendererInterface { - protected TwigComponentsDefaultRenderer $inner; - - public function __construct(TwigComponentsDefaultRenderer $inner) - { - $this->inner = $inner; + public function __construct( + private TwigComponentsDefaultRenderer $inner + ) { } + /** + * @param array $parameters + */ public function renderGroup(string $groupName, array $parameters = []): array { return $this->inner->renderGroup($groupName, $parameters); } + /** + * @param array $parameters + */ public function renderSingle(string $name, $groupName, array $parameters = []): string { return $this->inner->renderSingle($name, $groupName, $parameters); diff --git a/src/lib/Component/ScriptComponent.php b/src/lib/Component/ScriptComponent.php index eca1cb39fe..8385ef7c2a 100644 --- a/src/lib/Component/ScriptComponent.php +++ b/src/lib/Component/ScriptComponent.php @@ -15,42 +15,21 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\ScriptComponent} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\TwigComponents\Component\ScriptComponent} instead */ -class ScriptComponent implements ComponentInterface +readonly class ScriptComponent implements ComponentInterface { - protected Environment $twig; - - protected string $src; - - protected string $type; - - protected ?string $async; - - protected ?string $defer; - - protected ?string $crossorigin; - - protected ?string $integrity; - public function __construct( - Environment $twig, - string $src, - string $type = 'text/javascript', - ?string $async = null, - ?string $defer = null, - ?string $crossorigin = null, - ?string $integrity = null + protected Environment $twig, + protected string $src, + protected string $type = 'text/javascript', + protected ?string $async = null, + protected ?string $defer = null, + protected ?string $crossorigin = null, + protected ?string $integrity = null ) { - $this->twig = $twig; - $this->src = $src; - $this->type = $type; - $this->async = $async; - $this->defer = $defer; - $this->crossorigin = $crossorigin; - $this->integrity = $integrity; } /** - * @param array $parameters + * @param array $parameters */ public function render(array $parameters = []): string { diff --git a/src/lib/Component/Search/GlobalSearchTwigComponent.php b/src/lib/Component/Search/GlobalSearchTwigComponent.php index c1d85b8837..6d7a1e3fee 100644 --- a/src/lib/Component/Search/GlobalSearchTwigComponent.php +++ b/src/lib/Component/Search/GlobalSearchTwigComponent.php @@ -15,22 +15,13 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Twig\Environment; -final class GlobalSearchTwigComponent implements ComponentInterface +final readonly class GlobalSearchTwigComponent implements ComponentInterface { - private Environment $twig; - - private FormFactoryInterface $formFactory; - - private UrlGeneratorInterface $urlGenerator; - public function __construct( - Environment $twig, - FormFactoryInterface $formFactory, - UrlGeneratorInterface $urlGenerator + private Environment $twig, + private FormFactoryInterface $formFactory, + private UrlGeneratorInterface $urlGenerator ) { - $this->twig = $twig; - $this->formFactory = $formFactory; - $this->urlGenerator = $urlGenerator; } public function render(array $parameters = []): string diff --git a/src/lib/Component/TabsComponent.php b/src/lib/Component/TabsComponent.php index 118654fd23..78c2d8323a 100644 --- a/src/lib/Component/TabsComponent.php +++ b/src/lib/Component/TabsComponent.php @@ -17,32 +17,23 @@ use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; use Twig\Environment; -class TabsComponent implements ComponentInterface +readonly class TabsComponent implements ComponentInterface { - protected Environment $twig; - - protected EventDispatcherInterface $eventDispatcher; - - protected string $template; - - protected string $groupIdentifier; - - protected array $parameters; - + /** + * @param array $parameters + */ public function __construct( - Environment $twig, - EventDispatcherInterface $eventDispatcher, - string $template, - string $groupIdentifier, - array $parameters = [] + protected Environment $twig, + protected EventDispatcherInterface $eventDispatcher, + protected string $template, + protected string $groupIdentifier, + protected array $parameters = [] ) { - $this->twig = $twig; - $this->eventDispatcher = $eventDispatcher; - $this->template = $template; - $this->groupIdentifier = $groupIdentifier; - $this->parameters = $parameters; } + /** + * @param array $parameters + */ public function render(array $parameters = []): string { $tabGroup = new TabGroup($this->groupIdentifier); @@ -68,6 +59,9 @@ public function render(array $parameters = []): string ); } + /** + * @param array $parameters + */ private function dispatchTabPreRenderEvent(TabInterface $tab, array $parameters): TabEvent { $tabEvent = new TabEvent(); @@ -79,6 +73,11 @@ private function dispatchTabPreRenderEvent(TabInterface $tab, array $parameters) return $tabEvent; } + /** + * @param array $parameters + * + * @return array{name: string, view: string, identifier: string} + */ private function composeTabParameters(TabInterface $tab, array $parameters): array { return [ diff --git a/src/lib/Component/TwigComponent.php b/src/lib/Component/TwigComponent.php index 566c9a66e9..43047b8bca 100644 --- a/src/lib/Component/TwigComponent.php +++ b/src/lib/Component/TwigComponent.php @@ -15,36 +15,26 @@ * @deprecated 4.6.19 The {@see \Ibexa\AdminUi\Component\TwigComponent} class is deprecated, will be removed in 6.0. * Use {@see \Ibexa\TwigComponents\Component\TemplateComponent} instead */ -class TwigComponent implements ComponentInterface +readonly class TwigComponent implements ComponentInterface { - protected string $template; - - protected Environment $twig; - - protected array $parameters; - /** - * @param \Twig\Environment $twig - * @param string $template - * @param array $parameters + * @param array $parameters */ public function __construct( - Environment $twig, - string $template, - array $parameters = [] + protected Environment $twig, + protected string $template, + protected array $parameters = [] ) { - $this->twig = $twig; - $this->template = $template; - $this->parameters = $parameters; } /** - * @param array $parameters - * - * @return string + * @param array $parameters */ public function render(array $parameters = []): string { - return $this->twig->render($this->template, $parameters + $this->parameters); + return $this->twig->render( + $this->template, + $parameters + $this->parameters + ); } } diff --git a/src/lib/Config/AdminUiForms/ContentTypeFieldTypesResolver.php b/src/lib/Config/AdminUiForms/ContentTypeFieldTypesResolver.php index a5be5280e0..0df10ad50e 100644 --- a/src/lib/Config/AdminUiForms/ContentTypeFieldTypesResolver.php +++ b/src/lib/Config/AdminUiForms/ContentTypeFieldTypesResolver.php @@ -14,13 +14,10 @@ /** * @internal */ -final class ContentTypeFieldTypesResolver implements ContentTypeFieldTypesResolverInterface +final readonly class ContentTypeFieldTypesResolver implements ContentTypeFieldTypesResolverInterface { - private ConfigResolverInterface $configResolver; - - public function __construct(ConfigResolverInterface $configResolver) + public function __construct(private ConfigResolverInterface $configResolver) { - $this->configResolver = $configResolver; } /** diff --git a/src/lib/Event/AddContentTypeGroupToUIConfigEvent.php b/src/lib/Event/AddContentTypeGroupToUIConfigEvent.php index 7eba95894c..d22188fdbc 100644 --- a/src/lib/Event/AddContentTypeGroupToUIConfigEvent.php +++ b/src/lib/Event/AddContentTypeGroupToUIConfigEvent.php @@ -13,15 +13,11 @@ final class AddContentTypeGroupToUIConfigEvent extends Event { - /** @var array<\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroup> */ - private array $contentTypeGroups; - /** * @param array<\Ibexa\Contracts\Core\Repository\Values\ContentType\ContentTypeGroup> $contentTypeGroups */ - public function __construct(array $contentTypeGroups) + public function __construct(private array $contentTypeGroups) { - $this->contentTypeGroups = $contentTypeGroups; } /** diff --git a/src/lib/Event/CancelEditVersionDraftEvent.php b/src/lib/Event/CancelEditVersionDraftEvent.php index 07736e6086..23ce648617 100644 --- a/src/lib/Event/CancelEditVersionDraftEvent.php +++ b/src/lib/Event/CancelEditVersionDraftEvent.php @@ -15,18 +15,12 @@ final class CancelEditVersionDraftEvent extends Event { - private Content $content; - - private Location $referrerLocation; - private ?Response $response = null; public function __construct( - Content $content, - Location $referrerLocation + private readonly Content $content, + private readonly Location $referrerLocation ) { - $this->content = $content; - $this->referrerLocation = $referrerLocation; } public function getContent(): Content diff --git a/src/lib/Event/FilterContentTypesEvent.php b/src/lib/Event/FilterContentTypesEvent.php index a5cea3d02b..eee39b5305 100644 --- a/src/lib/Event/FilterContentTypesEvent.php +++ b/src/lib/Event/FilterContentTypesEvent.php @@ -15,16 +15,12 @@ */ final class FilterContentTypesEvent extends Event { - /** @phpstan-var array> */ - private array $contentTypeGroups; - /** * @phpstan-param array> $contentTypeGroups */ public function __construct( - array $contentTypeGroups + private array $contentTypeGroups ) { - $this->contentTypeGroups = $contentTypeGroups; } /** diff --git a/src/lib/Event/Options.php b/src/lib/Event/Options.php index 8aa5f7306c..1a92644658 100644 --- a/src/lib/Event/Options.php +++ b/src/lib/Event/Options.php @@ -13,17 +13,16 @@ final class Options implements MutableOptionsBag { - /** @var array */ - private array $options; - /** * @param array $options */ - public function __construct(array $options = []) + public function __construct(private array $options = []) { - $this->options = $options; } + /** + * @return array + */ public function all(): array { return $this->options; diff --git a/src/lib/EventListener/AddNewTranslationFieldDefinition.php b/src/lib/EventListener/AddNewTranslationFieldDefinition.php index e21b2ff7fa..7c7d12e47c 100644 --- a/src/lib/EventListener/AddNewTranslationFieldDefinition.php +++ b/src/lib/EventListener/AddNewTranslationFieldDefinition.php @@ -11,7 +11,7 @@ use Ibexa\Contracts\AdminUi\Event\FieldDefinitionMappingEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class AddNewTranslationFieldDefinition implements EventSubscriberInterface +final readonly class AddNewTranslationFieldDefinition implements EventSubscriberInterface { public static function getSubscribedEvents(): array { @@ -30,8 +30,13 @@ public function addNewTranslation(FieldDefinitionMappingEvent $event): void $fieldDefinitionData = $event->getFieldDefinitionData(); $fieldDefinition = $event->getFieldDefinition(); - $fieldDefinitionData->names[$targetLanguage->languageCode] = $fieldDefinition->getName($baseLanguage->languageCode); - $fieldDefinitionData->descriptions[$targetLanguage->languageCode] = $fieldDefinition->getDescription($baseLanguage->languageCode); + $fieldDefinitionData->names[$targetLanguage->getLanguageCode()] = $fieldDefinition->getName( + $baseLanguage->getLanguageCode() + ); + + $fieldDefinitionData->descriptions[$targetLanguage->getLanguageCode()] = $fieldDefinition->getDescription( + $baseLanguage->getLanguageCode() + ); $event->setFieldDefinitionData($fieldDefinitionData); } diff --git a/src/lib/EventListener/AdminExceptionListener.php b/src/lib/EventListener/AdminExceptionListener.php index 115bec7cf3..82de4e124b 100644 --- a/src/lib/EventListener/AdminExceptionListener.php +++ b/src/lib/EventListener/AdminExceptionListener.php @@ -11,6 +11,7 @@ use Ibexa\Bundle\AdminUi\IbexaAdminUiBundle; use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Ibexa\Core\MVC\Symfony\SiteAccess; +use JMS\TranslationBundle\Annotation\Ignore; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use SplFileInfo; @@ -28,56 +29,22 @@ class AdminExceptionListener implements LoggerAwareInterface { use LoggerAwareTrait; - protected NotificationHandlerInterface $notificationHandler; - - protected Environment $twig; - - protected TagRenderer $encoreTagRenderer; - - private EntrypointLookupCollectionInterface $entrypointLookupCollection; - - protected array $siteAccessGroups; - - protected string $rootDir; - - protected string $kernelEnvironment; - - /** @var \Psr\Log\LogLevel::* */ - private string $logLevel; - /** - * @param \Twig\Environment $twig - * @param \Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface $notificationHandler - * @param \Symfony\WebpackEncoreBundle\Asset\TagRenderer $encoreTagRenderer - * @param \Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollectionInterface $entrypointLookupCollection - * @param array $siteAccessGroups - * @param string $kernelRootDir - * @param string $kernelEnvironment + * @param array $siteAccessGroups * @param \Psr\Log\LogLevel::* $logLevel */ public function __construct( - Environment $twig, - NotificationHandlerInterface $notificationHandler, - TagRenderer $encoreTagRenderer, - EntrypointLookupCollectionInterface $entrypointLookupCollection, - array $siteAccessGroups, - string $kernelProjectDir, - string $kernelEnvironment, - string $logLevel + protected Environment $twig, + protected NotificationHandlerInterface $notificationHandler, + protected TagRenderer $encoreTagRenderer, + protected EntrypointLookupCollectionInterface $entrypointLookupCollection, + protected array $siteAccessGroups, + protected string $rootDir, + protected string $kernelEnvironment, + private readonly string $logLevel ) { - $this->twig = $twig; - $this->notificationHandler = $notificationHandler; - $this->encoreTagRenderer = $encoreTagRenderer; - $this->entrypointLookupCollection = $entrypointLookupCollection; - $this->siteAccessGroups = $siteAccessGroups; - $this->rootDir = $kernelProjectDir; - $this->kernelEnvironment = $kernelEnvironment; - $this->logLevel = $logLevel; } - /** - * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event - */ public function onKernelException(ExceptionEvent $event): void { if ($this->kernelEnvironment !== 'prod') { @@ -104,7 +71,7 @@ public function onKernelException(ExceptionEvent $event): void $this->notificationHandler->error(/** @Ignore */ $this->getNotificationMessage($exception) ); - $this->logger->log($this->logLevel, $exception->getMessage(), [ + $this->logger?->log($this->logLevel, $exception->getMessage(), [ 'exception' => $exception, ]); @@ -132,11 +99,6 @@ public function onKernelException(ExceptionEvent $event): void $event->setResponse($response); } - /** - * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event - * - * @return bool - */ private function isAdminException(ExceptionEvent $event): bool { $request = $event->getRequest(); @@ -144,14 +106,12 @@ private function isAdminException(ExceptionEvent $event): bool /** @var \Ibexa\Core\MVC\Symfony\SiteAccess $siteAccess */ $siteAccess = $request->get('siteaccess', new SiteAccess('default')); - return \in_array($siteAccess->name, $this->siteAccessGroups[IbexaAdminUiBundle::ADMIN_GROUP_NAME]); + return in_array( + $siteAccess->name, + $this->siteAccessGroups[IbexaAdminUiBundle::ADMIN_GROUP_NAME] + ); } - /** - * @param \Throwable $exception - * - * @return string - */ private function getNotificationMessage(Throwable $exception): string { if ($exception instanceof HttpExceptionInterface) { diff --git a/src/lib/EventListener/ContentDownloadRouteReferenceListener.php b/src/lib/EventListener/ContentDownloadRouteReferenceListener.php index 6b7cb27926..a3f28f4d60 100644 --- a/src/lib/EventListener/ContentDownloadRouteReferenceListener.php +++ b/src/lib/EventListener/ContentDownloadRouteReferenceListener.php @@ -15,19 +15,19 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** - * Ensures that download urls generated in ezplatform-admin-ui are in the scope of admin siteaccess. + * Ensures that download urls generated in ibexa/admin-ui are in the scope of admin siteaccess. * * @internal for internal use by AdminUI */ -final class ContentDownloadRouteReferenceListener implements EventSubscriberInterface +final readonly class ContentDownloadRouteReferenceListener implements EventSubscriberInterface { - public const CONTENT_DOWNLOAD_ROUTE_NAME = 'ibexa.content.download'; + public const string CONTENT_DOWNLOAD_ROUTE_NAME = 'ibexa.content.download'; - private array $siteAccessGroups; - - public function __construct(array $siteAccessGroups) + /** + * @param array $siteAccessGroups + */ + public function __construct(private array $siteAccessGroups) { - $this->siteAccessGroups = $siteAccessGroups; } public static function getSubscribedEvents(): array @@ -52,6 +52,9 @@ public function onRouteReferenceGeneration(RouteReferenceGenerationEvent $event) } } + /** + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException + */ private function isAdminSiteAccess(SiteAccess $siteAccess): bool { return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($siteAccess); diff --git a/src/lib/EventListener/ContentProxyCreateDraftListener.php b/src/lib/EventListener/ContentProxyCreateDraftListener.php index e4db86e0c6..164dafd0d3 100644 --- a/src/lib/EventListener/ContentProxyCreateDraftListener.php +++ b/src/lib/EventListener/ContentProxyCreateDraftListener.php @@ -19,26 +19,14 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; -class ContentProxyCreateDraftListener implements EventSubscriberInterface +final readonly class ContentProxyCreateDraftListener implements EventSubscriberInterface { - private ContentService $contentService; - - private LocationService $locationService; - - private AutosaveServiceInterface $autosaveService; - - private RouterInterface $router; - public function __construct( - ContentService $contentService, - LocationService $locationService, - AutosaveServiceInterface $autosaveService, - RouterInterface $router + private ContentService $contentService, + private LocationService $locationService, + private AutosaveServiceInterface $autosaveService, + private RouterInterface $router ) { - $this->contentService = $contentService; - $this->locationService = $locationService; - $this->autosaveService = $autosaveService; - $this->router = $router; } public static function getSubscribedEvents(): array @@ -75,17 +63,17 @@ public function create(ContentProxyCreateEvent $event): void if ($options->get(ContentProxyCreateEvent::OPTION_IS_ON_THE_FLY, false)) { $response = new RedirectResponse( $this->router->generate('ibexa.content.on_the_fly.edit', [ - 'contentId' => $contentDraft->id, - 'versionNo' => $contentDraft->getVersionInfo()->versionNo, + 'contentId' => $contentDraft->getId(), + 'versionNo' => $contentDraft->getVersionInfo()->getVersionNo(), 'languageCode' => $event->getLanguageCode(), - 'locationId' => $contentDraft->contentInfo->mainLocationId, + 'locationId' => $contentDraft->getContentInfo()->getMainLocationId(), ]) ); } else { $response = new RedirectResponse( $this->router->generate('ibexa.content.draft.edit', [ - 'contentId' => $contentDraft->id, - 'versionNo' => $contentDraft->getVersionInfo()->versionNo, + 'contentId' => $contentDraft->getId(), + 'versionNo' => $contentDraft->getVersionInfo()->getVersionNo(), 'language' => $event->getLanguageCode(), ]) ); @@ -116,7 +104,7 @@ public function translate(ContentProxyTranslateEvent $event): void $contentUpdateStruct->fields = $this->getTranslatedContentFields($content, $toLanguageCode); } - $contentDraft = $this->contentService->createContentDraft($content->contentInfo); + $contentDraft = $this->contentService->createContentDraft($content->getContentInfo()); $this->contentService->updateContent( $contentDraft->getVersionInfo(), @@ -126,8 +114,8 @@ public function translate(ContentProxyTranslateEvent $event): void $response = new RedirectResponse( $this->router->generate('ibexa.content.draft.edit', [ - 'contentId' => $contentDraft->id, - 'versionNo' => $contentDraft->getVersionInfo()->versionNo, + 'contentId' => $contentDraft->getId(), + 'versionNo' => $contentDraft->getVersionInfo()->getVersionNo(), 'language' => $toLanguageCode, 'locationId' => $event->getLocationId(), ]) @@ -136,19 +124,24 @@ public function translate(ContentProxyTranslateEvent $event): void $event->setResponse($response); } + /** + * @return \Ibexa\Contracts\Core\Repository\Values\Content\Field[] + */ private function getTranslatedContentFields(Content $content, string $languageCode): array { $contentType = $content->getContentType(); $translatableFields = array_filter($content->getFields(), static function (Field $field) use ($contentType): bool { - return $contentType->getFieldDefinition($field->fieldDefIdentifier)->isTranslatable; + return $contentType->getFieldDefinition( + $field->getFieldDefinitionIdentifier() + )->isTranslatable(); }); return array_map(static function (Field $field) use ($languageCode): Field { return new Field([ - 'value' => $field->value, - 'fieldDefIdentifier' => $field->fieldDefIdentifier, - 'fieldTypeIdentifier' => $field->fieldTypeIdentifier, + 'value' => $field->getValue(), + 'fieldDefIdentifier' => $field->getFieldDefinitionIdentifier(), + 'fieldTypeIdentifier' => $field->getFieldTypeIdentifier(), 'languageCode' => $languageCode, ]); }, $translatableFields); diff --git a/src/lib/EventListener/ContentTranslateViewFilterParametersListener.php b/src/lib/EventListener/ContentTranslateViewFilterParametersListener.php index 75a4f90d5c..3d2257b46b 100644 --- a/src/lib/EventListener/ContentTranslateViewFilterParametersListener.php +++ b/src/lib/EventListener/ContentTranslateViewFilterParametersListener.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\EventListener; @@ -13,25 +14,13 @@ use Ibexa\Core\MVC\Symfony\View\ViewEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -/** - * {@inheritdoc} - */ -class ContentTranslateViewFilterParametersListener implements EventSubscriberInterface +readonly class ContentTranslateViewFilterParametersListener implements EventSubscriberInterface { - protected ContentTypeService $contentTypeService; - - /** - * @param \Ibexa\Contracts\Core\Repository\ContentTypeService $contentTypeService - */ public function __construct( - ContentTypeService $contentTypeService + protected ContentTypeService $contentTypeService ) { - $this->contentTypeService = $contentTypeService; } - /** - * @return array - */ public static function getSubscribedEvents(): array { return [ @@ -39,11 +28,6 @@ public static function getSubscribedEvents(): array ]; } - /** - * @param \Ibexa\Core\MVC\Symfony\View\Event\FilterViewParametersEvent $event - * - * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException - */ public function onFilterViewParameters(FilterViewParametersEvent $event): void { $view = $event->getView(); diff --git a/src/lib/EventListener/ContentTypeSuggestionsListener.php b/src/lib/EventListener/ContentTypeSuggestionsListener.php index f6c631fad8..e9f2241cbc 100644 --- a/src/lib/EventListener/ContentTypeSuggestionsListener.php +++ b/src/lib/EventListener/ContentTypeSuggestionsListener.php @@ -19,21 +19,15 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Contracts\Translation\TranslatorInterface; -final class ContentTypeSuggestionsListener implements EventSubscriberInterface +final readonly class ContentTypeSuggestionsListener implements EventSubscriberInterface { - private const SUGGESTIONS_AGGREGATION_KEY = 'suggestions'; + private const string SUGGESTIONS_AGGREGATION_KEY = 'suggestions'; - private SearchService $searchService; - - private TranslatorInterface $translator; - - private int $limit; - - public function __construct(SearchService $searchService, TranslatorInterface $translator, int $limit = 4) - { - $this->searchService = $searchService; - $this->translator = $translator; - $this->limit = $limit; + public function __construct( + private SearchService $searchService, + private TranslatorInterface $translator, + private int $limit = 4 + ) { } public static function getSubscribedEvents(): array @@ -76,7 +70,7 @@ private function isContentTypeAvailable(array $contentTypes, ContentType $needle { foreach ($contentTypes as $group) { foreach ($group as $contentType) { - if ($contentType->identifier === $needle->identifier) { + if ($contentType->getIdentifier() === $needle->getIdentifier()) { return true; } } @@ -105,7 +99,7 @@ private function getSuggestions(Location $location): array $query = new LocationQuery(); $query->limit = 0; - $query->filter = new ParentLocationId($location->id); + $query->filter = new ParentLocationId($location->getId()); $query->aggregations[] = $aggregation; $query->performCount = false; diff --git a/src/lib/EventListener/CredentialsExpirationWarningListener.php b/src/lib/EventListener/CredentialsExpirationWarningListener.php index df08d95424..740d7900b9 100644 --- a/src/lib/EventListener/CredentialsExpirationWarningListener.php +++ b/src/lib/EventListener/CredentialsExpirationWarningListener.php @@ -14,6 +14,7 @@ use Ibexa\Contracts\AdminUi\Notification\NotificationHandlerInterface; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Core\MVC\Symfony\Security\UserInterface; +use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -21,31 +22,18 @@ use Symfony\Component\Security\Http\SecurityEvents; use Symfony\Contracts\Translation\TranslatorInterface; -final class CredentialsExpirationWarningListener implements EventSubscriberInterface +final readonly class CredentialsExpirationWarningListener implements EventSubscriberInterface { - private NotificationHandlerInterface $notificationHandler; - - private TranslatorInterface $translator; - - private UrlGeneratorInterface $urlGenerator; - - private UserService $userService; - - /** @var string[][] */ - private array $siteAccessGroups; - + /** + * @param array $siteAccessGroups + */ public function __construct( - NotificationHandlerInterface $notificationHandler, - TranslatorInterface $translator, - UrlGeneratorInterface $urlGenerator, - UserService $userService, - array $siteAccessGroups + private NotificationHandlerInterface $notificationHandler, + private TranslatorInterface $translator, + private UrlGeneratorInterface $urlGenerator, + private UserService $userService, + private array $siteAccessGroups ) { - $this->notificationHandler = $notificationHandler; - $this->translator = $translator; - $this->urlGenerator = $urlGenerator; - $this->siteAccessGroups = $siteAccessGroups; - $this->userService = $userService; } public function onAuthenticationSuccess(InteractiveLoginEvent $event): void @@ -107,6 +95,8 @@ private function generateNotification(DateTimeInterface $passwordExpiresAt): voi private function isAdminSiteAccess(Request $request): bool { - return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess')); + return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy( + $request->attributes->get('siteaccess') + ); } } diff --git a/src/lib/EventListener/CredentialsExpiredListener.php b/src/lib/EventListener/CredentialsExpiredListener.php index 412d07aad0..d7c24b417d 100644 --- a/src/lib/EventListener/CredentialsExpiredListener.php +++ b/src/lib/EventListener/CredentialsExpiredListener.php @@ -17,21 +17,15 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -final class CredentialsExpiredListener implements EventSubscriberInterface +final readonly class CredentialsExpiredListener implements EventSubscriberInterface { - private RequestStack $requestStack; - - /** @var string[][] */ - private array $siteAccessGroups; - /** - * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack - * @param string[] $siteAccessGroups + * @param array $siteAccessGroups */ - public function __construct(RequestStack $requestStack, array $siteAccessGroups) - { - $this->requestStack = $requestStack; - $this->siteAccessGroups = $siteAccessGroups; + public function __construct( + private RequestStack $requestStack, + private array $siteAccessGroups + ) { } public static function getSubscribedEvents(): array @@ -60,6 +54,8 @@ public function onPreContentView(PreContentViewEvent $event): void private function isAdminSiteAccess(Request $request): bool { - return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess')); + return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy( + $request->attributes->get('siteaccess') + ); } } diff --git a/src/lib/EventListener/InContextTranslationListener.php b/src/lib/EventListener/InContextTranslationListener.php index a894da239a..343a111b9a 100644 --- a/src/lib/EventListener/InContextTranslationListener.php +++ b/src/lib/EventListener/InContextTranslationListener.php @@ -18,25 +18,18 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Contracts\Translation\TranslatorInterface; -final class InContextTranslationListener implements EventSubscriberInterface +final readonly class InContextTranslationListener implements EventSubscriberInterface { - private const ACHOLI_LANG = 'ach-UG'; - - private UserSettingService $userSettingService; - - /** @var string[] */ - private array $siteAccessGroups; - - private TranslatorInterface $translator; + private const string ACHOLI_LANG = 'ach-UG'; + /** + * @param array $siteAccessGroups + */ public function __construct( - array $siteAccessGroups, - UserSettingService $userSettingService, - TranslatorInterface $translator + private array $siteAccessGroups, + private UserSettingService $userSettingService, + private TranslatorInterface $translator ) { - $this->siteAccessGroups = $siteAccessGroups; - $this->userSettingService = $userSettingService; - $this->translator = $translator; } /** @@ -72,6 +65,8 @@ public function setInContextTranslation(RequestEvent $event): void private function isAdminSiteAccess(Request $request): bool { - return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess')); + return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy( + $request->attributes->get('siteaccess') + ); } } diff --git a/src/lib/EventListener/MenuPermissionsListener.php b/src/lib/EventListener/MenuPermissionsListener.php index 55080e9f36..5f0d83538b 100644 --- a/src/lib/EventListener/MenuPermissionsListener.php +++ b/src/lib/EventListener/MenuPermissionsListener.php @@ -13,29 +13,18 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class MenuPermissionsListener implements EventSubscriberInterface +final readonly class MenuPermissionsListener implements EventSubscriberInterface { - private PermissionResolver $permissionResolver; - - /** - * @param \Ibexa\Contracts\Core\Repository\PermissionResolver $permissionResolver - */ - public function __construct(PermissionResolver $permissionResolver) + public function __construct(private PermissionResolver $permissionResolver) { - $this->permissionResolver = $permissionResolver; } - /** - * @return array - */ public static function getSubscribedEvents(): array { return [ConfigureMenuEvent::MAIN_MENU => 'checkPermissions']; } /** - * @param \Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent $event - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ public function checkPermissions(ConfigureMenuEvent $event): void diff --git a/src/lib/EventListener/PopulateFieldDefinitionData.php b/src/lib/EventListener/PopulateFieldDefinitionData.php index 9942948ec2..5924d235e3 100644 --- a/src/lib/EventListener/PopulateFieldDefinitionData.php +++ b/src/lib/EventListener/PopulateFieldDefinitionData.php @@ -11,7 +11,7 @@ use Ibexa\Contracts\AdminUi\Event\FieldDefinitionMappingEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class PopulateFieldDefinitionData implements EventSubscriberInterface +final readonly class PopulateFieldDefinitionData implements EventSubscriberInterface { public static function getSubscribedEvents(): array { @@ -23,19 +23,19 @@ public function populateFieldDefinition(FieldDefinitionMappingEvent $event): voi $fieldDefinition = $event->getFieldDefinition(); $fieldDefinitionData = $event->getFieldDefinitionData(); - $fieldDefinitionData->identifier = $fieldDefinition->identifier; + $fieldDefinitionData->identifier = $fieldDefinition->getIdentifier(); $fieldDefinitionData->names = $fieldDefinition->getNames(); $fieldDefinitionData->descriptions = $fieldDefinition->getDescriptions(); - $fieldDefinitionData->fieldGroup = $fieldDefinition->fieldGroup; - $fieldDefinitionData->position = $fieldDefinition->position; - $fieldDefinitionData->isTranslatable = $fieldDefinition->isTranslatable; - $fieldDefinitionData->isRequired = $fieldDefinition->isRequired; - $fieldDefinitionData->isThumbnail = $fieldDefinition->isThumbnail; - $fieldDefinitionData->isInfoCollector = $fieldDefinition->isInfoCollector; + $fieldDefinitionData->fieldGroup = $fieldDefinition->getFieldGroup(); + $fieldDefinitionData->position = $fieldDefinition->getPosition(); + $fieldDefinitionData->isTranslatable = $fieldDefinition->isTranslatable(); + $fieldDefinitionData->isRequired = $fieldDefinition->isRequired(); + $fieldDefinitionData->isThumbnail = $fieldDefinition->isThumbnail(); + $fieldDefinitionData->isInfoCollector = $fieldDefinition->isInfoCollector(); $fieldDefinitionData->validatorConfiguration = $fieldDefinition->getValidatorConfiguration(); $fieldDefinitionData->fieldSettings = $fieldDefinition->getFieldSettings(); - $fieldDefinitionData->defaultValue = $fieldDefinition->defaultValue; - $fieldDefinitionData->isSearchable = $fieldDefinition->isSearchable; + $fieldDefinitionData->defaultValue = $fieldDefinition->getDefaultValue(); + $fieldDefinitionData->isSearchable = $fieldDefinition->isSearchable(); $event->setFieldDefinitionData($fieldDefinitionData); } diff --git a/src/lib/EventListener/RequestAttributesListener.php b/src/lib/EventListener/RequestAttributesListener.php index b7d042e897..6fa3baddfd 100644 --- a/src/lib/EventListener/RequestAttributesListener.php +++ b/src/lib/EventListener/RequestAttributesListener.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\EventListener; @@ -20,22 +21,17 @@ /** * Collects parameters for the ViewBuilder from the Request. */ -class RequestAttributesListener implements EventSubscriberInterface +final readonly class RequestAttributesListener implements EventSubscriberInterface { - private const TRANSLATED_CONTENT_VIEW_ROUTE_NAME = 'ibexa.content.translation.view'; - - private Repository $repository; - - private array $siteAccessGroups; + private const string TRANSLATED_CONTENT_VIEW_ROUTE_NAME = 'ibexa.content.translation.view'; /** - * @param array $siteAccessGroups - * @param \Ibexa\Contracts\Core\Repository\Repository $repository + * @param array $siteAccessGroups */ - public function __construct(array $siteAccessGroups, Repository $repository) - { - $this->repository = $repository; - $this->siteAccessGroups = $siteAccessGroups; + public function __construct( + private array $siteAccessGroups, + private Repository $repository + ) { } public static function getSubscribedEvents(): array @@ -46,8 +42,6 @@ public static function getSubscribedEvents(): array /** * Adds all the request attributes to the parameters. * - * @param \Ibexa\Core\MVC\Symfony\View\Event\FilterViewBuilderParametersEvent $event - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ @@ -72,17 +66,11 @@ public function addRequestAttributes(FilterViewBuilderParametersEvent $event): v $languageCode = $parameterBag->get('languageCode'); - $content = $this->loadContent($location->contentInfo->id, $languageCode); + $content = $this->loadContent($location->getContentInfo()->getId(), $languageCode); $parameterBag->set('content', $content); } } - /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @param \Symfony\Component\HttpFoundation\ParameterBag $parameterBag - * - * @return bool - */ private function hasContentLanguage(Request $request, ParameterBag $parameterBag): bool { return $parameterBag->has('languageCode') @@ -90,40 +78,35 @@ private function hasContentLanguage(Request $request, ParameterBag $parameterBag && $request->get('_route') === self::TRANSLATED_CONTENT_VIEW_ROUTE_NAME; } - /** - * @param int $locationId - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Location - */ private function loadLocation(int $locationId): Location { - $location = $this->repository->sudo( + return $this->repository->sudo( static function (Repository $repository) use ($locationId): Location { return $repository->getLocationService()->loadLocation($locationId); } ); - - return $location; } /** - * @param int $contentId - * @param string $language - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Content - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException */ private function loadContent(int $contentId, ?string $language): Content { - return $this->repository->getContentService()->loadContent($contentId, $language ? [$language] : null); + return $this->repository->getContentService()->loadContent( + $contentId, + $language ? [$language] : null + ); } private function isAdmin(Request $request): bool { $siteAccess = $request->attributes->get('siteaccess'); - return \in_array($siteAccess->name, $this->siteAccessGroups[IbexaAdminUiBundle::ADMIN_GROUP_NAME], true); + return in_array( + $siteAccess->name, + $this->siteAccessGroups[IbexaAdminUiBundle::ADMIN_GROUP_NAME], + true + ); } } diff --git a/src/lib/EventListener/RequestListener.php b/src/lib/EventListener/RequestListener.php index a0f66ceb6d..0f088ab905 100644 --- a/src/lib/EventListener/RequestListener.php +++ b/src/lib/EventListener/RequestListener.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\EventListener; @@ -14,16 +15,13 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; -class RequestListener implements EventSubscriberInterface +final readonly class RequestListener implements EventSubscriberInterface { - private array $groupsBySiteAccess; - /** - * @param $groupsBySiteAccess + * @param array $groupsBySiteAccess */ - public function __construct(array $groupsBySiteAccess) + public function __construct(private array $groupsBySiteAccess) { - $this->groupsBySiteAccess = $groupsBySiteAccess; } /** @@ -42,7 +40,7 @@ public function __construct(array $groupsBySiteAccess) * * array('eventName' => array('methodName', $priority)) * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))) * - * @return array The event names to listen to + * Returns the event names to listen to */ public static function getSubscribedEvents(): array { diff --git a/src/lib/EventListener/RequestLocaleListener.php b/src/lib/EventListener/RequestLocaleListener.php index e210246f36..50202d7c8c 100644 --- a/src/lib/EventListener/RequestLocaleListener.php +++ b/src/lib/EventListener/RequestLocaleListener.php @@ -18,37 +18,19 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Contracts\Translation\TranslatorInterface; -class RequestLocaleListener implements EventSubscriberInterface +final readonly class RequestLocaleListener implements EventSubscriberInterface { - private array $siteAccessGroups; - - private array $availableTranslations; - - private TranslatorInterface $translator; - - private UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider; - - private ConfigResolverInterface $configResolver; - /** - * @param array $siteAccessGroups - * @param array $availableTranslations - * @param \Symfony\Contracts\Translation\TranslatorInterface $translator - * @param \Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider - * @param \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface $configResolver + * @param array $siteAccessGroups + * @param string[] $availableTranslations */ public function __construct( - array $siteAccessGroups, - array $availableTranslations, - TranslatorInterface $translator, - UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider, - ConfigResolverInterface $configResolver + private array $siteAccessGroups, + private array $availableTranslations, + private TranslatorInterface $translator, + private UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider, + private ConfigResolverInterface $configResolver ) { - $this->siteAccessGroups = $siteAccessGroups; - $this->availableTranslations = $availableTranslations; - $this->translator = $translator; - $this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider; - $this->configResolver = $configResolver; } /** @@ -62,8 +44,6 @@ public static function getSubscribedEvents(): array } /** - * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event - * * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException */ public function onKernelRequest(RequestEvent $event): void @@ -74,13 +54,16 @@ public function onKernelRequest(RequestEvent $event): void return; } - $additionalTranslations = $this->configResolver->getParameter('user_preferences.additional_translations'); + $additionalTranslations = $this->configResolver->getParameter( + 'user_preferences.additional_translations' + ); + $preferableLocales = $this->userLanguagePreferenceProvider->getPreferredLocales($request); $locale = null; foreach ($preferableLocales as $preferableLocale) { - if (\in_array($preferableLocale, $this->availableTranslations, true) - || \in_array($preferableLocale, $additionalTranslations, true) + if (in_array($preferableLocale, $this->availableTranslations, true) + || in_array($preferableLocale, $additionalTranslations, true) ) { $locale = $preferableLocale; break; @@ -95,14 +78,12 @@ public function onKernelRequest(RequestEvent $event): void } /** - * @param \Symfony\Component\HttpFoundation\Request $request - * - * @return bool - * * @throws \Ibexa\AdminUi\Exception\InvalidArgumentException */ - protected function isAdminSiteAccess(Request $request): bool + private function isAdminSiteAccess(Request $request): bool { - return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess')); + return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy( + $request->attributes->get('siteaccess') + ); } } diff --git a/src/lib/EventListener/SearchViewFilterParametersListener.php b/src/lib/EventListener/SearchViewFilterParametersListener.php index 9dcde0f90d..1235dd9a83 100644 --- a/src/lib/EventListener/SearchViewFilterParametersListener.php +++ b/src/lib/EventListener/SearchViewFilterParametersListener.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\EventListener; @@ -19,27 +20,17 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; -final class SearchViewFilterParametersListener implements EventSubscriberInterface +final readonly class SearchViewFilterParametersListener implements EventSubscriberInterface { - private FormFactoryInterface $formFactory; - - private ConfigResolverInterface $configResolver; - - private RequestStack $requestStack; - - /** @var string[][] */ - private array $siteAccessGroups; - + /** + * @param array $siteAccessGroups + */ public function __construct( - FormFactoryInterface $formFactory, - ConfigResolverInterface $configResolver, - RequestStack $requestStack, - array $siteAccessGroups + private FormFactoryInterface $formFactory, + private ConfigResolverInterface $configResolver, + private RequestStack $requestStack, + private array $siteAccessGroups ) { - $this->formFactory = $formFactory; - $this->configResolver = $configResolver; - $this->requestStack = $requestStack; - $this->siteAccessGroups = $siteAccessGroups; } public static function getSubscribedEvents(): array @@ -57,7 +48,12 @@ public function onFilterViewParameters(FilterViewParametersEvent $event): void return; } - if (!$this->isAdminSiteAccess($this->requestStack->getCurrentRequest())) { + $request = $this->requestStack->getCurrentRequest(); + if (null === $request) { + return; + } + + if (!$this->isAdminSiteAccess($request)) { return; } @@ -68,12 +64,16 @@ public function onFilterViewParameters(FilterViewParametersEvent $event): void $event->getParameterBag()->add([ 'form_edit' => $editForm->createView(), - 'user_content_type_identifier' => $this->configResolver->getParameter('user_content_type_identifier'), + 'user_content_type_identifier' => $this->configResolver->getParameter( + 'user_content_type_identifier' + ), ]); } private function isAdminSiteAccess(Request $request): bool { - return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess')); + return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy( + $request->attributes->get('siteaccess') + ); } } diff --git a/src/lib/EventListener/SetViewParametersListener.php b/src/lib/EventListener/SetViewParametersListener.php index 90d98bb948..18cc36422e 100644 --- a/src/lib/EventListener/SetViewParametersListener.php +++ b/src/lib/EventListener/SetViewParametersListener.php @@ -32,36 +32,19 @@ /** * @todo It should use ViewEvents::FILTER_VIEW_PARAMETERS event instead. */ -class SetViewParametersListener implements EventSubscriberInterface +readonly class SetViewParametersListener implements EventSubscriberInterface { - protected LocationService $locationService; - - protected UserService $userService; - - private Repository $repository; - - private GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider; - - private ConfigResolverInterface $configResolver; - public function __construct( - LocationService $locationService, - UserService $userService, - Repository $repository, - ConfigResolverInterface $configResolver, - GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider + protected LocationService $locationService, + protected UserService $userService, + private Repository $repository, + private ConfigResolverInterface $configResolver, + private GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider ) { - $this->locationService = $locationService; - $this->userService = $userService; - $this->repository = $repository; - $this->configResolver = $configResolver; - $this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider; } /** * Returns an array of event names this subscriber wants to listen to. - * - * @return array The event names to listen to */ public static function getSubscribedEvents(): array { @@ -77,8 +60,6 @@ public static function getSubscribedEvents(): array } /** - * @param \Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent $event - * * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException @@ -94,8 +75,13 @@ public function setContentEditViewTemplateParameters(PreContentViewEvent $event) /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */ $content = $contentView->getParameter('content'); - $location = $contentView->hasParameter('location') ? $contentView->getParameter('location') : null; - $isPublished = null !== $content->contentInfo->mainLocationId && $content->contentInfo->published; + $location = $contentView->hasParameter('location') + ? $contentView->getParameter('location') + : null; + + $isPublished = + null !== $content->getContentInfo()->getMainLocationId() + && $content->getContentInfo()->isPublished(); $contentView->addParameters([ 'parent_location' => $this->resolveParentLocation($content, $location, $isPublished), @@ -104,19 +90,16 @@ public function setContentEditViewTemplateParameters(PreContentViewEvent $event) if (!$isPublished) { $contentView->addParameters([ - 'parent_locations' => $this->locationService->loadParentLocationsForDraftContent($content->versionInfo), + 'parent_locations' => $this->locationService->loadParentLocationsForDraftContent( + $content->getVersionInfo() + ), ]); } - $contentInfo = $content->versionInfo->contentInfo; - - $this->processCreator($contentInfo, $contentView); + $this->processCreator($content->getContentInfo(), $contentView); } /** - * @param \Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent $event - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException @@ -131,8 +114,10 @@ public function setContentTranslateViewTemplateParameters(PreContentViewEvent $e /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Content $content */ $content = $contentView->getContent(); + $contentInfo = $content->getContentInfo(); $location = $contentView->getLocation(); - $isPublished = null !== $content->contentInfo->mainLocationId && $content->contentInfo->published; + + $isPublished = null !== $contentInfo->getMainLocationId() && $contentInfo->isPublished(); $contentView->addParameters([ 'parent_location' => $this->resolveParentLocation($content, $location, $isPublished), @@ -141,18 +126,17 @@ public function setContentTranslateViewTemplateParameters(PreContentViewEvent $e if (!$isPublished) { $contentView->addParameters([ - 'parent_locations' => $this->locationService->loadParentLocationsForDraftContent($content->versionInfo), + 'parent_locations' => $this->locationService->loadParentLocationsForDraftContent( + $content->getVersionInfo() + ), ]); } - $contentInfo = $content->versionInfo->contentInfo; + $contentInfo = $content->getVersionInfo()->getContentInfo(); $this->processCreator($contentInfo, $contentView); } - /** - * @param \Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent $event - */ public function setUserUpdateViewTemplateParameters(PreContentViewEvent $event): void { $contentView = $event->getContentView(); @@ -163,18 +147,14 @@ public function setUserUpdateViewTemplateParameters(PreContentViewEvent $event): /** @var \Ibexa\Contracts\Core\Repository\Values\User\User $user */ $user = $contentView->getParameter('user'); - $contentInfo = $user->versionInfo->contentInfo; + $contentInfo = $user->getContentInfo(); $this->processCreator($contentInfo, $contentView); } - /** - * @param \Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent $event - */ public function setContentCreateViewTemplateParameters(PreContentViewEvent $event): void { $contentView = $event->getContentView(); - if (!$contentView instanceof ContentCreateView) { return; } @@ -200,15 +180,11 @@ public function setContentFieldsParameters(PreContentViewEvent $event): void $view->setParameters($parameters); } - /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo - * @param \Ibexa\Core\MVC\Symfony\View\View $contentView - */ private function processCreator(ContentInfo $contentInfo, View $contentView): void { try { $creator = $this->userService->loadUser($contentInfo->ownerId); - } catch (NotFoundException $exception) { + } catch (NotFoundException) { $creator = null; } @@ -218,13 +194,6 @@ private function processCreator(ContentInfo $contentInfo, View $contentView): vo } /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Location|null $location - * @param bool $isPublished - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Location - * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException @@ -234,7 +203,9 @@ private function resolveParentLocation(Content $content, ?Location $location, bo if (!$isPublished) { $parentLocations = $this->repository->sudo( static function (Repository $repository) use ($content): iterable { - return $repository->getLocationService()->loadParentLocationsForDraftContent($content->getVersionInfo()); + return $repository->getLocationService()->loadParentLocationsForDraftContent( + $content->getVersionInfo() + ); } ); diff --git a/src/lib/EventListener/TranslateEzSelectionMultilingualOptions.php b/src/lib/EventListener/TranslateSelectionMultilingualOptions.php similarity index 81% rename from src/lib/EventListener/TranslateEzSelectionMultilingualOptions.php rename to src/lib/EventListener/TranslateSelectionMultilingualOptions.php index eae26aca61..3562830d01 100644 --- a/src/lib/EventListener/TranslateEzSelectionMultilingualOptions.php +++ b/src/lib/EventListener/TranslateSelectionMultilingualOptions.php @@ -11,7 +11,7 @@ use Ibexa\Contracts\AdminUi\Event\FieldDefinitionMappingEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class TranslateEzSelectionMultilingualOptions implements EventSubscriberInterface +final readonly class TranslateSelectionMultilingualOptions implements EventSubscriberInterface { public static function getSubscribedEvents(): array { @@ -21,7 +21,7 @@ public static function getSubscribedEvents(): array public function setMultilingualOptions(FieldDefinitionMappingEvent $event): void { $fieldDefinition = $event->getFieldDefinitionData()->fieldDefinition; - if ('ibexa_selection' !== $fieldDefinition->fieldTypeIdentifier) { + if ('ibexa_selection' !== $fieldDefinition->getFieldTypeIdentifier()) { return; } @@ -35,8 +35,8 @@ public function setMultilingualOptions(FieldDefinitionMappingEvent $event): void $fieldDefinitionData = $event->getFieldDefinitionData(); $fieldSettings = $fieldDefinitionData->fieldSettings; - if (isset($fieldSettings['multilingualOptions'][$baseLanguage->languageCode])) { - $fieldSettings['multilingualOptions'][$targetLanguage->languageCode] = $fieldSettings['multilingualOptions'][$baseLanguage->languageCode]; + if (isset($fieldSettings['multilingualOptions'][$baseLanguage->getLanguageCode()])) { + $fieldSettings['multilingualOptions'][$targetLanguage->getLanguageCode()] = $fieldSettings['multilingualOptions'][$baseLanguage->getLanguageCode()]; } $fieldDefinitionData->fieldSettings = $fieldSettings; diff --git a/src/lib/EventListener/UserProfileListener.php b/src/lib/EventListener/UserProfileListener.php index b7d08cbd27..811a341887 100644 --- a/src/lib/EventListener/UserProfileListener.php +++ b/src/lib/EventListener/UserProfileListener.php @@ -25,38 +25,17 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; -final class UserProfileListener implements EventSubscriberInterface +final readonly class UserProfileListener implements EventSubscriberInterface { - private UrlGeneratorInterface $urlGenerator; - - private Repository $repository; - - private PermissionResolver $permissionResolver; - - private ContentService $contentService; - - private UserService $userService; - - private UserProfileConfigurationInterface $configuration; - - private RequestStack $requestStack; - public function __construct( - Repository $repository, - PermissionResolver $permissionResolver, - ContentService $contentService, - UserService $userService, - UrlGeneratorInterface $urlGenerator, - UserProfileConfigurationInterface $configuration, - RequestStack $requestStack + private Repository $repository, + private PermissionResolver $permissionResolver, + private ContentService $contentService, + private UserService $userService, + private UrlGeneratorInterface $urlGenerator, + private UserProfileConfigurationInterface $configuration, + private RequestStack $requestStack ) { - $this->repository = $repository; - $this->permissionResolver = $permissionResolver; - $this->contentService = $contentService; - $this->userService = $userService; - $this->urlGenerator = $urlGenerator; - $this->configuration = $configuration; - $this->requestStack = $requestStack; } public static function getSubscribedEvents(): array @@ -125,7 +104,11 @@ private function createUpdateStruct(UserUpdateData $data, string $languageCode): $updateStruct->contentUpdateStruct = $this->contentService->newContentUpdateStruct(); foreach ($data->getFieldsData() as $fieldDefIdentifier => $fieldData) { - $updateStruct->contentUpdateStruct->setField($fieldDefIdentifier, $fieldData->value, $languageCode); + $updateStruct->contentUpdateStruct->setField( + $fieldDefIdentifier, + $fieldData->getValue(), + $languageCode + ); } return $updateStruct; diff --git a/src/lib/EventListener/ViewTemplatesListener.php b/src/lib/EventListener/ViewTemplatesListener.php index f15ac53350..f1adb5576d 100644 --- a/src/lib/EventListener/ViewTemplatesListener.php +++ b/src/lib/EventListener/ViewTemplatesListener.php @@ -18,13 +18,10 @@ /** * Sets the templates used by the user controller. */ -class ViewTemplatesListener implements EventSubscriberInterface +final readonly class ViewTemplatesListener implements EventSubscriberInterface { - private ConfigResolverInterface $configResolver; - - public function __construct(ConfigResolverInterface $configResolver) + public function __construct(private ConfigResolverInterface $configResolver) { - $this->configResolver = $configResolver; } public static function getSubscribedEvents(): array @@ -35,6 +32,8 @@ public static function getSubscribedEvents(): array /** * If the event's view has a defined template, sets the view's template identifier, * and the 'page_layout' parameter. + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ public function setViewTemplates(PreContentViewEvent $event): void { diff --git a/src/lib/Exception/ContentTypeIconNotFoundException.php b/src/lib/Exception/ContentTypeIconNotFoundException.php index 50b720448a..7498efdb93 100644 --- a/src/lib/Exception/ContentTypeIconNotFoundException.php +++ b/src/lib/Exception/ContentTypeIconNotFoundException.php @@ -11,9 +11,9 @@ use Exception; use RuntimeException; -class ContentTypeIconNotFoundException extends RuntimeException +final class ContentTypeIconNotFoundException extends RuntimeException { - public function __construct($contentType, $code = 0, ?Exception $previous = null) + public function __construct(string $contentType, int $code = 0, ?Exception $previous = null) { parent::__construct("No icon found for '$contentType' content type", $code, $previous); } diff --git a/src/lib/Exception/InvalidArgumentException.php b/src/lib/Exception/InvalidArgumentException.php index 7cdf5fd5ff..2c4c677987 100644 --- a/src/lib/Exception/InvalidArgumentException.php +++ b/src/lib/Exception/InvalidArgumentException.php @@ -10,6 +10,6 @@ use Ibexa\Core\Base\Exceptions\InvalidArgumentException as BaseInvalidArgumentException; -class InvalidArgumentException extends BaseInvalidArgumentException +final class InvalidArgumentException extends BaseInvalidArgumentException { } diff --git a/src/lib/Exception/MenuItemExists.php b/src/lib/Exception/MenuItemExists.php index 17d36ef7a0..72a158a4da 100644 --- a/src/lib/Exception/MenuItemExists.php +++ b/src/lib/Exception/MenuItemExists.php @@ -4,11 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Exception; use Exception; -class MenuItemExists extends Exception +final class MenuItemExists extends Exception { } diff --git a/src/lib/Exception/MenuItemNotExists.php b/src/lib/Exception/MenuItemNotExists.php index 6b63e6b1ba..2b688b5831 100644 --- a/src/lib/Exception/MenuItemNotExists.php +++ b/src/lib/Exception/MenuItemNotExists.php @@ -4,11 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Exception; use Exception; -class MenuItemNotExists extends Exception +final class MenuItemNotExists extends Exception { } diff --git a/src/lib/Exception/MissingLimitationBlockException.php b/src/lib/Exception/MissingLimitationBlockException.php index 8d6497a1a0..2d24829faa 100644 --- a/src/lib/Exception/MissingLimitationBlockException.php +++ b/src/lib/Exception/MissingLimitationBlockException.php @@ -4,11 +4,12 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Exception; use RuntimeException; -class MissingLimitationBlockException extends RuntimeException +final class MissingLimitationBlockException extends RuntimeException { } diff --git a/src/lib/Exception/NoValidResultException.php b/src/lib/Exception/NoValidResultException.php index 4651ecb464..a97f4a043b 100644 --- a/src/lib/Exception/NoValidResultException.php +++ b/src/lib/Exception/NoValidResultException.php @@ -11,15 +11,11 @@ use Exception; use Throwable; -class NoValidResultException extends Exception +final class NoValidResultException extends Exception { - /** - * @param string $message - * @param int $code - */ public function __construct( - $message = 'No valid result from strategy', - $code = 0, + string $message = 'No valid result from strategy', + int $code = 0, ?Throwable $previous = null ) { parent::__construct($message, $code, $previous); diff --git a/src/lib/Exception/ValidationFailedException.php b/src/lib/Exception/ValidationFailedException.php index a97adb6284..be77bbbfe1 100644 --- a/src/lib/Exception/ValidationFailedException.php +++ b/src/lib/Exception/ValidationFailedException.php @@ -14,16 +14,12 @@ final class ValidationFailedException extends InvalidArgumentException { - private ConstraintViolationListInterface $errors; - public function __construct( string $argumentName, - ConstraintViolationListInterface $errors, + private readonly ConstraintViolationListInterface $errors, ?Exception $previous = null ) { parent::__construct($this->createMessage($argumentName, $errors), 0, $previous); - - $this->errors = $errors; } public function getErrors(): ConstraintViolationListInterface diff --git a/src/lib/Exception/ValueMapperNotFoundException.php b/src/lib/Exception/ValueMapperNotFoundException.php index 740122ba75..457de65f1f 100644 --- a/src/lib/Exception/ValueMapperNotFoundException.php +++ b/src/lib/Exception/ValueMapperNotFoundException.php @@ -4,13 +4,14 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Exception; use Exception; use InvalidArgumentException; -class ValueMapperNotFoundException extends InvalidArgumentException +final class ValueMapperNotFoundException extends InvalidArgumentException { public function __construct($limitationType, $code = 0, ?Exception $previous = null) { diff --git a/src/lib/FieldType/FieldDefinitionFormMapperInterface.php b/src/lib/FieldType/FieldDefinitionFormMapperInterface.php index d922b027f5..db29d62afd 100644 --- a/src/lib/FieldType/FieldDefinitionFormMapperInterface.php +++ b/src/lib/FieldType/FieldDefinitionFormMapperInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType; diff --git a/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcher.php b/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcher.php index 037b08cd02..fcd8d790df 100644 --- a/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcher.php +++ b/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcher.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType; @@ -16,7 +17,7 @@ * * Adds the form elements matching the given Field Data (Value or Definition) to a given Form. */ -class FieldTypeDefinitionFormMapperDispatcher implements FieldTypeDefinitionFormMapperDispatcherInterface +final class FieldTypeDefinitionFormMapperDispatcher implements FieldTypeDefinitionFormMapperDispatcherInterface { /** * @param \Ibexa\AdminUi\FieldType\FieldDefinitionFormMapperInterface[] $mappers @@ -32,7 +33,7 @@ public function addMapper(FieldDefinitionFormMapperInterface $mapper, string $fi $this->mappers[$fieldTypeIdentifier] = $mapper; } - public function map(FormInterface $fieldForm, FieldDefinitionData $data): void + public function map(FormInterface $form, FieldDefinitionData $data): void { $fieldTypeIdentifier = $data->getFieldTypeIdentifier(); $fieldTypeIdentifier = $this->fieldTypeAliasResolver->resolveIdentifier($fieldTypeIdentifier); @@ -41,6 +42,6 @@ public function map(FormInterface $fieldForm, FieldDefinitionData $data): void return; } - $this->mappers[$fieldTypeIdentifier]->mapFieldDefinitionForm($fieldForm, $data); + $this->mappers[$fieldTypeIdentifier]->mapFieldDefinitionForm($form, $data); } } diff --git a/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcherInterface.php b/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcherInterface.php index 4db549364a..35e7caa752 100644 --- a/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcherInterface.php +++ b/src/lib/FieldType/FieldTypeDefinitionFormMapperDispatcherInterface.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType; diff --git a/src/lib/FieldType/Mapper/AbstractRelationFormMapper.php b/src/lib/FieldType/Mapper/AbstractRelationFormMapper.php index e3a1842784..8257f7c56b 100644 --- a/src/lib/FieldType/Mapper/AbstractRelationFormMapper.php +++ b/src/lib/FieldType/Mapper/AbstractRelationFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -13,14 +14,10 @@ abstract class AbstractRelationFormMapper implements FieldDefinitionFormMapperInterface { - protected ContentTypeService $contentTypeService; - - protected LocationService $locationService; - - public function __construct(ContentTypeService $contentTypeService, LocationService $locationService) - { - $this->contentTypeService = $contentTypeService; - $this->locationService = $locationService; + public function __construct( + protected ContentTypeService $contentTypeService, + protected LocationService $locationService + ) { } /** @@ -33,7 +30,7 @@ protected function getContentTypesHash(): array $contentTypeHash = []; foreach ($this->contentTypeService->loadContentTypeGroups() as $contentTypeGroup) { foreach ($this->contentTypeService->loadContentTypes($contentTypeGroup) as $contentType) { - $contentTypeHash[$contentType->getName()] = $contentType->identifier; + $contentTypeHash[$contentType->getName()] = $contentType->getIdentifier(); } } ksort($contentTypeHash); diff --git a/src/lib/FieldType/Mapper/AuthorFormMapper.php b/src/lib/FieldType/Mapper/AuthorFormMapper.php index 590c18c599..eec9527395 100644 --- a/src/lib/FieldType/Mapper/AuthorFormMapper.php +++ b/src/lib/FieldType/Mapper/AuthorFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -21,7 +22,7 @@ /** * FormMapper for ibexa_author FieldType. */ -class AuthorFormMapper implements FieldDefinitionFormMapperInterface, FieldValueFormMapperInterface +final class AuthorFormMapper implements FieldDefinitionFormMapperInterface, FieldValueFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/BinaryFileFormMapper.php b/src/lib/FieldType/Mapper/BinaryFileFormMapper.php index ecfd0ac338..41aab63ab9 100644 --- a/src/lib/FieldType/Mapper/BinaryFileFormMapper.php +++ b/src/lib/FieldType/Mapper/BinaryFileFormMapper.php @@ -4,25 +4,22 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; use Ibexa\AdminUi\FieldType\FieldDefinitionFormMapperInterface; use Ibexa\AdminUi\Form\Data\FieldDefinitionData; use Ibexa\ContentForms\ConfigResolver\MaxUploadSize; -use Ibexa\Contracts\Core\Repository\FieldTypeService; use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Validator\Constraints\Range; -class BinaryFileFormMapper implements FieldDefinitionFormMapperInterface +final readonly class BinaryFileFormMapper implements FieldDefinitionFormMapperInterface { - private MaxUploadSize $maxUploadSize; - - public function __construct(FieldTypeService $fieldTypeService, MaxUploadSize $maxUploadSize) + public function __construct(private MaxUploadSize $maxUploadSize) { - $this->maxUploadSize = $maxUploadSize; } public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void diff --git a/src/lib/FieldType/Mapper/CheckboxFormMapper.php b/src/lib/FieldType/Mapper/CheckboxFormMapper.php index 49f4b7b09b..99466294c7 100644 --- a/src/lib/FieldType/Mapper/CheckboxFormMapper.php +++ b/src/lib/FieldType/Mapper/CheckboxFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -17,7 +18,7 @@ /** * FormMapper for ibexa_boolean FieldType. */ -class CheckboxFormMapper implements FieldDefinitionFormMapperInterface +final readonly class CheckboxFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $fieldDefinition): void { diff --git a/src/lib/FieldType/Mapper/CountryFormMapper.php b/src/lib/FieldType/Mapper/CountryFormMapper.php index 471b2860d9..40ca7cc58c 100644 --- a/src/lib/FieldType/Mapper/CountryFormMapper.php +++ b/src/lib/FieldType/Mapper/CountryFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -15,7 +16,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class CountryFormMapper implements FieldDefinitionFormMapperInterface +final readonly class CountryFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/DateFormMapper.php b/src/lib/FieldType/Mapper/DateFormMapper.php index 09f7b9c99c..0bb6ae42d7 100644 --- a/src/lib/FieldType/Mapper/DateFormMapper.php +++ b/src/lib/FieldType/Mapper/DateFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -18,7 +19,7 @@ /** * FormMapper for ibexa_date FieldType. */ -class DateFormMapper implements FieldDefinitionFormMapperInterface +final readonly class DateFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/DateTimeFormMapper.php b/src/lib/FieldType/Mapper/DateTimeFormMapper.php index 93e124b085..09ca0c7157 100644 --- a/src/lib/FieldType/Mapper/DateTimeFormMapper.php +++ b/src/lib/FieldType/Mapper/DateTimeFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -20,7 +21,7 @@ /** * FormMapper for ibexa_datetime FieldType. */ -class DateTimeFormMapper implements FieldDefinitionFormMapperInterface +final readonly class DateTimeFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/FloatFormMapper.php b/src/lib/FieldType/Mapper/FloatFormMapper.php index 6927656e16..fc5c52bfb2 100644 --- a/src/lib/FieldType/Mapper/FloatFormMapper.php +++ b/src/lib/FieldType/Mapper/FloatFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -18,11 +19,11 @@ /** * FormMapper for ibexa_float FieldType. */ -class FloatFormMapper implements FieldDefinitionFormMapperInterface +final readonly class FloatFormMapper implements FieldDefinitionFormMapperInterface { - public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $fieldDefinition): void + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { - $isTranslation = $fieldDefinition->contentTypeData->languageCode !== $fieldDefinition->contentTypeData->mainLanguageCode; + $isTranslation = $data->contentTypeData->languageCode !== $data->contentTypeData->mainLanguageCode; $defaultValueForm = $fieldDefinitionForm ->getConfig() ->getFormFactory() diff --git a/src/lib/FieldType/Mapper/ISBNFormMapper.php b/src/lib/FieldType/Mapper/ISBNFormMapper.php index ece97791d8..bbff2333bb 100644 --- a/src/lib/FieldType/Mapper/ISBNFormMapper.php +++ b/src/lib/FieldType/Mapper/ISBNFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -15,11 +16,11 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class ISBNFormMapper implements FieldDefinitionFormMapperInterface +final readonly class ISBNFormMapper implements FieldDefinitionFormMapperInterface { - public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $fieldDefinition): void + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { - $isTranslation = $fieldDefinition->contentTypeData->languageCode !== $fieldDefinition->contentTypeData->mainLanguageCode; + $isTranslation = $data->contentTypeData->languageCode !== $data->contentTypeData->mainLanguageCode; $defaultValueForm = $fieldDefinitionForm ->getConfig() ->getFormFactory() diff --git a/src/lib/FieldType/Mapper/ImageFormMapper.php b/src/lib/FieldType/Mapper/ImageFormMapper.php index e0b62a1ed2..6b3048f308 100644 --- a/src/lib/FieldType/Mapper/ImageFormMapper.php +++ b/src/lib/FieldType/Mapper/ImageFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -19,26 +20,16 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Range; -class ImageFormMapper implements FieldDefinitionFormMapperInterface +final readonly class ImageFormMapper implements FieldDefinitionFormMapperInterface { - /** @var array */ - private array $allowedMimeTypes; - - private MaxUploadSize $maxUploadSize; - - private MimeTypesInterface $mimeTypes; - /** * @param string[] $allowedMimeTypes */ public function __construct( - array $allowedMimeTypes, - MaxUploadSize $maxUploadSize, - MimeTypesInterface $mimeTypes + private array $allowedMimeTypes, + private MaxUploadSize $maxUploadSize, + private MimeTypesInterface $mimeTypes ) { - $this->allowedMimeTypes = $allowedMimeTypes; - $this->maxUploadSize = $maxUploadSize; - $this->mimeTypes = $mimeTypes; } public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void diff --git a/src/lib/FieldType/Mapper/IntegerFormMapper.php b/src/lib/FieldType/Mapper/IntegerFormMapper.php index 1d1181ccea..d5c186c9ef 100644 --- a/src/lib/FieldType/Mapper/IntegerFormMapper.php +++ b/src/lib/FieldType/Mapper/IntegerFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -18,11 +19,11 @@ /** * FormMapper for ibexa_integer FieldType. */ -class IntegerFormMapper implements FieldDefinitionFormMapperInterface +final readonly class IntegerFormMapper implements FieldDefinitionFormMapperInterface { - public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $fieldDefinition): void + public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { - $isTranslation = $fieldDefinition->contentTypeData->languageCode !== $fieldDefinition->contentTypeData->mainLanguageCode; + $isTranslation = $data->contentTypeData->languageCode !== $data->contentTypeData->mainLanguageCode; $defaultValueForm = $fieldDefinitionForm ->getConfig() ->getFormFactory() diff --git a/src/lib/FieldType/Mapper/MediaFormMapper.php b/src/lib/FieldType/Mapper/MediaFormMapper.php index f555e4367c..aca298533b 100644 --- a/src/lib/FieldType/Mapper/MediaFormMapper.php +++ b/src/lib/FieldType/Mapper/MediaFormMapper.php @@ -4,13 +4,13 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; use Ibexa\AdminUi\FieldType\FieldDefinitionFormMapperInterface; use Ibexa\AdminUi\Form\Data\FieldDefinitionData; use Ibexa\ContentForms\ConfigResolver\MaxUploadSize; -use Ibexa\Contracts\Core\Repository\FieldTypeService; use Ibexa\Core\FieldType\Media\Type; use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -19,16 +19,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Range; -class MediaFormMapper implements FieldDefinitionFormMapperInterface +final readonly class MediaFormMapper implements FieldDefinitionFormMapperInterface { - private MaxUploadSize $maxUploadSize; - - protected const ACCEPT_VIDEO = 'video/*'; - protected const ACCEPT_AUDIO = 'audio/*'; - - public function __construct(FieldTypeService $fieldTypeService, MaxUploadSize $maxUploadSize) - { - $this->maxUploadSize = $maxUploadSize; + public function __construct( + private MaxUploadSize $maxUploadSize + ) { } public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void diff --git a/src/lib/FieldType/Mapper/RelationFormMapper.php b/src/lib/FieldType/Mapper/RelationFormMapper.php index f54ec73d4e..cebd63d150 100644 --- a/src/lib/FieldType/Mapper/RelationFormMapper.php +++ b/src/lib/FieldType/Mapper/RelationFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -15,7 +16,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class RelationFormMapper extends AbstractRelationFormMapper +final class RelationFormMapper extends AbstractRelationFormMapper { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/RelationListFormMapper.php b/src/lib/FieldType/Mapper/RelationListFormMapper.php index e82b437be2..16f202e62b 100644 --- a/src/lib/FieldType/Mapper/RelationListFormMapper.php +++ b/src/lib/FieldType/Mapper/RelationListFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -16,7 +17,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class RelationListFormMapper extends AbstractRelationFormMapper +final class RelationListFormMapper extends AbstractRelationFormMapper { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/SelectionFormMapper.php b/src/lib/FieldType/Mapper/SelectionFormMapper.php index 6f0a5293d6..cb3edffb56 100644 --- a/src/lib/FieldType/Mapper/SelectionFormMapper.php +++ b/src/lib/FieldType/Mapper/SelectionFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -19,7 +20,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\OptionsResolver\OptionsResolver; -class SelectionFormMapper implements FieldDefinitionFormMapperInterface +final readonly class SelectionFormMapper implements FieldDefinitionFormMapperInterface { /** * Selection items can be added and removed, the collection field type is used for this. @@ -38,7 +39,7 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field $isTranslation = $data->contentTypeData->languageCode !== $data->contentTypeData->mainLanguageCode; $options = $fieldDefinitionForm->getConfig()->getOptions(); $languageCode = $options['languageCode']; - $isMultilingual = isset($data->fieldDefinition->fieldSettings['multilingualOptions']); + $isMultilingual = isset($data->fieldDefinition->getFieldSettings()['multilingualOptions']); $dataPropertyPathName = $isMultilingual ? 'multilingualOptions' : 'options'; $fieldDefinitionForm diff --git a/src/lib/FieldType/Mapper/TextBlockFormMapper.php b/src/lib/FieldType/Mapper/TextBlockFormMapper.php index 01df890dea..7664150f55 100644 --- a/src/lib/FieldType/Mapper/TextBlockFormMapper.php +++ b/src/lib/FieldType/Mapper/TextBlockFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -17,7 +18,7 @@ /** * FormMapper for ibexa_text FieldType. */ -class TextBlockFormMapper implements FieldDefinitionFormMapperInterface +final readonly class TextBlockFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/TextLineFormMapper.php b/src/lib/FieldType/Mapper/TextLineFormMapper.php index 657e7ed734..2240016665 100644 --- a/src/lib/FieldType/Mapper/TextLineFormMapper.php +++ b/src/lib/FieldType/Mapper/TextLineFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -18,7 +19,7 @@ /** * FormMapper for ibexa_string FieldType. */ -class TextLineFormMapper implements FieldDefinitionFormMapperInterface +final readonly class TextLineFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/TimeFormMapper.php b/src/lib/FieldType/Mapper/TimeFormMapper.php index 935005d7f0..4a089f3911 100644 --- a/src/lib/FieldType/Mapper/TimeFormMapper.php +++ b/src/lib/FieldType/Mapper/TimeFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -19,7 +20,7 @@ /** * FormMapper for ibexa_time FieldType. */ -class TimeFormMapper implements FieldDefinitionFormMapperInterface +final readonly class TimeFormMapper implements FieldDefinitionFormMapperInterface { public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void { diff --git a/src/lib/FieldType/Mapper/UserAccountFormMapper.php b/src/lib/FieldType/Mapper/UserAccountFormMapper.php index b82c656da7..a3fe51fbe2 100644 --- a/src/lib/FieldType/Mapper/UserAccountFormMapper.php +++ b/src/lib/FieldType/Mapper/UserAccountFormMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\FieldType\Mapper; @@ -23,7 +24,7 @@ /** * Maps a user FieldType. */ -final class UserAccountFormMapper implements FieldDefinitionFormMapperInterface, TranslationContainerInterface +final readonly class UserAccountFormMapper implements FieldDefinitionFormMapperInterface, TranslationContainerInterface { /** * {@inheritdoc} @@ -110,8 +111,6 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field /** * Fake method to set the translation domain for the extractor. * - * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver - * * @throws \Symfony\Component\OptionsResolver\Exception\AccessException */ public function configureOptions(OptionsResolver $resolver): void diff --git a/src/lib/Limitation/Mapper/ContentTypeLimitationMapper.php b/src/lib/Limitation/Mapper/ContentTypeLimitationMapper.php index 722e7c4d0f..4f98024aa4 100644 --- a/src/lib/Limitation/Mapper/ContentTypeLimitationMapper.php +++ b/src/lib/Limitation/Mapper/ContentTypeLimitationMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Limitation\Mapper; @@ -37,7 +38,9 @@ protected function getSelectionChoices(): array $contentTypeChoices = []; foreach ($this->contentTypeService->loadContentTypeGroups() as $group) { foreach ($this->contentTypeService->loadContentTypes($group) as $contentType) { - $contentTypeChoices[$contentType->id] = $contentType->getName($contentType->mainLanguageCode); + $contentTypeChoices[$contentType->id] = $contentType->getName( + $contentType->mainLanguageCode + ); } } @@ -52,9 +55,11 @@ public function mapLimitationValue(Limitation $limitation): array $values = []; foreach ($limitation->limitationValues as $contentTypeId) { try { - $values[] = $this->contentTypeService->loadContentType($contentTypeId); - } catch (NotFoundException $e) { - $this->logger->error(sprintf('Could not map the Limitation value: could not find a content type with ID %s', $contentTypeId)); + $values[] = $this->contentTypeService->loadContentType((int)$contentTypeId); + } catch (NotFoundException) { + $this->logger?->error( + sprintf('Could not map the Limitation value: could not find a content type with ID %s', $contentTypeId) + ); } } diff --git a/src/lib/Limitation/Mapper/LanguageLimitationMapper.php b/src/lib/Limitation/Mapper/LanguageLimitationMapper.php index 48ee86d422..aee885e4a1 100644 --- a/src/lib/Limitation/Mapper/LanguageLimitationMapper.php +++ b/src/lib/Limitation/Mapper/LanguageLimitationMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Limitation\Mapper; @@ -17,15 +18,12 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -class LanguageLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface +final class LanguageLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface { use LoggerAwareTrait; - private LanguageService $languageService; - - public function __construct(LanguageService $languageService) + public function __construct(private readonly LanguageService $languageService) { - $this->languageService = $languageService; $this->logger = new NullLogger(); } @@ -36,7 +34,7 @@ protected function getSelectionChoices(): array { $choices = []; foreach ($this->languageService->loadLanguages() as $language) { - $choices[$language->languageCode] = $language->name; + $choices[$language->getLanguageCode()] = $language->getName(); } return $choices; @@ -52,8 +50,10 @@ public function mapLimitationValue(Limitation $limitation): array foreach ($limitation->limitationValues as $languageCode) { try { $values[] = $this->languageService->loadLanguage($languageCode); - } catch (NotFoundException $e) { - $this->logger->error(sprintf('Could not map the Limitation value: could not find a language with code %s', $languageCode)); + } catch (NotFoundException) { + $this->logger?->error( + sprintf('Could not map the Limitation value: could not find a language with code %s', $languageCode) + ); } } diff --git a/src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php b/src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php index 7c3444158e..438cbe3504 100644 --- a/src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php +++ b/src/lib/Limitation/Mapper/ObjectStateLimitationMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Limitation\Mapper; @@ -18,15 +19,12 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -class ObjectStateLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface +final class ObjectStateLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface { use LoggerAwareTrait; - private ObjectStateService $objectStateService; - - public function __construct(ObjectStateService $objectStateService) + public function __construct(private readonly ObjectStateService $objectStateService) { - $this->objectStateService = $objectStateService; $this->logger = new NullLogger(); } @@ -55,10 +53,12 @@ public function mapLimitationValue(Limitation $limitation): array foreach ($limitation->limitationValues as $stateId) { try { $values[] = $this->getObjectStateLabel( - $this->objectStateService->loadObjectState($stateId) + $this->objectStateService->loadObjectState((int)$stateId) + ); + } catch (NotFoundException) { + $this->logger?->error( + sprintf('Could not map the Limitation value: could not find an Object state with ID %s', $stateId) ); - } catch (NotFoundException $e) { - $this->logger->error(sprintf('Could not map the Limitation value: could not find an Object state with ID %s', $stateId)); } } diff --git a/src/lib/Limitation/Mapper/SectionLimitationMapper.php b/src/lib/Limitation/Mapper/SectionLimitationMapper.php index 13abce7fec..2e1023d3dc 100644 --- a/src/lib/Limitation/Mapper/SectionLimitationMapper.php +++ b/src/lib/Limitation/Mapper/SectionLimitationMapper.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ +declare(strict_types=1); namespace Ibexa\AdminUi\Limitation\Mapper; @@ -17,15 +18,12 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; -class SectionLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface +final class SectionLimitationMapper extends MultipleSelectionBasedMapper implements LimitationValueMapperInterface, TranslationContainerInterface { use LoggerAwareTrait; - private SectionService $sectionService; - - public function __construct(SectionService $sectionService) + public function __construct(private readonly SectionService $sectionService) { - $this->sectionService = $sectionService; $this->logger = new NullLogger(); } @@ -36,7 +34,7 @@ protected function getSelectionChoices(): array { $choices = []; foreach ($this->sectionService->loadSections() as $section) { - $choices[$section->id] = $section->name; + $choices[$section->getId()] = $section->getName(); } return $choices; @@ -50,9 +48,11 @@ public function mapLimitationValue(Limitation $limitation): array $values = []; foreach ($limitation->limitationValues as $sectionId) { try { - $values[] = $this->sectionService->loadSection($sectionId); - } catch (NotFoundException $e) { - $this->logger->error(sprintf('Could not map the Limitation value: could not find a Section with ID %s', $sectionId)); + $values[] = $this->sectionService->loadSection((int)$sectionId); + } catch (NotFoundException) { + $this->logger?->error( + sprintf('Could not map the Limitation value: could not find a Section with ID %s', $sectionId) + ); } } diff --git a/src/lib/Translation/Extractor/JavaScriptFileVisitor.php b/src/lib/Translation/Extractor/JavaScriptFileVisitor.php index c2c5211806..af61382503 100644 --- a/src/lib/Translation/Extractor/JavaScriptFileVisitor.php +++ b/src/lib/Translation/Extractor/JavaScriptFileVisitor.php @@ -73,7 +73,7 @@ public function visitFile(SplFileInfo $file, MessageCatalogue $catalogue): void $ast = $parser->parse(); } catch (Exception $e) { - $this->logger->error(sprintf( + $this->logger?->error(sprintf( 'Unable to parse file %s: %s in line %d column %d', $file->getRealPath(), $e->getMessage(), @@ -158,7 +158,7 @@ private function extractId(SplFileInfo $file, array $arguments): ?string if (!($idNode instanceof Node\StringLiteral)) { $position = $idNode->getLocation()->getStart(); - $this->logger->error(sprintf( + $this->logger?->error(sprintf( 'Could not extract id, expected string literal but got %s (in %s on line %d column %d).', $idNode->getType(), $file->getRealPath(), @@ -194,7 +194,7 @@ private function extractDomain(SplFileInfo $file, array $arguments, string $meth if (!($domainNode instanceof Node\StringLiteral)) { $position = $domainNode->getLocation()->getStart(); - $this->logger->error(sprintf( + $this->logger?->error(sprintf( 'Could not extract domain, expected string literal but got %s (in %s on line %d column %d).', $domainNode->getType(), $file->getRealPath(), @@ -230,15 +230,8 @@ private function extractDesc(array $arguments): ?string return null; } - /** - * Returns true if file is supported by extractor. - * - * @param \SplFileInfo $file - * - * @return bool - */ private function supports(SplFileInfo $file): bool { - return '.js' === substr($file->getRealPath(), -3) && '.min.js' !== substr($file->getRealPath(), -7); + return str_ends_with($file->getRealPath(), '.js') && !str_ends_with($file->getRealPath(), '.min.js'); } } diff --git a/tests/lib/EventListener/ContentProxyCreateDraftListenerTest.php b/tests/lib/EventListener/ContentProxyCreateDraftListenerTest.php index f693473bd2..60c4bcea0c 100644 --- a/tests/lib/EventListener/ContentProxyCreateDraftListenerTest.php +++ b/tests/lib/EventListener/ContentProxyCreateDraftListenerTest.php @@ -162,8 +162,7 @@ public function testTranslateContentAutosaveEnabled(): void ]); $content - ->method('__get') - ->with('contentInfo') + ->method('getContentInfo') ->willReturn($contentInfo); $contentService = $this->createMock(ContentService::class); @@ -255,6 +254,9 @@ public function testAutosaveDisabled(): void $eventDispatcher->dispatch($translateEvent, ContentProxyTranslateEvent::class); } + /** + * @param \Ibexa\Core\Repository\Values\ContentType\FieldDefinition[] $fieldDefs + */ private function getContentType(array $fieldDefs = []): ContentType { return new ContentType([ @@ -262,8 +264,10 @@ private function getContentType(array $fieldDefs = []): ContentType ]); } - private function getFieldDefinition(string $identifier = 'identifier', bool $isTranslatable = false): FieldDefinition - { + private function getFieldDefinition( + string $identifier = 'identifier', + bool $isTranslatable = false + ): FieldDefinition { return new FieldDefinition([ 'identifier' => $identifier, 'defaultValue' => $this->createMock(Value::class), diff --git a/tests/lib/EventListener/SetViewParametersListenerTest.php b/tests/lib/EventListener/SetViewParametersListenerTest.php index f812e3a8b7..d12866f5ea 100644 --- a/tests/lib/EventListener/SetViewParametersListenerTest.php +++ b/tests/lib/EventListener/SetViewParametersListenerTest.php @@ -115,7 +115,9 @@ public function testSetViewTemplateParameters(): void ->method('sudo') ->willReturn([$locationA]); - $this->viewParametersListener->setContentEditViewTemplateParameters(new PreContentViewEvent($contentView)); + $this->viewParametersListener->setContentEditViewTemplateParameters( + new PreContentViewEvent($contentView) + ); self::assertSame($locations, $contentView->getParameter('parent_locations')); } @@ -157,7 +159,9 @@ public function testSetViewTemplateParametersWithMainLocationId(): void ->method('sudo') ->willReturn($parentLocation); - $this->viewParametersListener->setContentEditViewTemplateParameters(new PreContentViewEvent($contentView)); + $this->viewParametersListener->setContentEditViewTemplateParameters( + new PreContentViewEvent($contentView) + ); self::assertSame([], $contentView->getParameter('parent_locations')); self::assertSame(reset($parentLocations), $contentView->getParameter('parent_location')); @@ -190,7 +194,6 @@ public function testSetUserUpdateViewTemplateParametersWithoutUserUpdateViewInst public function testSetUserUpdateViewTemplateParameters(): void { $ownerId = 42; - $user = $this->generateUser($ownerId); $userUpdateView = new UserUpdateView(); @@ -203,7 +206,9 @@ public function testSetUserUpdateViewTemplateParameters(): void ->with($ownerId) ->willReturn($user); - $this->viewParametersListener->setUserUpdateViewTemplateParameters(new PreContentViewEvent($userUpdateView)); + $this->viewParametersListener->setUserUpdateViewTemplateParameters( + new PreContentViewEvent($userUpdateView) + ); self::assertSame($user, $userUpdateView->getParameter('creator')); } @@ -297,49 +302,34 @@ public function testSubscribedEvents(): void } } - /** - * @param int $mainLocationId - * @param bool $published - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo - */ private function generateContentInfo(?int $mainLocationId = null, bool $published = false): API\ContentInfo { return new API\ContentInfo([ 'mainLocationId' => $mainLocationId, 'ownerId' => self::EXAMPLE_OWNER_ID, 'published' => $published, + 'owner' => $this->generateUser(self::EXAMPLE_OWNER_ID), + 'id' => self::EXAMPLE_OWNER_ID, + 'status' => $published ? API\ContentInfo::STATUS_PUBLISHED : API\ContentInfo::STATUS_DRAFT, ]); } - /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo $contentInfo - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo - */ private function generateVersionInfo(API\ContentInfo $contentInfo): API\VersionInfo { return new VersionInfo(['contentInfo' => $contentInfo]); } - /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Content - */ private function generateContent(API\VersionInfo|VersionInfo $versionInfo): API\Content { return new Core\Content(['versionInfo' => $versionInfo]); } - /** - * @param int $ownerId - * - * @return \Ibexa\Contracts\Core\Repository\Values\User\User - */ private function generateUser(int $ownerId): APIUser { - $contentInfo = new API\ContentInfo(['ownerId' => $ownerId]); + $contentInfo = new API\ContentInfo([ + 'ownerId' => $ownerId, + 'id' => $ownerId, + ]); $versionInfo = new VersionInfo(['contentInfo' => $contentInfo]); @@ -348,10 +338,7 @@ private function generateUser(int $ownerId): APIUser return new CoreUser(['content' => $content]); } - /** - * @return \Ibexa\Contracts\Core\Repository\Values\Content\Field|\PHPUnit\Framework\MockObject\MockObject - */ - private function createFieldMock(string $identifier, string $type, string $fieldGroup = 'content'): MockObject + private function createFieldMock(string $identifier, string $type, string $fieldGroup = 'content'): MockObject|Field { $data = new FieldData([ 'field' => new Field([ diff --git a/tests/lib/Limitation/Mapper/SectionLimitationMapperTest.php b/tests/lib/Limitation/Mapper/SectionLimitationMapperTest.php index 3838151517..30077ca877 100644 --- a/tests/lib/Limitation/Mapper/SectionLimitationMapperTest.php +++ b/tests/lib/Limitation/Mapper/SectionLimitationMapperTest.php @@ -37,7 +37,7 @@ protected function setUp(): void public function testMapLimitationValue(): void { - $values = ['3', '5', '7']; + $values = [3, 5, 7]; $expected = []; foreach ($values as $i => $value) {