diff --git a/lib/Models/src/Core/Handlers/AbstractHandler.php b/lib/Models/src/Core/Handlers/AbstractHandler.php index fa5a7084..d7e1fbbe 100644 --- a/lib/Models/src/Core/Handlers/AbstractHandler.php +++ b/lib/Models/src/Core/Handlers/AbstractHandler.php @@ -8,8 +8,6 @@ abstract class AbstractHandler { - protected ObjectManager $objectManager; - /** * @return ObjectManager */ @@ -18,22 +16,9 @@ public function getObjectManager(): ObjectManager return $this->objectManager; } - /** - * @param ObjectManager $objectManager - * @return static - */ - public function setObjectManager(ObjectManager $objectManager) - { - $this->objectManager = $objectManager; - return $this; - } - - /** - * @param ObjectManager $objectManager - */ - public function __construct(ObjectManager $objectManager) - { - $this->objectManager = $objectManager; + public function __construct( + protected readonly ObjectManager $objectManager + ) { } /** diff --git a/lib/Models/src/Core/Handlers/HandlerFactoryInterface.php b/lib/Models/src/Core/Handlers/HandlerFactoryInterface.php index 2b0e53b6..0f9745b2 100644 --- a/lib/Models/src/Core/Handlers/HandlerFactoryInterface.php +++ b/lib/Models/src/Core/Handlers/HandlerFactoryInterface.php @@ -8,9 +8,5 @@ interface HandlerFactoryInterface { - /** - * @param AbstractEntity $entity - * @return AbstractHandler - */ public function getHandler(AbstractEntity $entity): AbstractHandler; } diff --git a/lib/RoadizCoreBundle/src/Bag/NodeTypes.php b/lib/RoadizCoreBundle/src/Bag/NodeTypes.php index 44147c4a..177f0fa4 100644 --- a/lib/RoadizCoreBundle/src/Bag/NodeTypes.php +++ b/lib/RoadizCoreBundle/src/Bag/NodeTypes.php @@ -4,34 +4,20 @@ namespace RZ\Roadiz\CoreBundle\Bag; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\Bag\LazyParameterBag; use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface; use RZ\Roadiz\CoreBundle\Entity\NodeType; use RZ\Roadiz\CoreBundle\Repository\NodeTypeRepository; -class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface +final class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface { - private ?NodeTypeRepository $repository = null; - private ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) + public function __construct(private readonly NodeTypeRepository $repository) { parent::__construct(); - $this->managerRegistry = $managerRegistry; } - /** - * @return NodeTypeRepository - */ public function getRepository(): NodeTypeRepository { - if (null === $this->repository) { - $this->repository = $this->managerRegistry->getRepository(NodeType::class); - } return $this->repository; } diff --git a/lib/RoadizCoreBundle/src/Bag/Roles.php b/lib/RoadizCoreBundle/src/Bag/Roles.php index 4d13624c..fc433556 100644 --- a/lib/RoadizCoreBundle/src/Bag/Roles.php +++ b/lib/RoadizCoreBundle/src/Bag/Roles.php @@ -9,28 +9,17 @@ use RZ\Roadiz\CoreBundle\Entity\Role; use RZ\Roadiz\CoreBundle\Repository\RoleRepository; -class Roles extends LazyParameterBag +final class Roles extends LazyParameterBag { - private ManagerRegistry $managerRegistry; - private ?RoleRepository $repository = null; - - /** - * @param ManagerRegistry $managerRegistry; - */ - public function __construct(ManagerRegistry $managerRegistry) - { + public function __construct( + private readonly RoleRepository $repository, + private readonly ManagerRegistry $managerRegistry + ) { parent::__construct(); - $this->managerRegistry = $managerRegistry; } - /** - * @return RoleRepository - */ public function getRepository(): RoleRepository { - if (null === $this->repository) { - $this->repository = $this->managerRegistry->getRepository(Role::class); - } return $this->repository; } @@ -57,14 +46,15 @@ protected function populateParameters(): void * * @return Role */ - public function get($key, $default = null): Role + public function get(string $key, $default = null): Role { $role = parent::get($key, $default); if (null === $role) { $role = new Role($key); - $this->managerRegistry->getManagerForClass(Role::class)->persist($role); - $this->managerRegistry->getManagerForClass(Role::class)->flush(); + $roleManager = $this->managerRegistry->getManagerForClass(Role::class); + $roleManager->persist($role); + $roleManager->flush(); } return $role; diff --git a/lib/RoadizCoreBundle/src/Bag/Settings.php b/lib/RoadizCoreBundle/src/Bag/Settings.php index 4e8a3d4c..8256c9c6 100644 --- a/lib/RoadizCoreBundle/src/Bag/Settings.php +++ b/lib/RoadizCoreBundle/src/Bag/Settings.php @@ -4,34 +4,25 @@ namespace RZ\Roadiz\CoreBundle\Bag; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\Bag\LazyParameterBag; use RZ\Roadiz\CoreBundle\Entity\Document; use RZ\Roadiz\CoreBundle\Entity\Setting; +use RZ\Roadiz\CoreBundle\Repository\DocumentRepository; use RZ\Roadiz\CoreBundle\Repository\SettingRepository; use Symfony\Component\Stopwatch\Stopwatch; -class Settings extends LazyParameterBag +final class Settings extends LazyParameterBag { - private ManagerRegistry $managerRegistry; - private ?SettingRepository $repository = null; - private Stopwatch $stopwatch; - - public function __construct(ManagerRegistry $managerRegistry, Stopwatch $stopwatch) - { + public function __construct( + private readonly SettingRepository $repository, + private readonly DocumentRepository $documentRepository, + private readonly Stopwatch $stopwatch + ) { parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->stopwatch = $stopwatch; } - /** - * @return SettingRepository - */ public function getRepository(): SettingRepository { - if (null === $this->repository) { - $this->repository = $this->managerRegistry->getRepository(Setting::class); - } return $this->repository; } @@ -72,9 +63,7 @@ public function getDocument(string $key): ?Document { try { $id = $this->getInt($key); - return $this->managerRegistry - ->getRepository(Document::class) - ->findOneById($id); + return $this->documentRepository->findOneById($id); } catch (\Exception $e) { return null; } diff --git a/lib/RoadizCoreBundle/src/Cache/Clearer/FileClearer.php b/lib/RoadizCoreBundle/src/Cache/Clearer/FileClearer.php index 0cb90568..955e348f 100644 --- a/lib/RoadizCoreBundle/src/Cache/Clearer/FileClearer.php +++ b/lib/RoadizCoreBundle/src/Cache/Clearer/FileClearer.php @@ -7,11 +7,9 @@ abstract class FileClearer implements ClearerInterface { protected ?string $output = null; - protected string $cacheDir; - public function __construct(string $cacheDir) + public function __construct(protected readonly string $cacheDir) { - $this->cacheDir = $cacheDir; } public function clear(): bool diff --git a/lib/RoadizCoreBundle/src/Cache/Clearer/NodesSourcesUrlsCacheClearer.php b/lib/RoadizCoreBundle/src/Cache/Clearer/NodesSourcesUrlsCacheClearer.php index f59f919b..a7018fe0 100644 --- a/lib/RoadizCoreBundle/src/Cache/Clearer/NodesSourcesUrlsCacheClearer.php +++ b/lib/RoadizCoreBundle/src/Cache/Clearer/NodesSourcesUrlsCacheClearer.php @@ -8,12 +8,9 @@ final class NodesSourcesUrlsCacheClearer extends FileClearer { - private CacheItemPoolInterface $cacheProvider; - - public function __construct(CacheItemPoolInterface $cacheProvider) + public function __construct(private readonly CacheItemPoolInterface $cacheProvider) { parent::__construct(''); - $this->cacheProvider = $cacheProvider; } public function clear(): bool diff --git a/lib/RoadizCoreBundle/src/Cache/CloudflareProxyCache.php b/lib/RoadizCoreBundle/src/Cache/CloudflareProxyCache.php index 15e63174..93485e54 100644 --- a/lib/RoadizCoreBundle/src/Cache/CloudflareProxyCache.php +++ b/lib/RoadizCoreBundle/src/Cache/CloudflareProxyCache.php @@ -6,32 +6,15 @@ final class CloudflareProxyCache { - protected string $name; - protected string $zone; - protected string $version; - protected string $bearer; - protected string $email; - protected string $key; - protected int $timeout; - - /** - * @param string $name - * @param string $zone - * @param string $version - * @param string $bearer - * @param string $email - * @param string $key - * @param int $timeout - */ - public function __construct(string $name, string $zone, string $version, string $bearer, string $email, string $key, int $timeout) - { - $this->name = $name; - $this->zone = $zone; - $this->version = $version; - $this->bearer = $bearer; - $this->email = $email; - $this->key = $key; - $this->timeout = $timeout; + public function __construct( + private readonly string $name, + private readonly string $zone, + private readonly string $version, + private readonly string $bearer, + private readonly string $email, + private readonly string $key, + private readonly int $timeout + ) { } /** diff --git a/lib/RoadizCoreBundle/src/Cache/ReverseProxyCache.php b/lib/RoadizCoreBundle/src/Cache/ReverseProxyCache.php index 80900a63..8aa36611 100644 --- a/lib/RoadizCoreBundle/src/Cache/ReverseProxyCache.php +++ b/lib/RoadizCoreBundle/src/Cache/ReverseProxyCache.php @@ -6,23 +6,12 @@ final class ReverseProxyCache { - protected string $name; - protected string $host; - protected string $domainName; - protected int $timeout; - - /** - * @param string $name - * @param string $host - * @param string $domainName - * @param int $timeout - */ - public function __construct(string $name, string $host, string $domainName, int $timeout) - { - $this->name = $name; - $this->host = $host; - $this->domainName = $domainName; - $this->timeout = $timeout; + public function __construct( + private readonly string $name, + private readonly string $host, + private readonly string $domainName, + private readonly int $timeout + ) { } /** @@ -48,4 +37,9 @@ public function getDomainName(): string { return $this->domainName; } + + public function getTimeout(): int + { + return $this->timeout; + } } diff --git a/lib/RoadizCoreBundle/src/Cache/ReverseProxyCacheLocator.php b/lib/RoadizCoreBundle/src/Cache/ReverseProxyCacheLocator.php index b6a4a3f6..b3f4b963 100644 --- a/lib/RoadizCoreBundle/src/Cache/ReverseProxyCacheLocator.php +++ b/lib/RoadizCoreBundle/src/Cache/ReverseProxyCacheLocator.php @@ -6,20 +6,14 @@ final class ReverseProxyCacheLocator { - /** - * @var ReverseProxyCache[] - */ - private array $frontends; - private ?CloudflareProxyCache $cloudflareProxyCache; - /** * @param ReverseProxyCache[] $frontends * @param CloudflareProxyCache|null $cloudflareProxyCache */ - public function __construct(array $frontends, ?CloudflareProxyCache $cloudflareProxyCache = null) - { - $this->frontends = $frontends; - $this->cloudflareProxyCache = $cloudflareProxyCache; + public function __construct( + private readonly array $frontends, + private readonly ?CloudflareProxyCache $cloudflareProxyCache = null + ) { } /** diff --git a/lib/RoadizCoreBundle/src/Console/AppInstallCommand.php b/lib/RoadizCoreBundle/src/Console/AppInstallCommand.php index 9ce43d3c..e1023ba7 100644 --- a/lib/RoadizCoreBundle/src/Console/AppInstallCommand.php +++ b/lib/RoadizCoreBundle/src/Console/AppInstallCommand.php @@ -21,42 +21,23 @@ use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\Yaml\Yaml; -/** - * Command line utils for managing themes from terminal. - */ final class AppInstallCommand extends Command { - protected SymfonyStyle $io; + private SymfonyStyle $io; private bool $dryRun = false; - protected string $projectDir; - protected NodeTypesImporter $nodeTypesImporter; - protected TagsImporter $tagsImporter; - protected SettingsImporter $settingsImporter; - protected RolesImporter $rolesImporter; - protected GroupsImporter $groupsImporter; - protected AttributeImporter $attributeImporter; - protected ManagerRegistry $managerRegistry; public function __construct( - string $projectDir, - ManagerRegistry $managerRegistry, - NodeTypesImporter $nodeTypesImporter, - TagsImporter $tagsImporter, - SettingsImporter $settingsImporter, - RolesImporter $rolesImporter, - GroupsImporter $groupsImporter, - AttributeImporter $attributeImporter, - string $name = null + private readonly string $projectDir, + private readonly ManagerRegistry $managerRegistry, + private readonly NodeTypesImporter $nodeTypesImporter, + private readonly TagsImporter $tagsImporter, + private readonly SettingsImporter $settingsImporter, + private readonly RolesImporter $rolesImporter, + private readonly GroupsImporter $groupsImporter, + private readonly AttributeImporter $attributeImporter, + ?string $name = null ) { parent::__construct($name); - $this->projectDir = $projectDir; - $this->nodeTypesImporter = $nodeTypesImporter; - $this->tagsImporter = $tagsImporter; - $this->settingsImporter = $settingsImporter; - $this->rolesImporter = $rolesImporter; - $this->groupsImporter = $groupsImporter; - $this->attributeImporter = $attributeImporter; - $this->managerRegistry = $managerRegistry; } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/AppMigrateCommand.php b/lib/RoadizCoreBundle/src/Console/AppMigrateCommand.php index 9aef6a7a..e8949486 100644 --- a/lib/RoadizCoreBundle/src/Console/AppMigrateCommand.php +++ b/lib/RoadizCoreBundle/src/Console/AppMigrateCommand.php @@ -6,7 +6,6 @@ use RZ\Roadiz\CoreBundle\Doctrine\SchemaUpdater; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -16,14 +15,12 @@ final class AppMigrateCommand extends Command { - protected string $projectDir; - private SchemaUpdater $schemaUpdater; - - public function __construct(SchemaUpdater $schemaUpdater, string $projectDir, ?string $name = null) - { + public function __construct( + private readonly SchemaUpdater $schemaUpdater, + private readonly string $projectDir, + ?string $name = null + ) { parent::__construct($name); - $this->projectDir = $projectDir; - $this->schemaUpdater = $schemaUpdater; } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/CustomFormAnswerPurgeCommand.php b/lib/RoadizCoreBundle/src/Console/CustomFormAnswerPurgeCommand.php index 5363c503..07270a01 100644 --- a/lib/RoadizCoreBundle/src/Console/CustomFormAnswerPurgeCommand.php +++ b/lib/RoadizCoreBundle/src/Console/CustomFormAnswerPurgeCommand.php @@ -19,20 +19,13 @@ final class CustomFormAnswerPurgeCommand extends Command { - private ManagerRegistry $managerRegistry; - private EventDispatcherInterface $eventDispatcher; - private LoggerInterface $logger; - public function __construct( - ManagerRegistry $managerRegistry, - EventDispatcherInterface $eventDispatcher, - LoggerInterface $logger, + private readonly ManagerRegistry $managerRegistry, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly LoggerInterface $logger, string $name = null ) { parent::__construct($name); - $this->managerRegistry = $managerRegistry; - $this->eventDispatcher = $eventDispatcher; - $this->logger = $logger; } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/DecodePrivateKeyCommand.php b/lib/RoadizCoreBundle/src/Console/DecodePrivateKeyCommand.php index e213f591..f86cc50d 100644 --- a/lib/RoadizCoreBundle/src/Console/DecodePrivateKeyCommand.php +++ b/lib/RoadizCoreBundle/src/Console/DecodePrivateKeyCommand.php @@ -4,7 +4,6 @@ namespace RZ\Roadiz\CoreBundle\Console; -use RZ\Crypto\KeyChain\KeyChainInterface; use RZ\Roadiz\CoreBundle\Crypto\UniqueKeyEncoderFactory; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -15,16 +14,13 @@ /** * @package RZ\Roadiz\CoreBundle\Console */ -class DecodePrivateKeyCommand extends Command +final class DecodePrivateKeyCommand extends Command { - protected KeyChainInterface $keyChain; - protected UniqueKeyEncoderFactory $uniqueKeyEncoderFactory; - - public function __construct(KeyChainInterface $keyChain, UniqueKeyEncoderFactory $uniqueKeyEncoderFactory) - { - parent::__construct(); - $this->keyChain = $keyChain; - $this->uniqueKeyEncoderFactory = $uniqueKeyEncoderFactory; + public function __construct( + private readonly UniqueKeyEncoderFactory $uniqueKeyEncoderFactory, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/EncodePrivateKeyCommand.php b/lib/RoadizCoreBundle/src/Console/EncodePrivateKeyCommand.php index 763b2ffa..24e49841 100644 --- a/lib/RoadizCoreBundle/src/Console/EncodePrivateKeyCommand.php +++ b/lib/RoadizCoreBundle/src/Console/EncodePrivateKeyCommand.php @@ -5,7 +5,6 @@ namespace RZ\Roadiz\CoreBundle\Console; use ParagonIE\HiddenString\HiddenString; -use RZ\Crypto\KeyChain\KeyChainInterface; use RZ\Roadiz\CoreBundle\Crypto\UniqueKeyEncoderFactory; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -16,16 +15,13 @@ /** * @package RZ\Roadiz\CoreBundle\Console */ -class EncodePrivateKeyCommand extends Command +final class EncodePrivateKeyCommand extends Command { - protected KeyChainInterface $keyChain; - protected UniqueKeyEncoderFactory $uniqueKeyEncoderFactory; - - public function __construct(KeyChainInterface $keyChain, UniqueKeyEncoderFactory $uniqueKeyEncoderFactory) - { - parent::__construct(); - $this->keyChain = $keyChain; - $this->uniqueKeyEncoderFactory = $uniqueKeyEncoderFactory; + public function __construct( + private readonly UniqueKeyEncoderFactory $uniqueKeyEncoderFactory, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/FilesCommandTrait.php b/lib/RoadizCoreBundle/src/Console/FilesCommandTrait.php index e215fe70..15d73514 100644 --- a/lib/RoadizCoreBundle/src/Console/FilesCommandTrait.php +++ b/lib/RoadizCoreBundle/src/Console/FilesCommandTrait.php @@ -9,7 +9,7 @@ trait FilesCommandTrait /** * @return string */ - protected function getPublicFolderName() + protected function getPublicFolderName(): string { return '/exported_public'; } @@ -17,7 +17,7 @@ protected function getPublicFolderName() /** * @return string */ - protected function getPrivateFolderName() + protected function getPrivateFolderName(): string { return '/exported_private'; } @@ -25,7 +25,7 @@ protected function getPrivateFolderName() /** * @return string */ - protected function getFontsFolderName() + protected function getFontsFolderName(): string { return '/exported_fonts'; } diff --git a/lib/RoadizCoreBundle/src/Console/FilesExportCommand.php b/lib/RoadizCoreBundle/src/Console/FilesExportCommand.php index 29fac777..adf93e2d 100644 --- a/lib/RoadizCoreBundle/src/Console/FilesExportCommand.php +++ b/lib/RoadizCoreBundle/src/Console/FilesExportCommand.php @@ -14,20 +14,17 @@ use Symfony\Component\String\Slugger\AsciiSlugger; use ZipArchive; -class FilesExportCommand extends Command +final class FilesExportCommand extends Command { use FilesCommandTrait; - protected FileAwareInterface $fileAware; - protected string $exportDir; - protected string $appNamespace; - - public function __construct(FileAwareInterface $fileAware, string $exportDir, string $appNamespace) - { - parent::__construct(); - $this->fileAware = $fileAware; - $this->exportDir = $exportDir; - $this->appNamespace = $appNamespace; + public function __construct( + private readonly FileAwareInterface $fileAware, + private readonly string $exportDir, + private readonly string $appNamespace, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/FilesImportCommand.php b/lib/RoadizCoreBundle/src/Console/FilesImportCommand.php index 55c0b07f..4b910575 100644 --- a/lib/RoadizCoreBundle/src/Console/FilesImportCommand.php +++ b/lib/RoadizCoreBundle/src/Console/FilesImportCommand.php @@ -15,20 +15,16 @@ use Symfony\Component\String\Slugger\AsciiSlugger; use ZipArchive; -class FilesImportCommand extends Command +final class FilesImportCommand extends Command { use FilesCommandTrait; - protected FileAwareInterface $fileAware; - protected string $exportDir; - protected string $appNamespace; - - public function __construct(FileAwareInterface $fileAware, string $exportDir, string $appNamespace) - { - parent::__construct(); - $this->fileAware = $fileAware; - $this->exportDir = $exportDir; - $this->appNamespace = $appNamespace; + public function __construct( + private readonly FileAwareInterface $fileAware, + private readonly string $appNamespace, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/GenerateApiResourceCommand.php b/lib/RoadizCoreBundle/src/Console/GenerateApiResourceCommand.php index 7bfda603..87ae30e3 100644 --- a/lib/RoadizCoreBundle/src/Console/GenerateApiResourceCommand.php +++ b/lib/RoadizCoreBundle/src/Console/GenerateApiResourceCommand.php @@ -12,18 +12,14 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class GenerateApiResourceCommand extends Command +final class GenerateApiResourceCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected ApiResourceGenerator $apiResourceGenerator; - public function __construct( - ManagerRegistry $managerRegistry, - ApiResourceGenerator $apiResourceGenerator + private readonly ManagerRegistry $managerRegistry, + private readonly ApiResourceGenerator $apiResourceGenerator, + ?string $name = null ) { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->apiResourceGenerator = $apiResourceGenerator; + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/GenerateNodeSourceEntitiesCommand.php b/lib/RoadizCoreBundle/src/Console/GenerateNodeSourceEntitiesCommand.php index 1a630456..04c3b8dc 100644 --- a/lib/RoadizCoreBundle/src/Console/GenerateNodeSourceEntitiesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/GenerateNodeSourceEntitiesCommand.php @@ -5,6 +5,8 @@ namespace RZ\Roadiz\CoreBundle\Console; use Doctrine\Persistence\ManagerRegistry; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use RZ\Roadiz\CoreBundle\Entity\NodeType; use RZ\Roadiz\CoreBundle\EntityHandler\HandlerFactory; use RZ\Roadiz\CoreBundle\EntityHandler\NodeTypeHandler; @@ -13,23 +15,14 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing node-types from terminal. - */ -class GenerateNodeSourceEntitiesCommand extends Command +final class GenerateNodeSourceEntitiesCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected HandlerFactory $handlerFactory; - - /** - * @param ManagerRegistry $managerRegistry - * @param HandlerFactory $handlerFactory - */ - public function __construct(ManagerRegistry $managerRegistry, HandlerFactory $handlerFactory) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->handlerFactory = $handlerFactory; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly HandlerFactory $handlerFactory, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void @@ -38,6 +31,10 @@ protected function configure(): void ->setDescription('Generate node-sources entities PHP classes.'); } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + */ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); diff --git a/lib/RoadizCoreBundle/src/Console/GeneratePrivateKeyCommand.php b/lib/RoadizCoreBundle/src/Console/GeneratePrivateKeyCommand.php index 3f46c280..9b610e4a 100644 --- a/lib/RoadizCoreBundle/src/Console/GeneratePrivateKeyCommand.php +++ b/lib/RoadizCoreBundle/src/Console/GeneratePrivateKeyCommand.php @@ -10,23 +10,14 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * @package RZ\Roadiz\CoreBundle\Console - */ -class GeneratePrivateKeyCommand extends Command +final class GeneratePrivateKeyCommand extends Command { - protected KeyChainInterface $keyChain; - protected string $privateKeyName; - - /** - * @param KeyChainInterface $keyChain - * @param string $privateKeyName - */ - public function __construct(KeyChainInterface $keyChain, string $privateKeyName) - { - parent::__construct(); - $this->keyChain = $keyChain; - $this->privateKeyName = $privateKeyName; + public function __construct( + private readonly KeyChainInterface $keyChain, + private readonly string $privateKeyName, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/InstallCommand.php b/lib/RoadizCoreBundle/src/Console/InstallCommand.php index 79291b84..913de1ca 100644 --- a/lib/RoadizCoreBundle/src/Console/InstallCommand.php +++ b/lib/RoadizCoreBundle/src/Console/InstallCommand.php @@ -18,33 +18,16 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Yaml\Yaml; -/** - * Command line utils for installing RZ-CMS v3 from terminal. - */ -class InstallCommand extends Command +final class InstallCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected RolesImporter $rolesImporter; - protected GroupsImporter $groupsImporter; - protected SettingsImporter $settingsImporter; - - /** - * @param ManagerRegistry $managerRegistry - * @param RolesImporter $rolesImporter - * @param GroupsImporter $groupsImporter - * @param SettingsImporter $settingsImporter - */ public function __construct( - ManagerRegistry $managerRegistry, - RolesImporter $rolesImporter, - GroupsImporter $groupsImporter, - SettingsImporter $settingsImporter + private readonly ManagerRegistry $managerRegistry, + private readonly RolesImporter $rolesImporter, + private readonly GroupsImporter $groupsImporter, + private readonly SettingsImporter $settingsImporter, + ?string $name = null ) { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->rolesImporter = $rolesImporter; - $this->groupsImporter = $groupsImporter; - $this->settingsImporter = $settingsImporter; + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/LogsCleanupCommand.php b/lib/RoadizCoreBundle/src/Console/LogsCleanupCommand.php index d9b94f3c..56fd662a 100644 --- a/lib/RoadizCoreBundle/src/Console/LogsCleanupCommand.php +++ b/lib/RoadizCoreBundle/src/Console/LogsCleanupCommand.php @@ -15,17 +15,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class LogsCleanupCommand extends Command +final class LogsCleanupCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/MailerTestCommand.php b/lib/RoadizCoreBundle/src/Console/MailerTestCommand.php index f7c43949..83a66962 100644 --- a/lib/RoadizCoreBundle/src/Console/MailerTestCommand.php +++ b/lib/RoadizCoreBundle/src/Console/MailerTestCommand.php @@ -13,20 +13,15 @@ use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Mime\Address; -class MailerTestCommand extends Command +final class MailerTestCommand extends Command { - protected EmailManager $emailManager; - - /** - * @param EmailManager $emailManager - */ - public function __construct(EmailManager $emailManager) - { - parent::__construct(); - $this->emailManager = $emailManager; + public function __construct( + private readonly EmailManager $emailManager, + ?string $name = null + ) { + parent::__construct($name); } - protected function configure(): void { $this->setName('mailer:send:test') diff --git a/lib/RoadizCoreBundle/src/Console/NodeApplyUniversalFieldsCommand.php b/lib/RoadizCoreBundle/src/Console/NodeApplyUniversalFieldsCommand.php index a136ac45..942e2541 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeApplyUniversalFieldsCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeApplyUniversalFieldsCommand.php @@ -15,20 +15,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -class NodeApplyUniversalFieldsCommand extends Command +final class NodeApplyUniversalFieldsCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected UniversalDataDuplicator $universalDataDuplicator; - - /** - * @param ManagerRegistry $managerRegistry - * @param UniversalDataDuplicator $universalDataDuplicator - */ - public function __construct(ManagerRegistry $managerRegistry, UniversalDataDuplicator $universalDataDuplicator) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->universalDataDuplicator = $universalDataDuplicator; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly UniversalDataDuplicator $universalDataDuplicator, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodeClearTagCommand.php b/lib/RoadizCoreBundle/src/Console/NodeClearTagCommand.php index 7ba65879..e7e775f7 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeClearTagCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeClearTagCommand.php @@ -15,18 +15,13 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -class NodeClearTagCommand extends Command +final class NodeClearTagCommand extends Command { - protected SymfonyStyle $io; - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void @@ -48,7 +43,7 @@ protected function getNodeQueryBuilder(Tag $tag): QueryBuilder protected function execute(InputInterface $input, OutputInterface $output): int { $em = $this->managerRegistry->getManagerForClass(Node::class); - $this->io = new SymfonyStyle($input, $output); + $io = new SymfonyStyle($input, $output); $tagId = (int) $input->getArgument('tagId'); if ($tagId <= 0) { @@ -69,12 +64,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int ->getSingleScalarResult(); if ($count <= 0) { - $this->io->warning('No nodes were found linked with this tag.'); + $io->warning('No nodes were found linked with this tag.'); return 0; } if ( - $this->io->askQuestion(new ConfirmationQuestion( + $io->askQuestion(new ConfirmationQuestion( sprintf('Are you sure to delete permanently %d nodes?', $count), false )) @@ -84,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ->getQuery() ->getResult(); - $this->io->progressStart($count); + $io->progressStart($count); /** @var Node $node */ foreach ($results as $node) { $em->remove($node); @@ -92,10 +87,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $em->flush(); // Executes all updates. } ++$i; - $this->io->progressAdvance(); + $io->progressAdvance(); } $em->flush(); - $this->io->progressFinish(); + $io->progressFinish(); } return 0; diff --git a/lib/RoadizCoreBundle/src/Console/NodeTypesCommand.php b/lib/RoadizCoreBundle/src/Console/NodeTypesCommand.php index 23107664..262bcaa6 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeTypesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeTypesCommand.php @@ -13,20 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing node-types from terminal. - */ -class NodeTypesCommand extends Command +final class NodeTypesCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodeTypesCreationCommand.php b/lib/RoadizCoreBundle/src/Console/NodeTypesCreationCommand.php index 812e9d0d..25788fec 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeTypesCreationCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeTypesCreationCommand.php @@ -23,21 +23,13 @@ */ class NodeTypesCreationCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected HandlerFactory $handlerFactory; - protected SchemaUpdater $schemaUpdater; - - /** - * @param ManagerRegistry $managerRegistry - * @param HandlerFactory $handlerFactory - * @param SchemaUpdater $schemaUpdater - */ - public function __construct(ManagerRegistry $managerRegistry, HandlerFactory $handlerFactory, SchemaUpdater $schemaUpdater) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->handlerFactory = $handlerFactory; - $this->schemaUpdater = $schemaUpdater; + public function __construct( + protected readonly ManagerRegistry $managerRegistry, + protected readonly HandlerFactory $handlerFactory, + protected readonly SchemaUpdater $schemaUpdater, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodeTypesDefaultValuesCommand.php b/lib/RoadizCoreBundle/src/Console/NodeTypesDefaultValuesCommand.php index bf59585e..2c4c3ec7 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeTypesDefaultValuesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeTypesDefaultValuesCommand.php @@ -5,7 +5,6 @@ namespace RZ\Roadiz\CoreBundle\Console; use Doctrine\Persistence\ManagerRegistry; -use RZ\Roadiz\Core\AbstractEntities\AbstractEntity; use RZ\Roadiz\Core\AbstractEntities\AbstractField; use RZ\Roadiz\CoreBundle\Entity\NodeTypeField; use RZ\Roadiz\EntityGenerator\Field\DefaultValuesResolverInterface; @@ -15,16 +14,14 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class NodeTypesDefaultValuesCommand extends Command +final class NodeTypesDefaultValuesCommand extends Command { - private DefaultValuesResolverInterface $defaultValuesResolver; - private ManagerRegistry $managerRegistry; - - public function __construct(DefaultValuesResolverInterface $defaultValuesResolver, ManagerRegistry $managerRegistry, string $name = null) - { + public function __construct( + private readonly DefaultValuesResolverInterface $defaultValuesResolver, + private readonly ManagerRegistry $managerRegistry, + string $name = null + ) { parent::__construct($name); - $this->defaultValuesResolver = $defaultValuesResolver; - $this->managerRegistry = $managerRegistry; } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodeTypesDeleteCommand.php b/lib/RoadizCoreBundle/src/Console/NodeTypesDeleteCommand.php index e4bfb545..6e9d47c0 100644 --- a/lib/RoadizCoreBundle/src/Console/NodeTypesDeleteCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodeTypesDeleteCommand.php @@ -19,23 +19,15 @@ /** * Command line utils for managing node-types from terminal. */ -class NodeTypesDeleteCommand extends Command +final class NodeTypesDeleteCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected HandlerFactory $handlerFactory; - protected SchemaUpdater $schemaUpdater; - - /** - * @param ManagerRegistry $managerRegistry - * @param HandlerFactory $handlerFactory - * @param SchemaUpdater $schemaUpdater - */ - public function __construct(ManagerRegistry $managerRegistry, HandlerFactory $handlerFactory, SchemaUpdater $schemaUpdater) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->handlerFactory = $handlerFactory; - $this->schemaUpdater = $schemaUpdater; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly HandlerFactory $handlerFactory, + private readonly SchemaUpdater $schemaUpdater, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodesCleanNamesCommand.php b/lib/RoadizCoreBundle/src/Console/NodesCleanNamesCommand.php index bee548c7..394a55de 100644 --- a/lib/RoadizCoreBundle/src/Console/NodesCleanNamesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodesCleanNamesCommand.php @@ -15,21 +15,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * @package RZ\Roadiz\CoreBundle\Console - */ final class NodesCleanNamesCommand extends Command { - protected NodeNamePolicyInterface $nodeNamePolicy; - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly NodeNamePolicyInterface $nodeNamePolicy, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodesCommand.php b/lib/RoadizCoreBundle/src/Console/NodesCommand.php index 3442ea0c..cd5e56a0 100644 --- a/lib/RoadizCoreBundle/src/Console/NodesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodesCommand.php @@ -13,20 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing nodes from terminal. - */ -class NodesCommand extends Command +final class NodesCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodesCreationCommand.php b/lib/RoadizCoreBundle/src/Console/NodesCreationCommand.php deleted file mode 100644 index 98e3ce6b..00000000 --- a/lib/RoadizCoreBundle/src/Console/NodesCreationCommand.php +++ /dev/null @@ -1,133 +0,0 @@ -managerRegistry = $managerRegistry; - $this->nodeFactory = $nodeFactory; - } - - protected function configure(): void - { - $this->setName('nodes:create') - ->setDescription('Create a new node') - ->addArgument( - 'node-name', - InputArgument::REQUIRED, - 'Node name' - ) - ->addArgument( - 'node-type', - InputArgument::REQUIRED, - 'Node-type name' - ) - ->addArgument( - 'locale', - InputArgument::OPTIONAL, - 'Translation locale' - ); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $nodeName = $input->getArgument('node-name'); - $typeName = $input->getArgument('node-type'); - $locale = $input->getArgument('locale'); - $this->io = new SymfonyStyle($input, $output); - - $existingNode = $this->managerRegistry - ->getRepository(Node::class) - ->setDisplayingNotPublishedNodes(true) - ->findOneByNodeName($nodeName); - - if (null === $existingNode) { - $type = $this->managerRegistry - ->getRepository(NodeType::class) - ->findOneByName($typeName); - - if (null !== $type) { - $translation = null; - - if ($locale) { - $translation = $this->managerRegistry - ->getRepository(TranslationInterface::class) - ->findOneBy(['locale' => $locale]); - } - - if ($translation === null) { - $translation = $this->managerRegistry - ->getRepository(TranslationInterface::class) - ->findDefault(); - } - - $this->executeNodeCreation($input->getArgument('node-name'), $type, $translation); - } else { - $this->io->error('"' . $typeName . '" node type does not exist.'); - return 1; - } - return 0; - } else { - $this->io->error($existingNode->getNodeName() . ' node already exists.'); - return 1; - } - } - - /** - * @param string $nodeName - * @param NodeType $type - * @param TranslationInterface $translation - */ - private function executeNodeCreation( - string $nodeName, - NodeType $type, - TranslationInterface $translation - ): void { - $node = $this->nodeFactory->create($nodeName, $type, $translation); - $source = $node->getNodeSources()->first() ?: null; - if (null === $source) { - throw new \InvalidArgumentException('Node source is null'); - } - $fields = $type->getFields(); - - foreach ($fields as $field) { - if (!$field->isVirtual()) { - $question = new Question('[Field ' . $field->getLabel() . '] : ', null); - $fValue = $this->io->askQuestion($question); - $setterName = $field->getSetterName(); - $source->$setterName($fValue); - } - } - - $this->managerRegistry->getManagerForClass(Node::class)->flush(); - $this->io->success('Node “' . $nodeName . '” created at root level.'); - } -} diff --git a/lib/RoadizCoreBundle/src/Console/NodesDetailsCommand.php b/lib/RoadizCoreBundle/src/Console/NodesDetailsCommand.php index d5095807..444d3850 100644 --- a/lib/RoadizCoreBundle/src/Console/NodesDetailsCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodesDetailsCommand.php @@ -14,17 +14,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -class NodesDetailsCommand extends Command +final class NodesDetailsCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodesEmptyTrashCommand.php b/lib/RoadizCoreBundle/src/Console/NodesEmptyTrashCommand.php index d9078595..8e21028b 100644 --- a/lib/RoadizCoreBundle/src/Console/NodesEmptyTrashCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodesEmptyTrashCommand.php @@ -15,20 +15,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -class NodesEmptyTrashCommand extends Command +final class NodesEmptyTrashCommand extends Command { - protected ManagerRegistry $managerRegistry; - protected HandlerFactory $handlerFactory; - - /** - * @param ManagerRegistry $managerRegistry - * @param HandlerFactory $handlerFactory - */ - public function __construct(ManagerRegistry $managerRegistry, HandlerFactory $handlerFactory) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - $this->handlerFactory = $handlerFactory; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly HandlerFactory $handlerFactory, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/NodesOrphansCommand.php b/lib/RoadizCoreBundle/src/Console/NodesOrphansCommand.php index 60fcf003..e3a68598 100644 --- a/lib/RoadizCoreBundle/src/Console/NodesOrphansCommand.php +++ b/lib/RoadizCoreBundle/src/Console/NodesOrphansCommand.php @@ -13,20 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * @package RZ\Roadiz\CoreBundle\Console - */ -class NodesOrphansCommand extends Command +final class NodesOrphansCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/PrivateKeyCommand.php b/lib/RoadizCoreBundle/src/Console/PrivateKeyCommand.php index 9e368498..245887f4 100644 --- a/lib/RoadizCoreBundle/src/Console/PrivateKeyCommand.php +++ b/lib/RoadizCoreBundle/src/Console/PrivateKeyCommand.php @@ -11,17 +11,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * @package RZ\Roadiz\CoreBundle\Console - */ -class PrivateKeyCommand extends Command +final class PrivateKeyCommand extends Command { - protected KeyChainInterface $keyChain; - - public function __construct(KeyChainInterface $keyChain) - { - parent::__construct(); - $this->keyChain = $keyChain; + public function __construct( + private readonly KeyChainInterface $keyChain, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/SolrCommand.php b/lib/RoadizCoreBundle/src/Console/SolrCommand.php index 6e930a20..32396f2b 100644 --- a/lib/RoadizCoreBundle/src/Console/SolrCommand.php +++ b/lib/RoadizCoreBundle/src/Console/SolrCommand.php @@ -10,21 +10,15 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing nodes from terminal. - */ class SolrCommand extends Command { protected ?SymfonyStyle $io = null; - protected ClientRegistry $clientRegistry; - /** - * @param ClientRegistry $clientRegistry - */ - public function __construct(ClientRegistry $clientRegistry) - { - parent::__construct(); - $this->clientRegistry = $clientRegistry; + public function __construct( + protected readonly ClientRegistry $clientRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void @@ -57,7 +51,7 @@ protected function displayBasicConfig(): void if (null !== $this->io) { $this->io->error('No Solr search engine server has been configured…'); $this->io->note(<<indexerFactory = $indexerFactory; + public function __construct( + protected readonly IndexerFactoryInterface $indexerFactory, + ClientRegistry $clientRegistry, + ?string $name = null + ) { + parent::__construct($clientRegistry, $name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/SolrReindexCommand.php b/lib/RoadizCoreBundle/src/Console/SolrReindexCommand.php index eb582902..041a22fb 100644 --- a/lib/RoadizCoreBundle/src/Console/SolrReindexCommand.php +++ b/lib/RoadizCoreBundle/src/Console/SolrReindexCommand.php @@ -12,31 +12,20 @@ use RZ\Roadiz\CoreBundle\SearchEngine\Indexer\IndexerFactoryInterface; use RZ\Roadiz\CoreBundle\SearchEngine\SolariumDocumentTranslation; use RZ\Roadiz\CoreBundle\SearchEngine\SolariumNodeSource; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Stopwatch\Stopwatch; -/** - * Command line utils for managing nodes from terminal. - */ class SolrReindexCommand extends SolrCommand implements ThemeAwareCommandInterface { - protected ?QuestionHelper $questionHelper = null; - protected IndexerFactoryInterface $indexerFactory; - - /** - * @param ClientRegistry $clientRegistry - * @param IndexerFactoryInterface $indexerFactory - */ public function __construct( + protected readonly IndexerFactoryInterface $indexerFactory, ClientRegistry $clientRegistry, - IndexerFactoryInterface $indexerFactory + ?string $name = null ) { - parent::__construct($clientRegistry); - $this->indexerFactory = $indexerFactory; + parent::__construct($clientRegistry, $name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/SolrResetCommand.php b/lib/RoadizCoreBundle/src/Console/SolrResetCommand.php index 6cd34a0f..ac48d1f3 100644 --- a/lib/RoadizCoreBundle/src/Console/SolrResetCommand.php +++ b/lib/RoadizCoreBundle/src/Console/SolrResetCommand.php @@ -13,21 +13,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing nodes from terminal. - */ -class SolrResetCommand extends SolrCommand +final class SolrResetCommand extends SolrCommand { - protected IndexerFactoryInterface $indexerFactory; - - /** - * @param ClientRegistry $clientRegistry - * @param IndexerFactoryInterface $indexerFactory - */ - public function __construct(ClientRegistry $clientRegistry, IndexerFactoryInterface $indexerFactory) - { - parent::__construct($clientRegistry); - $this->indexerFactory = $indexerFactory; + public function __construct( + private readonly IndexerFactoryInterface $indexerFactory, + ClientRegistry $clientRegistry, + ?string $name = null + ) { + parent::__construct($clientRegistry, $name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/TranslationsCommand.php b/lib/RoadizCoreBundle/src/Console/TranslationsCommand.php index 58217357..e3781525 100644 --- a/lib/RoadizCoreBundle/src/Console/TranslationsCommand.php +++ b/lib/RoadizCoreBundle/src/Console/TranslationsCommand.php @@ -11,20 +11,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing translations from terminal. - */ class TranslationsCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + protected readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/TranslationsCreationCommand.php b/lib/RoadizCoreBundle/src/Console/TranslationsCreationCommand.php index a4ac9e5d..9d0f8b90 100644 --- a/lib/RoadizCoreBundle/src/Console/TranslationsCreationCommand.php +++ b/lib/RoadizCoreBundle/src/Console/TranslationsCreationCommand.php @@ -4,9 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Console; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\CoreBundle\Entity\Translation; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,19 +14,8 @@ /** * Command line utils for managing translations */ -class TranslationsCreationCommand extends Command +final class TranslationsCreationCommand extends TranslationsCommand { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - } - protected function configure(): void { $this->setName('translations:create') diff --git a/lib/RoadizCoreBundle/src/Console/TranslationsDeleteCommand.php b/lib/RoadizCoreBundle/src/Console/TranslationsDeleteCommand.php index eb3e5a9d..60f54562 100644 --- a/lib/RoadizCoreBundle/src/Console/TranslationsDeleteCommand.php +++ b/lib/RoadizCoreBundle/src/Console/TranslationsDeleteCommand.php @@ -4,9 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Console; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\CoreBundle\Entity\Translation; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,19 +14,8 @@ /** * Command line utils for managing translations. */ -class TranslationsDeleteCommand extends Command +final class TranslationsDeleteCommand extends TranslationsCommand { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - } - protected function configure(): void { $this->setName('translations:delete') diff --git a/lib/RoadizCoreBundle/src/Console/TranslationsDisableCommand.php b/lib/RoadizCoreBundle/src/Console/TranslationsDisableCommand.php index abf6317b..164b7422 100644 --- a/lib/RoadizCoreBundle/src/Console/TranslationsDisableCommand.php +++ b/lib/RoadizCoreBundle/src/Console/TranslationsDisableCommand.php @@ -4,9 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Console; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\CoreBundle\Entity\Translation; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,19 +14,8 @@ /** * Command line utils for managing translations. */ -class TranslationsDisableCommand extends Command +final class TranslationsDisableCommand extends TranslationsCommand { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - } - protected function configure(): void { $this->setName('translations:disable') diff --git a/lib/RoadizCoreBundle/src/Console/TranslationsEnableCommand.php b/lib/RoadizCoreBundle/src/Console/TranslationsEnableCommand.php index f7fe0530..f6656694 100644 --- a/lib/RoadizCoreBundle/src/Console/TranslationsEnableCommand.php +++ b/lib/RoadizCoreBundle/src/Console/TranslationsEnableCommand.php @@ -4,9 +4,7 @@ namespace RZ\Roadiz\CoreBundle\Console; -use Doctrine\Persistence\ManagerRegistry; use RZ\Roadiz\CoreBundle\Entity\Translation; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -16,19 +14,8 @@ /** * Command line utils for managing translations. */ -class TranslationsEnableCommand extends Command +final class TranslationsEnableCommand extends TranslationsCommand { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; - } - protected function configure(): void { $this->setName('translations:enable') diff --git a/lib/RoadizCoreBundle/src/Console/UsersCommand.php b/lib/RoadizCoreBundle/src/Console/UsersCommand.php index f61d19ef..2309ff8d 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersCommand.php @@ -14,17 +14,13 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ class UsersCommand extends Command { - protected ManagerRegistry $managerRegistry; - - public function __construct(ManagerRegistry $managerRegistry, string $name = null) - { + public function __construct( + protected readonly ManagerRegistry $managerRegistry, + string $name = null + ) { parent::__construct($name); - $this->managerRegistry = $managerRegistry; } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersCreationCommand.php b/lib/RoadizCoreBundle/src/Console/UsersCreationCommand.php index bb33ff51..2373093e 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersCreationCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersCreationCommand.php @@ -15,9 +15,6 @@ use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ final class UsersCreationCommand extends UsersCommand { protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersDeleteCommand.php b/lib/RoadizCoreBundle/src/Console/UsersDeleteCommand.php index 9e98959f..2e8c3062 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersDeleteCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersDeleteCommand.php @@ -11,9 +11,6 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ final class UsersDeleteCommand extends UsersCommand { protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersDisableCommand.php b/lib/RoadizCoreBundle/src/Console/UsersDisableCommand.php index 11cf7db2..97b0062a 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersDisableCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersDisableCommand.php @@ -11,9 +11,6 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ final class UsersDisableCommand extends UsersCommand { protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersEnableCommand.php b/lib/RoadizCoreBundle/src/Console/UsersEnableCommand.php index f277a779..b9092656 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersEnableCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersEnableCommand.php @@ -11,9 +11,6 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ final class UsersEnableCommand extends UsersCommand { protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersPasswordCommand.php b/lib/RoadizCoreBundle/src/Console/UsersPasswordCommand.php index ccab60ae..9d265e1f 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersPasswordCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersPasswordCommand.php @@ -13,21 +13,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Style\SymfonyStyle; -/** - * Command line utils for managing users from terminal. - */ final class UsersPasswordCommand extends UsersCommand { - private PasswordGenerator $passwordGenerator; - - /** - * @param ManagerRegistry $managerRegistry - * @param PasswordGenerator $passwordGenerator - */ - public function __construct(ManagerRegistry $managerRegistry, PasswordGenerator $passwordGenerator) - { - parent::__construct($managerRegistry); - $this->passwordGenerator = $passwordGenerator; + public function __construct( + private readonly PasswordGenerator $passwordGenerator, + ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($managerRegistry, $name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/UsersRolesCommand.php b/lib/RoadizCoreBundle/src/Console/UsersRolesCommand.php index 0c9fc369..047a2d5b 100644 --- a/lib/RoadizCoreBundle/src/Console/UsersRolesCommand.php +++ b/lib/RoadizCoreBundle/src/Console/UsersRolesCommand.php @@ -20,16 +20,12 @@ */ final class UsersRolesCommand extends UsersCommand { - private Roles $rolesBag; - - /** - * @param ManagerRegistry $managerRegistry - * @param Roles $rolesBag - */ - public function __construct(ManagerRegistry $managerRegistry, Roles $rolesBag) - { - parent::__construct($managerRegistry); - $this->rolesBag = $rolesBag; + public function __construct( + private readonly Roles $rolesBag, + ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($managerRegistry, $name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/Console/VersionsPurgeCommand.php b/lib/RoadizCoreBundle/src/Console/VersionsPurgeCommand.php index 0f83df79..8891e472 100644 --- a/lib/RoadizCoreBundle/src/Console/VersionsPurgeCommand.php +++ b/lib/RoadizCoreBundle/src/Console/VersionsPurgeCommand.php @@ -18,15 +18,11 @@ final class VersionsPurgeCommand extends Command { - protected ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - */ - public function __construct(ManagerRegistry $managerRegistry) - { - parent::__construct(); - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + ?string $name = null + ) { + parent::__construct($name); } protected function configure(): void diff --git a/lib/RoadizCoreBundle/src/EntityHandler/CustomFormFieldHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/CustomFormFieldHandler.php index 368bb8fd..90576601 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/CustomFormFieldHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/CustomFormFieldHandler.php @@ -11,14 +11,11 @@ /** * Handle operations with customForms fields entities. */ -class CustomFormFieldHandler extends AbstractHandler +final class CustomFormFieldHandler extends AbstractHandler { private ?CustomFormField $customFormField = null; private CustomFormHandler $customFormHandler; - /** - * @return CustomFormField - */ public function getCustomFormField(): ?CustomFormField { return $this->customFormField; @@ -27,15 +24,13 @@ public function getCustomFormField(): ?CustomFormField * @param CustomFormField $customFormField * @return $this */ - public function setCustomFormField(CustomFormField $customFormField) + public function setCustomFormField(CustomFormField $customFormField): self { $this->customFormField = $customFormField; return $this; } /** - * Create a new custom-form-field handler with custom-form-field to handle. - * * @param ObjectManager $objectManager * @param CustomFormHandler $customFormHandler */ diff --git a/lib/RoadizCoreBundle/src/EntityHandler/CustomFormHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/CustomFormHandler.php index d77dd59e..a2fbb925 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/CustomFormHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/CustomFormHandler.php @@ -11,7 +11,7 @@ /** * Handle operations with node-type entities. */ -class CustomFormHandler extends AbstractHandler +final class CustomFormHandler extends AbstractHandler { protected ?CustomForm $customForm = null; @@ -20,11 +20,7 @@ public function getCustomForm(): ?CustomForm return $this->customForm; } - /** - * @param CustomForm $customForm - * @return $this - */ - public function setCustomForm(CustomForm $customForm) + public function setCustomForm(CustomForm $customForm): self { $this->customForm = $customForm; return $this; diff --git a/lib/RoadizCoreBundle/src/EntityHandler/DocumentHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/DocumentHandler.php index 106ccf87..44e9d885 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/DocumentHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/DocumentHandler.php @@ -21,15 +21,13 @@ /** * Handle operations with documents entities. */ -class DocumentHandler extends AbstractHandler +final class DocumentHandler extends AbstractHandler { - protected ?DocumentInterface $document = null; - private FilesystemOperator $documentStorage; + private ?DocumentInterface $document = null; - public function __construct(ObjectManager $objectManager, FilesystemOperator $documentStorage) + public function __construct(ObjectManager $objectManager, private readonly FilesystemOperator $documentStorage) { parent::__construct($objectManager); - $this->documentStorage = $documentStorage; } /** @@ -95,9 +93,9 @@ public function getDocument(): ?DocumentInterface /** * @param DocumentInterface $document - * @return DocumentHandler + * @return $this */ - public function setDocument(DocumentInterface $document): DocumentHandler + public function setDocument(DocumentInterface $document): self { $this->document = $document; return $this; diff --git a/lib/RoadizCoreBundle/src/EntityHandler/FolderHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/FolderHandler.php index 2b01d6af..5cb16fdb 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/FolderHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/FolderHandler.php @@ -6,13 +6,12 @@ use Doctrine\Common\Collections\Criteria; use RZ\Roadiz\Core\Handlers\AbstractHandler; -use RZ\Roadiz\Core\AbstractEntities\LeafInterface; use RZ\Roadiz\CoreBundle\Entity\Folder; /** * Handle operations with folders entities. */ -class FolderHandler extends AbstractHandler +final class FolderHandler extends AbstractHandler { protected ?Folder $folder = null; @@ -28,7 +27,7 @@ public function getFolder(): Folder * @param Folder $folder * @return $this */ - public function setFolder(Folder $folder) + public function setFolder(Folder $folder): self { $this->folder = $folder; return $this; @@ -39,7 +38,7 @@ public function setFolder(Folder $folder) * * @return $this */ - private function removeChildren() + private function removeChildren(): self { /** @var Folder $folder */ foreach ($this->getFolder()->getChildren() as $folder) { @@ -57,7 +56,7 @@ private function removeChildren() * * @return $this */ - public function removeWithChildrenAndAssociations() + public function removeWithChildrenAndAssociations(): self { $this->removeChildren(); $this->objectManager->remove($this->getFolder()); @@ -69,49 +68,6 @@ public function removeWithChildrenAndAssociations() return $this; } - /** - * Return every folder’s parents. - * - * @deprecated Use directly Folder::getParents method. - * @return array - */ - public function getParents(): array - { - $parentsArray = []; - $parent = $this->getFolder(); - - do { - $parent = $parent->getParent(); - if ($parent !== null) { - $parentsArray[] = $parent; - } else { - break; - } - } while ($parent !== null); - - return array_reverse($parentsArray); - } - - /** - * Get folder full path using folder names. - * - * @deprecated Use directly Folder::getFullPath method. - * @return string - */ - public function getFullPath(): string - { - $parents = $this->getParents(); - $path = []; - - foreach ($parents as $parent) { - $path[] = $parent->getFolderName(); - } - - $path[] = $this->getFolder()->getFolderName(); - - return implode('/', $path); - } - /** * Clean position for current folder siblings. * diff --git a/lib/RoadizCoreBundle/src/EntityHandler/GroupHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/GroupHandler.php index b4cfe577..9fb78ea9 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/GroupHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/GroupHandler.php @@ -11,7 +11,7 @@ /** * Handle operations with Group entities. */ -class GroupHandler extends AbstractHandler +final class GroupHandler extends AbstractHandler { private ?Group $group = null; diff --git a/lib/RoadizCoreBundle/src/EntityHandler/HandlerFactory.php b/lib/RoadizCoreBundle/src/EntityHandler/HandlerFactory.php index 8975ba83..860b941e 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/HandlerFactory.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/HandlerFactory.php @@ -20,16 +20,10 @@ use RZ\Roadiz\CoreBundle\Entity\Tag; use RZ\Roadiz\CoreBundle\Entity\Translation; -class HandlerFactory implements HandlerFactoryInterface +final class HandlerFactory implements HandlerFactoryInterface { - private ContainerInterface $container; - - /** - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) + public function __construct(private readonly ContainerInterface $container) { - $this->container = $container; } /** diff --git a/lib/RoadizCoreBundle/src/EntityHandler/NodeHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/NodeHandler.php index 2336d661..4b1ca5aa 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/NodeHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/NodeHandler.php @@ -5,8 +5,9 @@ namespace RZ\Roadiz\CoreBundle\EntityHandler; use Doctrine\Common\Collections\Criteria; +use Doctrine\ORM\NonUniqueResultException; use Doctrine\Persistence\ObjectManager; -use RZ\Roadiz\Core\AbstractEntities\LeafInterface; +use RZ\Roadiz\Core\Handlers\AbstractHandler; use RZ\Roadiz\CoreBundle\Entity\CustomForm; use RZ\Roadiz\CoreBundle\Entity\Node; use RZ\Roadiz\CoreBundle\Entity\NodesCustomForms; @@ -14,42 +15,28 @@ use RZ\Roadiz\CoreBundle\Entity\NodesToNodes; use RZ\Roadiz\CoreBundle\Entity\NodeTypeField; use RZ\Roadiz\CoreBundle\Entity\Translation; -use RZ\Roadiz\CoreBundle\Repository\NodeRepository; use RZ\Roadiz\CoreBundle\Node\NodeDuplicator; use RZ\Roadiz\CoreBundle\Node\NodeNamePolicyInterface; +use RZ\Roadiz\CoreBundle\Repository\NodeRepository; use RZ\Roadiz\CoreBundle\Security\Authorization\Chroot\NodeChrootResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Workflow\Registry; -use Symfony\Component\Workflow\Workflow; -use RZ\Roadiz\Core\Handlers\AbstractHandler; use Symfony\Component\Workflow\WorkflowInterface; /** * Handle operations with nodes entities. */ -class NodeHandler extends AbstractHandler +final class NodeHandler extends AbstractHandler { - protected NodeChrootResolver $chrootResolver; - private Registry $registry; private ?Node $node = null; - private NodeNamePolicyInterface $nodeNamePolicy; - /** - * @param ObjectManager $objectManager - * @param Registry $registry - * @param NodeChrootResolver $chrootResolver - * @param NodeNamePolicyInterface $nodeNamePolicy - */ final public function __construct( ObjectManager $objectManager, - Registry $registry, - NodeChrootResolver $chrootResolver, - NodeNamePolicyInterface $nodeNamePolicy + private readonly Registry $registry, + private readonly NodeChrootResolver $chrootResolver, + private readonly NodeNamePolicyInterface $nodeNamePolicy ) { parent::__construct($objectManager); - $this->registry = $registry; - $this->chrootResolver = $chrootResolver; - $this->nodeNamePolicy = $nodeNamePolicy; } protected function createSelf(): self @@ -75,9 +62,9 @@ public function getNode(): Node /** * @param Node $node - * @return NodeHandler + * @return $this */ - public function setNode(Node $node) + public function setNode(Node $node): self { $this->node = $node; return $this; @@ -90,7 +77,7 @@ public function setNode(Node $node) * @param bool $flush * @return $this */ - public function cleanCustomFormsFromField(NodeTypeField $field, bool $flush = true) + public function cleanCustomFormsFromField(NodeTypeField $field, bool $flush = true): self { $nodesCustomForms = $this->objectManager ->getRepository(NodesCustomForms::class) @@ -121,7 +108,7 @@ public function addCustomFormForField( NodeTypeField $field, bool $flush = true, ?float $position = null - ) { + ): self { $ncf = new NodesCustomForms($this->getNode(), $customForm, $field); if (null === $position) { @@ -165,7 +152,7 @@ public function getCustomFormsFromFieldName(string $fieldName): array * @param bool $flush * @return $this */ - public function cleanNodesFromField(NodeTypeField $field, bool $flush = true) + public function cleanNodesFromField(NodeTypeField $field, bool $flush = true): self { $this->node->clearBNodesForField($field); @@ -185,7 +172,7 @@ public function cleanNodesFromField(NodeTypeField $field, bool $flush = true) * @param null|float $position * @return $this */ - public function addNodeForField(Node $node, NodeTypeField $field, bool $flush = true, ?float $position = null) + public function addNodeForField(Node $node, NodeTypeField $field, bool $flush = true, ?float $position = null): self { $ntn = new NodesToNodes($this->getNode(), $node, $field); @@ -265,7 +252,7 @@ public function getNodeSourceByTranslation($translation): ?NodesSources * * @return $this */ - private function removeChildren() + private function removeChildren(): self { /** @var Node $node */ foreach ($this->getNode()->getChildren() as $node) { @@ -281,7 +268,7 @@ private function removeChildren() * * @return $this */ - public function removeAssociations() + public function removeAssociations(): self { /** @var NodesSources $ns */ foreach ($this->getNode()->getNodeSources() as $ns) { @@ -298,7 +285,7 @@ public function removeAssociations() * * @return $this */ - public function removeWithChildrenAndAssociations() + public function removeWithChildrenAndAssociations(): self { $this->removeChildren(); $this->removeAssociations(); @@ -322,7 +309,7 @@ private function getWorkflow(): WorkflowInterface * * @return $this */ - public function softRemoveWithChildren() + public function softRemoveWithChildren(): self { $workflow = $this->getWorkflow(); if ($workflow->can($this->getNode(), 'delete')) { @@ -346,7 +333,7 @@ public function softRemoveWithChildren() * * @return $this */ - public function softUnremoveWithChildren() + public function softUnremoveWithChildren(): self { $workflow = $this->getWorkflow(); if ($workflow->can($this->getNode(), 'undelete')) { @@ -370,7 +357,7 @@ public function softUnremoveWithChildren() * * @return $this */ - public function publishWithChildren() + public function publishWithChildren(): self { $workflow = $this->getWorkflow(); if ($workflow->can($this->getNode(), 'publish')) { @@ -393,7 +380,7 @@ public function publishWithChildren() * * @return $this */ - public function archiveWithChildren() + public function archiveWithChildren(): self { $workflow = $this->getWorkflow(); if ($workflow->can($this->getNode(), 'archive')) { @@ -562,7 +549,7 @@ public function getAllOffspringId(): array * * @return $this */ - public function makeHome() + public function makeHome(): self { $defaults = $this->getRepository() ->setDisplayingNotPublishedNodes(true) @@ -584,7 +571,7 @@ public function makeHome() * @return Node * @deprecated Use NodeDuplicator::duplicate() instead. */ - public function duplicate() + public function duplicate(): Node { $duplicator = new NodeDuplicator( $this->getNode(), @@ -597,15 +584,16 @@ public function duplicate() /** * Get previous node from hierarchy. * - * @param array|null $criteria - * @param array|null $order + * @param array|null $criteria + * @param array|null $order * * @return Node|null + * @throws NonUniqueResultException */ public function getPrevious( ?array $criteria = null, ?array $order = null - ) { + ): ?Node { if ($this->getNode()->getPosition() <= 1) { return null; } @@ -646,7 +634,7 @@ public function getPrevious( public function getNext( ?array $criteria = null, ?array $order = null - ) { + ): ?Node { if (null === $criteria) { $criteria = []; } diff --git a/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeFieldHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeFieldHandler.php index a1542bb8..2a17f9d5 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeFieldHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeFieldHandler.php @@ -12,9 +12,8 @@ /** * Handle operations with node-type fields entities. */ -class NodeTypeFieldHandler extends AbstractHandler +final class NodeTypeFieldHandler extends AbstractHandler { - private HandlerFactory $handlerFactory; private ?NodeTypeField $nodeTypeField = null; public function getNodeTypeField(): NodeTypeField @@ -35,16 +34,9 @@ public function setNodeTypeField(NodeTypeField $nodeTypeField): self return $this; } - /** - * Create a new node-type-field handler with node-type-field to handle. - * - * @param ObjectManager $objectManager - * @param HandlerFactory $handlerFactory - */ - public function __construct(ObjectManager $objectManager, HandlerFactory $handlerFactory) + public function __construct(ObjectManager $objectManager, private readonly HandlerFactory $handlerFactory) { parent::__construct($objectManager); - $this->handlerFactory = $handlerFactory; } /** diff --git a/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeHandler.php index c1ee99c3..e391a276 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/NodeTypeHandler.php @@ -24,18 +24,9 @@ /** * Handle operations with node-type entities. */ -class NodeTypeHandler extends AbstractHandler +final class NodeTypeHandler extends AbstractHandler { private ?NodeType $nodeType = null; - private EntityGeneratorFactory $entityGeneratorFactory; - private ApiResourceGenerator $apiResourceGenerator; - private HandlerFactory $handlerFactory; - private string $generatedEntitiesDir; - private SerializerInterface $serializer; - private string $serializedNodeTypesDir; - private string $importFilesConfigPath; - private string $kernelProjectDir; - private LoggerInterface $logger; /** * @return NodeType @@ -52,7 +43,7 @@ public function getNodeType(): NodeType * @param NodeType $nodeType * @return $this */ - public function setNodeType(NodeType $nodeType) + public function setNodeType(NodeType $nodeType): self { $this->nodeType = $nodeType; return $this; @@ -60,26 +51,17 @@ public function setNodeType(NodeType $nodeType) public function __construct( ObjectManager $objectManager, - EntityGeneratorFactory $entityGeneratorFactory, - HandlerFactory $handlerFactory, - SerializerInterface $serializer, - ApiResourceGenerator $apiResourceGenerator, - LoggerInterface $logger, - string $generatedEntitiesDir, - string $serializedNodeTypesDir, - string $importFilesConfigPath, - string $kernelProjectDir + private readonly EntityGeneratorFactory $entityGeneratorFactory, + private readonly HandlerFactory $handlerFactory, + private readonly SerializerInterface $serializer, + private readonly ApiResourceGenerator $apiResourceGenerator, + private readonly LoggerInterface $logger, + private readonly string $generatedEntitiesDir, + private readonly string $serializedNodeTypesDir, + private readonly string $importFilesConfigPath, + private readonly string $kernelProjectDir ) { parent::__construct($objectManager); - $this->entityGeneratorFactory = $entityGeneratorFactory; - $this->handlerFactory = $handlerFactory; - $this->generatedEntitiesDir = $generatedEntitiesDir; - $this->serializer = $serializer; - $this->serializedNodeTypesDir = $serializedNodeTypesDir; - $this->importFilesConfigPath = $importFilesConfigPath; - $this->kernelProjectDir = $kernelProjectDir; - $this->apiResourceGenerator = $apiResourceGenerator; - $this->logger = $logger; } public function getGeneratedEntitiesFolder(): string diff --git a/lib/RoadizCoreBundle/src/EntityHandler/NodesSourcesHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/NodesSourcesHandler.php index 860fa692..4b16fe3a 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/NodesSourcesHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/NodesSourcesHandler.php @@ -6,6 +6,7 @@ use Doctrine\ORM\EntityRepository; use Doctrine\Persistence\ObjectManager; +use RZ\Roadiz\Core\Handlers\AbstractHandler; use RZ\Roadiz\CoreBundle\Bag\Settings; use RZ\Roadiz\CoreBundle\Entity\Document; use RZ\Roadiz\CoreBundle\Entity\Node; @@ -13,32 +14,21 @@ use RZ\Roadiz\CoreBundle\Entity\NodesSourcesDocuments; use RZ\Roadiz\CoreBundle\Entity\NodeTypeField; use RZ\Roadiz\CoreBundle\Entity\Tag; -use RZ\Roadiz\CoreBundle\Repository\NodesSourcesRepository; -use RZ\Roadiz\Core\Handlers\AbstractHandler; /** * Handle operations with node-sources entities. */ -class NodesSourcesHandler extends AbstractHandler +final class NodesSourcesHandler extends AbstractHandler { - protected ?NodesSources $nodeSource = null; + private ?NodesSources $nodeSource = null; /** * @var array|null */ - protected ?array $parentsNodeSources = null; - protected Settings $settingsBag; + private ?array $parentsNodeSources = null; - /** - * Create a new node-source handler with node-source to handle. - * - * @param ObjectManager $objectManager - * @param Settings $settingsBag - */ - public function __construct(ObjectManager $objectManager, Settings $settingsBag) + public function __construct(ObjectManager $objectManager, private readonly Settings $settingsBag) { parent::__construct($objectManager); - - $this->settingsBag = $settingsBag; } /** @@ -62,9 +52,9 @@ public function getNodeSource(): NodesSources /** * @param NodesSources $nodeSource - * @return NodesSourcesHandler + * @return $this */ - public function setNodeSource(NodesSources $nodeSource) + public function setNodeSource(NodesSources $nodeSource): self { $this->nodeSource = $nodeSource; return $this; @@ -77,7 +67,7 @@ public function setNodeSource(NodesSources $nodeSource) * @param bool $flush * @return $this */ - public function cleanDocumentsFromField(NodeTypeField $field, bool $flush = true) + public function cleanDocumentsFromField(NodeTypeField $field, bool $flush = true): self { $this->nodeSource->clearDocumentsByFields($field); @@ -102,7 +92,7 @@ public function addDocumentForField( NodeTypeField $field, bool $flush = true, ?float $position = null - ) { + ): self { $nsDoc = new NodesSourcesDocuments($this->nodeSource, $document, $field); if (!$this->nodeSource->hasNodesSourcesDocuments($nsDoc)) { @@ -455,9 +445,9 @@ public function getNext( /** * Get node tags with current source translation. * - * @return array + * @return iterable */ - public function getTags() + public function getTags(): iterable { /** * @phpstan-ignore-next-line @@ -501,7 +491,7 @@ public function getSEO(): array * * @return array Collection of nodes */ - public function getNodesFromFieldName(string $fieldName) + public function getNodesFromFieldName(string $fieldName): array { $field = $this->nodeSource->getNode()->getNodeType()->getFieldByName($fieldName); if (null !== $field) { @@ -523,7 +513,7 @@ public function getNodesFromFieldName(string $fieldName) * * @return array Collection of nodes */ - public function getReverseNodesFromFieldName(string $fieldName) + public function getReverseNodesFromFieldName(string $fieldName): array { $field = $this->nodeSource->getNode()->getNodeType()->getFieldByName($fieldName); if (null !== $field) { diff --git a/lib/RoadizCoreBundle/src/EntityHandler/TagHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/TagHandler.php index b99e28c2..e3cf16b0 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/TagHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/TagHandler.php @@ -13,7 +13,7 @@ /** * Handle operations with tags entities. */ -class TagHandler extends AbstractHandler +final class TagHandler extends AbstractHandler { private ?Tag $tag = null; @@ -32,7 +32,7 @@ public function getTag(): Tag * @param Tag $tag * @return $this */ - public function setTag(Tag $tag) + public function setTag(Tag $tag): self { $this->tag = $tag; return $this; @@ -43,7 +43,7 @@ public function setTag(Tag $tag) * * @return $this */ - private function removeChildren() + private function removeChildren(): self { /** @var Tag $tag */ foreach ($this->tag->getChildren() as $tag) { @@ -59,7 +59,7 @@ private function removeChildren() * * @return $this */ - public function removeAssociations() + public function removeAssociations(): self { foreach ($this->tag->getTranslatedTags() as $tt) { $this->objectManager->remove($tt); @@ -73,7 +73,7 @@ public function removeAssociations() * * @return $this */ - public function removeWithChildrenAndAssociations() + public function removeWithChildrenAndAssociations(): self { $this->removeChildren(); $this->removeAssociations(); @@ -88,120 +88,6 @@ public function removeWithChildrenAndAssociations() return $this; } - /** - * @return array Array of Translation - * @deprecated Do not query DB here - */ - public function getAvailableTranslations() - { - $query = $this->objectManager - ->createQuery(' - SELECT tr - FROM RZ\Roadiz\CoreBundle\Entity\Translation tr - INNER JOIN tr.tagTranslations tt - INNER JOIN tt.tag t - WHERE t.id = :tag_id') - ->setParameter('tag_id', $this->tag->getId()); - - try { - return $query->getResult(); - } catch (NoResultException $e) { - return []; - } - } - /** - * @return array Array of Translation id - * @deprecated Do not query DB here - */ - public function getAvailableTranslationsId() - { - $query = $this->objectManager - ->createQuery(' - SELECT tr.id FROM RZ\Roadiz\CoreBundle\Entity\Tag t - INNER JOIN t.translatedTags tt - INNER JOIN tt.translation tr - WHERE t.id = :tag_id') - ->setParameter('tag_id', $this->tag->getId()); - - try { - $simpleArray = []; - $complexArray = $query->getScalarResult(); - foreach ($complexArray as $subArray) { - $simpleArray[] = $subArray['id']; - } - - return $simpleArray; - } catch (NoResultException $e) { - return []; - } - } - - /** - * @return array Array of Translation - * @deprecated Do not query DB here - */ - public function getUnavailableTranslations() - { - $query = $this->objectManager - ->createQuery(' - SELECT tr FROM RZ\Roadiz\CoreBundle\Entity\Translation tr - WHERE tr.id NOT IN (:translations_id)') - ->setParameter('translations_id', $this->getAvailableTranslationsId()); - - try { - return $query->getResult(); - } catch (NoResultException $e) { - return []; - } - } - - /** - * @return array Array of Translation id - * @deprecated Do not query DB here - */ - public function getUnavailableTranslationsId() - { - /** @var Query $query */ - $query = $this->objectManager - ->createQuery(' - SELECT t.id FROM RZ\Roadiz\CoreBundle\Entity\Translation t - WHERE t.id NOT IN (:translations_id)') - ->setParameter('translations_id', $this->getAvailableTranslationsId()); - - try { - $simpleArray = []; - $complexArray = $query->getScalarResult(); - foreach ($complexArray as $subArray) { - $simpleArray[] = $subArray['id']; - } - - return $simpleArray; - } catch (NoResultException $e) { - return []; - } - } - - /** - * Return every tag’s parents. - * @deprecated Use directly Tag::getParents - * @return array - */ - public function getParents() - { - return $this->tag->getParents(); - } - - /** - * Get tag full path using tag names. - * - * @deprecated Use directly Tag::getFullPath - * @return string - */ - public function getFullPath(): string - { - return $this->tag->getFullPath(); - } - /** * Clean position for current tag siblings. * diff --git a/lib/RoadizCoreBundle/src/EntityHandler/TranslationHandler.php b/lib/RoadizCoreBundle/src/EntityHandler/TranslationHandler.php index 7a9d9673..3fc38349 100644 --- a/lib/RoadizCoreBundle/src/EntityHandler/TranslationHandler.php +++ b/lib/RoadizCoreBundle/src/EntityHandler/TranslationHandler.php @@ -14,7 +14,7 @@ /** * Handle operations with translations entities. */ -class TranslationHandler extends AbstractHandler +final class TranslationHandler extends AbstractHandler { private ?TranslationInterface $translation = null; @@ -34,7 +34,7 @@ public function getTranslation(): TranslationInterface * * @return $this */ - public function setTranslation(TranslationInterface $translation) + public function setTranslation(TranslationInterface $translation): self { $this->translation = $translation; return $this; @@ -45,7 +45,7 @@ public function setTranslation(TranslationInterface $translation) * * @return $this */ - public function makeDefault() + public function makeDefault(): self { $defaults = $this->objectManager ->getRepository(Translation::class) diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/AssetsCacheEventSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/AssetsCacheEventSubscriber.php index 1e729545..664344d0 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/AssetsCacheEventSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/AssetsCacheEventSubscriber.php @@ -11,23 +11,16 @@ final class AssetsCacheEventSubscriber implements EventSubscriberInterface { - private AssetsFileClearer $assetsClearer; - private LoggerInterface $logger; - - public function __construct(AssetsFileClearer $assetsClearer, LoggerInterface $logger) - { - $this->assetsClearer = $assetsClearer; - $this->logger = $logger; + public function __construct( + private readonly AssetsFileClearer $assetsClearer, + private readonly LoggerInterface $logger + ) { } - /** - * @inheritDoc - */ public static function getSubscribedEvents(): array { return [ - CachePurgeAssetsRequestEvent::class => ['onPurgeAssetsRequest', 0], - '\RZ\Roadiz\Core\Events\Cache\CachePurgeAssetsRequestEvent' => ['onPurgeAssetsRequest', 0], + CachePurgeAssetsRequestEvent::class => ['onPurgeAssetsRequest', 0] ]; } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php index 1e6ba43f..0ffa1a25 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/AutomaticWebhookSubscriber.php @@ -25,23 +25,11 @@ final class AutomaticWebhookSubscriber implements EventSubscriberInterface { - private WebhookDispatcher $webhookDispatcher; - private HandlerFactoryInterface $handlerFactory; - private ManagerRegistry $managerRegistry; - - /** - * @param WebhookDispatcher $webhookDispatcher - * @param ManagerRegistry $managerRegistry - * @param HandlerFactoryInterface $handlerFactory - */ public function __construct( - WebhookDispatcher $webhookDispatcher, - ManagerRegistry $managerRegistry, - HandlerFactoryInterface $handlerFactory + private readonly WebhookDispatcher $webhookDispatcher, + private readonly ManagerRegistry $managerRegistry, + private readonly HandlerFactoryInterface $handlerFactory ) { - $this->webhookDispatcher = $webhookDispatcher; - $this->handlerFactory = $handlerFactory; - $this->managerRegistry = $managerRegistry; } public static function getSubscribedEvents(): array @@ -49,21 +37,13 @@ public static function getSubscribedEvents(): array return [ 'workflow.node.completed' => ['onAutomaticWebhook'], NodeVisibilityChangedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\Node\NodeVisibilityChangedEvent' => 'onAutomaticWebhook', NodesSourcesPreUpdatedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\NodesSources\NodesSourcesPreUpdatedEvent' => 'onAutomaticWebhook', NodesSourcesDeletedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\NodesSources\NodesSourcesDeletedEvent' => 'onAutomaticWebhook', NodeUpdatedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\Node\NodeUpdatedEvent' => 'onAutomaticWebhook', NodeDeletedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\Node\NodeDeletedEvent' => 'onAutomaticWebhook', NodeTaggedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\Node\NodeTaggedEvent' => 'onAutomaticWebhook', TagUpdatedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\Tag\TagUpdatedEvent' => 'onAutomaticWebhook', DocumentTranslationUpdatedEvent::class => 'onAutomaticWebhook', - '\RZ\Roadiz\Core\Events\DocumentTranslationUpdatedEvent' => 'onAutomaticWebhook', DocumentUpdatedEvent::class => 'onAutomaticWebhook', ]; } @@ -115,8 +95,6 @@ private function isEventSubjectInRootNode(mixed $event, ?Node $rootNode): bool */ return true; } - /** @var Node|null $subject */ - $subject = null; switch (true) { case $event instanceof Event: diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/CloudflareCacheEventSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/CloudflareCacheEventSubscriber.php index caa710e9..48fd5f2e 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/CloudflareCacheEventSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/CloudflareCacheEventSubscriber.php @@ -24,27 +24,12 @@ final class CloudflareCacheEventSubscriber implements EventSubscriberInterface { - private LoggerInterface $logger; - private MessageBusInterface $bus; - private UrlGeneratorInterface $urlGenerator; - private ReverseProxyCacheLocator $reverseProxyCacheLocator; - - /** - * @param MessageBusInterface $bus - * @param ReverseProxyCacheLocator $reverseProxyCacheLocator - * @param UrlGeneratorInterface $urlGenerator - * @param LoggerInterface $logger - */ public function __construct( - MessageBusInterface $bus, - ReverseProxyCacheLocator $reverseProxyCacheLocator, - UrlGeneratorInterface $urlGenerator, - LoggerInterface $logger + private readonly MessageBusInterface $bus, + private readonly ReverseProxyCacheLocator $reverseProxyCacheLocator, + private readonly UrlGeneratorInterface $urlGenerator, + private readonly LoggerInterface $logger ) { - $this->logger = $logger; - $this->bus = $bus; - $this->reverseProxyCacheLocator = $reverseProxyCacheLocator; - $this->urlGenerator = $urlGenerator; } /** * @inheritDoc @@ -53,25 +38,15 @@ public static function getSubscribedEvents(): array { return [ CachePurgeRequestEvent::class => ['onBanRequest', 3], - '\RZ\Roadiz\Core\Events\Cache\CachePurgeRequestEvent' => ['onBanRequest', 3], NodesSourcesUpdatedEvent::class => ['onPurgeRequest', 3], - '\RZ\Roadiz\Core\Events\NodesSources\NodesSourcesUpdatedEvent' => ['onPurgeRequest', 3], ]; } - /** - * @return bool - */ protected function supportConfig(): bool { return null !== $this->reverseProxyCacheLocator->getCloudflareProxyCache(); } - /** - * @param CachePurgeRequestEvent $event - * @throws \GuzzleHttp\Exception\GuzzleException - * @return void - */ public function onBanRequest(CachePurgeRequestEvent $event): void { if (!$this->supportConfig()) { @@ -109,11 +84,6 @@ public function onBanRequest(CachePurgeRequestEvent $event): void } } - /** - * @param NodesSourcesUpdatedEvent $event - * - * @throws \GuzzleHttp\Exception\GuzzleException - */ public function onPurgeRequest(NodesSourcesUpdatedEvent $event): void { if (!$this->supportConfig()) { @@ -154,6 +124,7 @@ private function getCloudflareCacheProxy(): CloudflareProxyCache /** * @param array $body * @return Request + * @throws \JsonException */ protected function createRequest(array $body): Request { @@ -169,10 +140,7 @@ protected function createRequest(array $body): Request $this->getCloudflareCacheProxy()->getVersion(), $this->getCloudflareCacheProxy()->getZone() ); - $body = \json_encode($body); - if (false === $body) { - throw new \RuntimeException('Unable to json_encode body'); - } + $body = \json_encode($body, JSON_THROW_ON_ERROR); return new Request( 'POST', $uri, @@ -183,6 +151,7 @@ protected function createRequest(array $body): Request /** * @return Request + * @throws \JsonException */ protected function createBanRequest(): Request { @@ -193,8 +162,8 @@ protected function createBanRequest(): Request /** * @param string[] $uris - * * @return Request + * @throws \JsonException */ protected function createPurgeRequest(array $uris = []): Request { diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php index c135ab01..19a3b5f5 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/LocaleSubscriber.php @@ -13,13 +13,10 @@ final class LocaleSubscriber implements EventSubscriberInterface { - private ManagerRegistry $managerRegistry; - private RequestContextAwareInterface $router; - - public function __construct(ManagerRegistry $managerRegistry, RequestContextAwareInterface $router) - { - $this->managerRegistry = $managerRegistry; - $this->router = $router; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly RequestContextAwareInterface $router + ) { } /** diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/LoggableSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/LoggableSubscriber.php index 9dc9a7ed..8bec9f86 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/LoggableSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/LoggableSubscriber.php @@ -5,27 +5,18 @@ namespace RZ\Roadiz\CoreBundle\EventSubscriber; use Gedmo\Loggable\LoggableListener; +use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; final class LoggableSubscriber implements EventSubscriberInterface { - private LoggableListener $loggableListener; - private ?TokenStorageInterface $tokenStorage; - private ?AuthorizationCheckerInterface $authorizationChecker; - public function __construct( - LoggableListener $loggableListener, - TokenStorageInterface $tokenStorage = null, - AuthorizationCheckerInterface $authorizationChecker = null + private readonly LoggableListener $loggableListener, + private readonly Security $security, ) { - $this->loggableListener = $loggableListener; - $this->tokenStorage = $tokenStorage; - $this->authorizationChecker = $authorizationChecker; } public function onKernelRequest(RequestEvent $event): void @@ -34,14 +25,12 @@ public function onKernelRequest(RequestEvent $event): void return; } - if (null === $this->tokenStorage || null === $this->authorizationChecker) { + if (null === $user = $this->security->getUser()) { return; } - $token = $this->tokenStorage->getToken(); - - if (null !== $token && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { - $this->loggableListener->setUsername($token); + if ($this->security->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + $this->loggableListener->setUsername($user); } } diff --git a/lib/RoadizCoreBundle/src/EventSubscriber/NodeDuplicationSubscriber.php b/lib/RoadizCoreBundle/src/EventSubscriber/NodeDuplicationSubscriber.php index 7370ee3d..6990f179 100644 --- a/lib/RoadizCoreBundle/src/EventSubscriber/NodeDuplicationSubscriber.php +++ b/lib/RoadizCoreBundle/src/EventSubscriber/NodeDuplicationSubscriber.php @@ -10,26 +10,18 @@ use RZ\Roadiz\CoreBundle\EntityHandler\NodeHandler; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class NodeDuplicationSubscriber implements EventSubscriberInterface +final class NodeDuplicationSubscriber implements EventSubscriberInterface { - protected HandlerFactoryInterface $handlerFactory; - private ManagerRegistry $managerRegistry; - - /** - * @param ManagerRegistry $managerRegistry - * @param HandlerFactoryInterface $handlerFactory - */ - public function __construct(ManagerRegistry $managerRegistry, HandlerFactoryInterface $handlerFactory) - { - $this->handlerFactory = $handlerFactory; - $this->managerRegistry = $managerRegistry; + public function __construct( + private readonly ManagerRegistry $managerRegistry, + private readonly HandlerFactoryInterface $handlerFactory + ) { } public static function getSubscribedEvents(): array { return [ NodeDuplicatedEvent::class => 'cleanPosition', - '\RZ\Roadiz\Core\Events\Node\NodeDuplicatedEvent' => 'cleanPosition', ]; } diff --git a/lib/RoadizCoreBundle/src/Mailer/ContactFormManager.php b/lib/RoadizCoreBundle/src/Mailer/ContactFormManager.php index 1c340f40..8fa3df41 100644 --- a/lib/RoadizCoreBundle/src/Mailer/ContactFormManager.php +++ b/lib/RoadizCoreBundle/src/Mailer/ContactFormManager.php @@ -56,10 +56,6 @@ class ContactFormManager extends EmailManager 'image/gif', ]; protected int $maxFileSize = 5242880; // 5MB - protected FormFactoryInterface $formFactory; - protected FormErrorSerializerInterface $formErrorSerializer; - protected ?string $recaptchaPrivateKey; - protected ?string $recaptchaPublicKey; /* * DO NOT DIRECTLY USE THIS CONSTRUCTOR @@ -67,20 +63,18 @@ class ContactFormManager extends EmailManager */ public function __construct( RequestStack $requestStack, - FormFactoryInterface $formFactory, TranslatorInterface $translator, Environment $templating, MailerInterface $mailer, Settings $settingsBag, DocumentUrlGeneratorInterface $documentUrlGenerator, - FormErrorSerializerInterface $formErrorSerializer, - ?string $recaptchaPrivateKey, - ?string $recaptchaPublicKey + protected readonly FormFactoryInterface $formFactory, + protected readonly FormErrorSerializerInterface $formErrorSerializer, + protected readonly ?string $recaptchaPrivateKey, + protected readonly ?string $recaptchaPublicKey ) { parent::__construct($requestStack, $translator, $templating, $mailer, $settingsBag, $documentUrlGenerator); - $this->formFactory = $formFactory; - $this->formErrorSerializer = $formErrorSerializer; $this->options = [ 'attr' => [ 'id' => 'contactForm', @@ -101,8 +95,6 @@ public function __construct( 'new.contact.form.%site%', ['%site%' => $this->settingsBag->get('site_name')] )); - $this->recaptchaPrivateKey = $recaptchaPrivateKey; - $this->recaptchaPublicKey = $recaptchaPublicKey; } /** @@ -130,7 +122,7 @@ public function setFormName(string $formName): ContactFormManager * * @return $this */ - public function disableCsrfProtection() + public function disableCsrfProtection(): self { $this->options['csrf_protection'] = false; return $this; @@ -153,7 +145,7 @@ public function getForm(): FormInterface * @see https://symfony.com/doc/4.4/reference/constraints/Email.html#strict * @return $this */ - public function setEmailStrictMode(bool $emailStrictMode = true) + public function setEmailStrictMode(bool $emailStrictMode = true): self { $this->emailStrictMode = $emailStrictMode; @@ -171,9 +163,9 @@ public function isEmailStrictMode(): bool * Adds email, name and message fields with their constraints. * * @param bool $useHoneypot - * @return ContactFormManager $this + * @return $this */ - public function withDefaultFields(bool $useHoneypot = true) + public function withDefaultFields(bool $useHoneypot = true): self { $this->getFormBuilder()->add('email', EmailType::class, [ 'label' => 'your.email', @@ -184,7 +176,7 @@ public function withDefaultFields(bool $useHoneypot = true) 'message' => 'email.not.valid', 'mode' => $this->isEmailStrictMode() ? Email::VALIDATION_MODE_STRICT : - Email::VALIDATION_MODE_LOOSE + Email::VALIDATION_MODE_HTML5 ]), ], ]) @@ -217,7 +209,7 @@ public function withDefaultFields(bool $useHoneypot = true) * @param string $honeypotName * @return $this */ - public function withHoneypot(string $honeypotName = 'eml') + public function withHoneypot(string $honeypotName = 'eml'): self { $this->getFormBuilder()->add($honeypotName, HoneypotType::class); return $this; @@ -229,7 +221,7 @@ public function withHoneypot(string $honeypotName = 'eml') * @param string $consentDescription * @return $this */ - public function withUserConsent(string $consentDescription = 'contact_form.user_consent') + public function withUserConsent(string $consentDescription = 'contact_form.user_consent'): self { $this->getFormBuilder()->add('consent', CheckboxType::class, [ 'label' => $consentDescription, @@ -276,7 +268,7 @@ public function getFormBuilder(): FormBuilderInterface public function withGoogleRecaptcha( string $name = 'recaptcha', string $validatorFieldName = Recaptcha::FORM_NAME - ) { + ): self { if ( !empty($this->recaptchaPublicKey) && !empty($this->recaptchaPrivateKey) @@ -634,7 +626,7 @@ public function getRedirectUrl(): ?string * * @return self */ - public function setRedirectUrl(?string $redirectUrl) + public function setRedirectUrl(?string $redirectUrl): self { $this->redirectUrl = $redirectUrl; @@ -646,7 +638,7 @@ public function setRedirectUrl(?string $redirectUrl) * * @return int */ - public function getMaxFileSize() + public function getMaxFileSize(): int { return $this->maxFileSize; } @@ -658,7 +650,7 @@ public function getMaxFileSize() * * @return self */ - public function setMaxFileSize($maxFileSize) + public function setMaxFileSize($maxFileSize): self { $this->maxFileSize = (int) $maxFileSize; @@ -670,7 +662,7 @@ public function setMaxFileSize($maxFileSize) * * @return array */ - public function getAllowedMimeTypes() + public function getAllowedMimeTypes(): array { return $this->allowedMimeTypes; } @@ -682,7 +674,7 @@ public function getAllowedMimeTypes() * * @return self */ - public function setAllowedMimeTypes(array $allowedMimeTypes) + public function setAllowedMimeTypes(array $allowedMimeTypes): self { $this->allowedMimeTypes = $allowedMimeTypes; @@ -692,7 +684,7 @@ public function setAllowedMimeTypes(array $allowedMimeTypes) /** * @return array */ - public function getOptions() + public function getOptions(): array { return $this->options; } @@ -700,9 +692,9 @@ public function getOptions() /** * @param array $options * - * @return ContactFormManager + * @return $this */ - public function setOptions($options) + public function setOptions(array $options): self { $this->options = $options; diff --git a/lib/RoadizCoreBundle/src/Mailer/EmailManager.php b/lib/RoadizCoreBundle/src/Mailer/EmailManager.php index eb84898f..73890767 100644 --- a/lib/RoadizCoreBundle/src/Mailer/EmailManager.php +++ b/lib/RoadizCoreBundle/src/Mailer/EmailManager.php @@ -33,43 +33,30 @@ class EmailManager protected ?Address $origin = null; protected string $successMessage = 'email.successfully.sent'; protected string $failMessage = 'email.has.errors'; - protected TranslatorInterface $translator; - protected Environment $templating; - protected MailerInterface $mailer; protected ?string $emailTemplate = null; protected ?string $emailPlainTextTemplate = null; protected string $emailStylesheet; - protected RequestStack $requestStack; protected array $assignation; protected ?Email $message; - protected ?Settings $settingsBag; - protected ?DocumentUrlGeneratorInterface $documentUrlGenerator; /** @var File[] */ protected array $files = []; /** @var array */ protected array $resources = []; public function __construct( - RequestStack $requestStack, - TranslatorInterface $translator, - Environment $templating, - MailerInterface $mailer, - ?Settings $settingsBag = null, - ?DocumentUrlGeneratorInterface $documentUrlGenerator = null + protected readonly RequestStack $requestStack, + protected readonly TranslatorInterface $translator, + protected readonly Environment $templating, + protected readonly MailerInterface $mailer, + protected readonly Settings $settingsBag, + protected readonly DocumentUrlGeneratorInterface $documentUrlGenerator ) { - $this->requestStack = $requestStack; - $this->translator = $translator; - $this->mailer = $mailer; - $this->templating = $templating; $this->assignation = []; $this->message = null; - /* * Sets a default CSS for emails. */ $this->emailStylesheet = dirname(__DIR__) . '/../css/transactionalStyles.css'; - $this->settingsBag = $settingsBag; - $this->documentUrlGenerator = $documentUrlGenerator; } /** @@ -278,7 +265,7 @@ public function getReceiverEmail(): ?string * @return $this * @throws \Exception */ - public function setReceiver($receiver): static + public function setReceiver(mixed $receiver): static { if ($receiver instanceof Address) { $this->receiver = [$receiver]; @@ -333,7 +320,7 @@ public function getSenderEmail(): ?string * @return $this * @throws \Exception */ - public function setSender($sender): static + public function setSender(mixed $sender): static { if ($sender instanceof Address) { $this->sender = [$sender]; @@ -401,16 +388,6 @@ public function getTranslator(): TranslatorInterface return $this->translator; } - /** - * @param TranslatorInterface $translator - * @return $this - */ - public function setTranslator(TranslatorInterface $translator): static - { - $this->translator = $translator; - return $this; - } - /** * @return Environment */ @@ -419,16 +396,6 @@ public function getTemplating(): Environment return $this->templating; } - /** - * @param Environment $templating - * @return $this - */ - public function setTemplating(Environment $templating): static - { - $this->templating = $templating; - return $this; - } - /** * @return MailerInterface */ @@ -437,16 +404,6 @@ public function getMailer(): MailerInterface return $this->mailer; } - /** - * @param MailerInterface $mailer - * @return $this - */ - public function setMailer(MailerInterface $mailer): static - { - $this->mailer = $mailer; - return $this; - } - /** * @return string|null */ diff --git a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/AbstractIndexer.php b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/AbstractIndexer.php index ee723f7f..94e9716c 100644 --- a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/AbstractIndexer.php +++ b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/AbstractIndexer.php @@ -14,22 +14,16 @@ abstract class AbstractIndexer implements CliAwareIndexer { - private ClientRegistry $clientRegistry; - protected SolariumFactoryInterface $solariumFactory; protected LoggerInterface $logger; protected ?SymfonyStyle $io = null; - protected ManagerRegistry $managerRegistry; public function __construct( - ClientRegistry $clientRegistry, - ManagerRegistry $managerRegistry, - SolariumFactoryInterface $solariumFactory, - LoggerInterface $searchEngineLogger + protected readonly ClientRegistry $clientRegistry, + protected readonly ManagerRegistry $managerRegistry, + protected readonly SolariumFactoryInterface $solariumFactory, + readonly LoggerInterface $searchEngineLogger ) { - $this->solariumFactory = $solariumFactory; - $this->clientRegistry = $clientRegistry; $this->logger = $searchEngineLogger; - $this->managerRegistry = $managerRegistry; } /** diff --git a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/DocumentIndexer.php b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/DocumentIndexer.php index 20992dff..7118e785 100644 --- a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/DocumentIndexer.php +++ b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/DocumentIndexer.php @@ -61,9 +61,8 @@ public function reindexAll(): void ->createQueryBuilder('d') ->getQuery(); - if (null !== $this->io) { - $this->io->progressStart((int) $countQuery->getSingleScalarResult()); - } + $this->io?->title(get_class($this)); + $this->io?->progressStart((int) $countQuery->getSingleScalarResult()); foreach ($q->toIterable() as $row) { $solarium = $this->solariumFactory->createWithDocument($row); @@ -72,9 +71,7 @@ public function reindexAll(): void foreach ($solarium->getDocuments() as $document) { $buffer->addDocument($document); } - if (null !== $this->io) { - $this->io->progressAdvance(); - } + $this->io?->progressAdvance(); // detach from Doctrine, so that it can be Garbage-Collected immediately $this->managerRegistry->getManager()->detach($row); } @@ -83,8 +80,6 @@ public function reindexAll(): void // optimize the index $this->optimizeSolr(); - if (null !== $this->io) { - $this->io->progressFinish(); - } + $this->io?->progressFinish(); } } diff --git a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/NodesSourcesIndexer.php b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/NodesSourcesIndexer.php index a7780845..65279dd0 100644 --- a/lib/RoadizCoreBundle/src/SearchEngine/Indexer/NodesSourcesIndexer.php +++ b/lib/RoadizCoreBundle/src/SearchEngine/Indexer/NodesSourcesIndexer.php @@ -115,9 +115,8 @@ public function reindexAll(int $batchCount = 1, int $batchNumber = 0): void */ $paginator = new Paginator($baseQb->getQuery(), true); - if (null !== $this->io) { - $this->io->progressStart($count); - } + $this->io?->title(get_class($this)); + $this->io?->progressStart($count); foreach ($paginator as $row) { $solarium = $this->solariumFactory->createWithNodesSources($row); @@ -125,9 +124,7 @@ public function reindexAll(int $batchCount = 1, int $batchNumber = 0): void $solarium->index(); $buffer->addDocument($solarium->getDocument()); - if (null !== $this->io) { - $this->io->progressAdvance(); - } + $this->io?->progressAdvance(); // detach from Doctrine, so that it can be Garbage-Collected immediately $this->managerRegistry->getManager()->detach($row); } @@ -137,8 +134,6 @@ public function reindexAll(int $batchCount = 1, int $batchNumber = 0): void // optimize the index $this->optimizeSolr(); - if (null !== $this->io) { - $this->io->progressFinish(); - } + $this->io?->progressFinish(); } } diff --git a/lib/RoadizCoreBundle/src/TwigExtension/AttributesExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/AttributesExtension.php index 890cfa49..92755704 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/AttributesExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/AttributesExtension.php @@ -19,16 +19,10 @@ use Twig\TwigFunction; use Twig\TwigTest; -class AttributesExtension extends AbstractExtension +final class AttributesExtension extends AbstractExtension { - protected EntityManagerInterface $entityManager; - - /** - * @param EntityManagerInterface $entityManager - */ - public function __construct(EntityManagerInterface $entityManager) + public function __construct(private readonly EntityManagerInterface $entityManager) { - $this->entityManager = $entityManager; } public function getFunctions(): array @@ -213,7 +207,7 @@ public function getNodeSourceGroupedAttributeValues(?NodesSources $nodesSources, * * @return string|null */ - public function getAttributeLabelOrCode($mixed, TranslationInterface $translation = null): ?string + public function getAttributeLabelOrCode(mixed $mixed, TranslationInterface $translation = null): ?string { if (null === $mixed) { return null; @@ -240,7 +234,7 @@ public function getAttributeLabelOrCode($mixed, TranslationInterface $translatio * @param TranslationInterface|null $translation * @return string|null */ - public function getAttributeGroupLabelOrCode($mixed, TranslationInterface $translation = null): ?string + public function getAttributeGroupLabelOrCode(mixed $mixed, TranslationInterface $translation = null): ?string { if (null === $mixed) { return null; diff --git a/lib/RoadizCoreBundle/src/TwigExtension/BlockRenderExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/BlockRenderExtension.php index e4944307..5e028743 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/BlockRenderExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/BlockRenderExtension.php @@ -15,16 +15,10 @@ * Extension that allow render inner page part calling directly their * controller response instead of doing a simple include. */ -class BlockRenderExtension extends AbstractExtension +final class BlockRenderExtension extends AbstractExtension { - protected FragmentHandler $handler; - - /** - * @param FragmentHandler $handler - */ - public function __construct(FragmentHandler $handler) + public function __construct(private readonly FragmentHandler $handler) { - $this->handler = $handler; } public function getFilters(): array @@ -42,7 +36,7 @@ public function getFilters(): array * @return string * @throws RuntimeError */ - public function blockRender(NodesSources $nodeSource = null, string $themeName = "DefaultTheme", array $assignation = []) + public function blockRender(NodesSources $nodeSource = null, string $themeName = "DefaultTheme", array $assignation = []): string { if (null !== $nodeSource) { if (!empty($themeName)) { diff --git a/lib/RoadizCoreBundle/src/TwigExtension/CentralTruncateExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/CentralTruncateExtension.php index 8c3c8851..077e73e9 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/CentralTruncateExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/CentralTruncateExtension.php @@ -9,7 +9,7 @@ use function Symfony\Component\String\u; -class CentralTruncateExtension extends AbstractExtension +final class CentralTruncateExtension extends AbstractExtension { public function getFilters(): array { diff --git a/lib/RoadizCoreBundle/src/TwigExtension/DocumentUrlExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/DocumentUrlExtension.php index 869d4d6b..f7c59709 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/DocumentUrlExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/DocumentUrlExtension.php @@ -15,21 +15,12 @@ /** * Extension that allow render documents Url */ -class DocumentUrlExtension extends AbstractExtension +final class DocumentUrlExtension extends AbstractExtension { - protected DocumentUrlGeneratorInterface $documentUrlGenerator; - protected bool $throwExceptions; - - /** - * @param DocumentUrlGeneratorInterface $documentUrlGenerator - * @param bool $throwExceptions Trigger exception if using filter on NULL values (default: false) - */ public function __construct( - DocumentUrlGeneratorInterface $documentUrlGenerator, - bool $throwExceptions = false + private readonly DocumentUrlGeneratorInterface $documentUrlGenerator, + private readonly bool $throwExceptions = false ) { - $this->throwExceptions = $throwExceptions; - $this->documentUrlGenerator = $documentUrlGenerator; } /** @@ -54,7 +45,7 @@ public function getFilters(): array * @return string * @throws RuntimeError */ - public function getUrl(PersistableInterface $mixed = null, array $criteria = []) + public function getUrl(PersistableInterface $mixed = null, array $criteria = []): string { if (null === $mixed) { if ($this->throwExceptions) { diff --git a/lib/RoadizCoreBundle/src/TwigExtension/HandlerExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/HandlerExtension.php index 186355d6..46bd6cd0 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/HandlerExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/HandlerExtension.php @@ -4,6 +4,8 @@ namespace RZ\Roadiz\CoreBundle\TwigExtension; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use RZ\Roadiz\Core\AbstractEntities\AbstractEntity; use RZ\Roadiz\Core\Handlers\AbstractHandler; use RZ\Roadiz\CoreBundle\EntityHandler\HandlerFactory; @@ -13,14 +15,8 @@ final class HandlerExtension extends AbstractExtension { - private HandlerFactory $handlerFactory; - - /** - * @param HandlerFactory $handlerFactory - */ - public function __construct(HandlerFactory $handlerFactory) + public function __construct(private readonly HandlerFactory $handlerFactory) { - $this->handlerFactory = $handlerFactory; } public function getFilters(): array @@ -34,8 +30,10 @@ public function getFilters(): array * @param mixed $mixed * @return AbstractHandler|null * @throws RuntimeError + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function getHandler($mixed) + public function getHandler(mixed $mixed): ?AbstractHandler { if (null === $mixed) { return null; diff --git a/lib/RoadizCoreBundle/src/TwigExtension/JwtExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/JwtExtension.php index c8d2452b..246e20d8 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/JwtExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/JwtExtension.php @@ -9,24 +9,16 @@ use Psr\Log\LoggerInterface; use RZ\Roadiz\CoreBundle\Preview\User\PreviewUserProviderInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -use Symfony\Component\Security\Core\User\UserInterface; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; final class JwtExtension extends AbstractExtension { - private PreviewUserProviderInterface $previewUserProvider; - private JWTTokenManagerInterface $tokenManager; - private LoggerInterface $logger; - public function __construct( - JWTTokenManagerInterface $tokenManager, - LoggerInterface $logger, - PreviewUserProviderInterface $previewUserProvider + private readonly JWTTokenManagerInterface $tokenManager, + private readonly LoggerInterface $logger, + private readonly PreviewUserProviderInterface $previewUserProvider ) { - $this->tokenManager = $tokenManager; - $this->logger = $logger; - $this->previewUserProvider = $previewUserProvider; } public function getFunctions(): array diff --git a/lib/RoadizCoreBundle/src/TwigExtension/LogExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/LogExtension.php index d34d9f35..cfaa612e 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/LogExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/LogExtension.php @@ -20,13 +20,10 @@ final class LogExtension extends AbstractExtension { - private Security $security; - private UrlGeneratorInterface $urlGenerator; - - public function __construct(Security $security, UrlGeneratorInterface $urlGenerator) - { - $this->security = $security; - $this->urlGenerator = $urlGenerator; + public function __construct( + private readonly Security $security, + private readonly UrlGeneratorInterface $urlGenerator + ) { } public function getFunctions(): array diff --git a/lib/RoadizCoreBundle/src/TwigExtension/NodesSourcesExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/NodesSourcesExtension.php index 61726ab0..05e0248a 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/NodesSourcesExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/NodesSourcesExtension.php @@ -4,8 +4,12 @@ namespace RZ\Roadiz\CoreBundle\TwigExtension; +use Doctrine\ORM\NonUniqueResultException; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use RZ\Roadiz\CoreBundle\Bag\NodeTypes; use RZ\Roadiz\CoreBundle\Entity\NodesSources; +use RZ\Roadiz\CoreBundle\Entity\Tag; use RZ\Roadiz\CoreBundle\EntityApi\NodeSourceApi; use RZ\Roadiz\CoreBundle\EntityHandler\HandlerFactory; use RZ\Roadiz\CoreBundle\EntityHandler\NodesSourcesHandler; @@ -19,27 +23,12 @@ */ final class NodesSourcesExtension extends AbstractExtension { - protected NodeSourceApi $nodeSourceApi; - protected HandlerFactory $handlerFactory; - private bool $throwExceptions; - private NodeTypes $nodeTypesBag; - - /** - * @param NodeSourceApi $nodeSourceApi - * @param HandlerFactory $handlerFactory - * @param NodeTypes $nodeTypesBag - * @param bool $throwExceptions - */ public function __construct( - NodeSourceApi $nodeSourceApi, - HandlerFactory $handlerFactory, - NodeTypes $nodeTypesBag, - bool $throwExceptions = false + private readonly NodeSourceApi $nodeSourceApi, + private readonly HandlerFactory $handlerFactory, + private readonly NodeTypes $nodeTypesBag, + private readonly bool $throwExceptions = false ) { - $this->throwExceptions = $throwExceptions; - $this->handlerFactory = $handlerFactory; - $this->nodeTypesBag = $nodeTypesBag; - $this->nodeSourceApi = $nodeSourceApi; } public function getFilters(): array @@ -115,7 +104,7 @@ public function getChildren(NodesSources $ns = null, array $criteria = null, arr * @return NodesSources|null * @throws RuntimeError */ - public function getNext(NodesSources $ns = null, array $criteria = null, array $order = null) + public function getNext(NodesSources $ns = null, array $criteria = null, array $order = null): ?NodesSources { if (null === $ns) { if ($this->throwExceptions) { @@ -136,7 +125,7 @@ public function getNext(NodesSources $ns = null, array $criteria = null, array $ * @return NodesSources|null * @throws RuntimeError */ - public function getPrevious(NodesSources $ns = null, array $criteria = null, array $order = null) + public function getPrevious(NodesSources $ns = null, array $criteria = null, array $order = null): ?NodesSources { if (null === $ns) { if ($this->throwExceptions) { @@ -157,7 +146,7 @@ public function getPrevious(NodesSources $ns = null, array $criteria = null, arr * @return NodesSources|null * @throws RuntimeError */ - public function getLastSibling(NodesSources $ns = null, array $criteria = null, array $order = null) + public function getLastSibling(NodesSources $ns = null, array $criteria = null, array $order = null): ?NodesSources { if (null === $ns) { if ($this->throwExceptions) { @@ -178,7 +167,7 @@ public function getLastSibling(NodesSources $ns = null, array $criteria = null, * @return NodesSources|null * @throws RuntimeError */ - public function getFirstSibling(NodesSources $ns = null, array $criteria = null, array $order = null) + public function getFirstSibling(NodesSources $ns = null, array $criteria = null, array $order = null): ?NodesSources { if (null === $ns) { if ($this->throwExceptions) { @@ -197,7 +186,7 @@ public function getFirstSibling(NodesSources $ns = null, array $criteria = null, * @return NodesSources|null * @throws RuntimeError */ - public function getParent(NodesSources $ns = null) + public function getParent(NodesSources $ns = null): ?NodesSources { if (null === $ns) { if ($this->throwExceptions) { @@ -214,9 +203,12 @@ public function getParent(NodesSources $ns = null) * @param NodesSources|null $ns * @param array|null $criteria * @return array + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface * @throws RuntimeError + * @throws NonUniqueResultException */ - public function getParents(NodesSources $ns = null, array $criteria = null) + public function getParents(NodesSources $ns = null, array $criteria = null): array { if (null === $ns) { if ($this->throwExceptions) { @@ -232,10 +224,12 @@ public function getParents(NodesSources $ns = null, array $criteria = null) /** * @param NodesSources|null $ns - * @return array + * @return iterable * @throws RuntimeError + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ - public function getTags(NodesSources $ns = null) + public function getTags(NodesSources $ns = null): iterable { if (null === $ns) { if ($this->throwExceptions) { diff --git a/lib/RoadizCoreBundle/src/TwigExtension/RoadizExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/RoadizExtension.php index 62b7fd10..c5d4d333 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/RoadizExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/RoadizExtension.php @@ -11,35 +11,18 @@ use Twig\Extension\AbstractExtension; use Twig\Extension\GlobalsInterface; -class RoadizExtension extends AbstractExtension implements GlobalsInterface +final class RoadizExtension extends AbstractExtension implements GlobalsInterface { - protected Settings $settingsBag; - protected NodeTypes $nodeTypesBag; - protected PreviewResolverInterface $previewResolver; - protected NodeChrootResolver $chrootResolver; - protected string $cmsVersion; - protected string $cmsVersionPrefix; - protected bool $hideRoadizVersion; - protected int $maxVersionsShowed; - public function __construct( - Settings $settingsBag, - NodeTypes $nodeTypesBag, - PreviewResolverInterface $previewResolver, - NodeChrootResolver $chrootResolver, - string $cmsVersion, - string $cmsVersionPrefix, - bool $hideRoadizVersion, - int $maxVersionsShowed + private readonly Settings $settingsBag, + private readonly NodeTypes $nodeTypesBag, + private readonly PreviewResolverInterface $previewResolver, + private readonly NodeChrootResolver $chrootResolver, + private readonly string $cmsVersion, + private readonly string $cmsVersionPrefix, + private readonly bool $hideRoadizVersion, + private readonly int $maxVersionsShowed ) { - $this->settingsBag = $settingsBag; - $this->nodeTypesBag = $nodeTypesBag; - $this->previewResolver = $previewResolver; - $this->chrootResolver = $chrootResolver; - $this->cmsVersion = $cmsVersion; - $this->cmsVersionPrefix = $cmsVersionPrefix; - $this->hideRoadizVersion = $hideRoadizVersion; - $this->maxVersionsShowed = $maxVersionsShowed; } /** diff --git a/lib/RoadizCoreBundle/src/TwigExtension/RoutingExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/RoutingExtension.php index bfdd578d..f78d3dd3 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/RoutingExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/RoutingExtension.php @@ -14,21 +14,12 @@ /** * Override Symfony RoutingExtension to support object url generation. */ -class RoutingExtension extends AbstractExtension +final class RoutingExtension extends AbstractExtension { - private UrlGeneratorInterface $generator; - private \Symfony\Bridge\Twig\Extension\RoutingExtension $decorated; - - /** - * @param UrlGeneratorInterface $generator - * @param \Symfony\Bridge\Twig\Extension\RoutingExtension $decorated - */ public function __construct( - \Symfony\Bridge\Twig\Extension\RoutingExtension $decorated, - UrlGeneratorInterface $generator + private readonly \Symfony\Bridge\Twig\Extension\RoutingExtension $decorated, + private readonly UrlGeneratorInterface $generator ) { - $this->generator = $generator; - $this->decorated = $decorated; } /** @@ -49,7 +40,7 @@ public function getFunctions(): array * @return string * @throws RuntimeError */ - public function getPath($name, array $parameters = [], bool $relative = false): string + public function getPath(string|object|null $name, array $parameters = [], bool $relative = false): string { if (is_string($name)) { return $this->decorated->getPath( @@ -75,7 +66,7 @@ public function getPath($name, array $parameters = [], bool $relative = false): * @return string * @throws RuntimeError */ - public function getUrl($name, array $parameters = [], bool $schemeRelative = false): string + public function getUrl(string|object|null $name, array $parameters = [], bool $schemeRelative = false): string { if (is_string($name)) { return $this->decorated->getUrl( diff --git a/lib/RoadizCoreBundle/src/TwigExtension/TransChoiceExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/TransChoiceExtension.php index 949b0243..96c19b15 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/TransChoiceExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/TransChoiceExtension.php @@ -15,14 +15,8 @@ */ final class TransChoiceExtension extends AbstractExtension { - private TranslatorInterface $translator; - - /** - * @param TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) + public function __construct(private readonly TranslatorInterface $translator) { - $this->translator = $translator; } public function getFilters(): array diff --git a/lib/RoadizCoreBundle/src/TwigExtension/TranslationExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/TranslationExtension.php index 807a2fc7..cd248352 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/TranslationExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/TranslationExtension.php @@ -34,7 +34,7 @@ public function getTests(): array * * @return bool */ - public function isLocaleRtl($mixed) + public function isLocaleRtl(mixed $mixed): bool { if ($mixed instanceof TranslationInterface) { return $mixed->isRtl(); diff --git a/lib/RoadizCoreBundle/src/TwigExtension/TranslationMenuExtension.php b/lib/RoadizCoreBundle/src/TwigExtension/TranslationMenuExtension.php index b1fdb2fd..2c0bccd8 100644 --- a/lib/RoadizCoreBundle/src/TwigExtension/TranslationMenuExtension.php +++ b/lib/RoadizCoreBundle/src/TwigExtension/TranslationMenuExtension.php @@ -13,17 +13,10 @@ final class TranslationMenuExtension extends AbstractExtension { - private RequestStack $requestStack; - private TranslationViewer $translationViewer; - - /** - * @param RequestStack $requestStack - * @param TranslationViewer $translationViewer - */ - public function __construct(RequestStack $requestStack, TranslationViewer $translationViewer) - { - $this->requestStack = $requestStack; - $this->translationViewer = $translationViewer; + public function __construct( + private readonly RequestStack $requestStack, + private readonly TranslationViewer $translationViewer + ) { } public function getFilters(): array @@ -40,7 +33,7 @@ public function getFilters(): array * @return array * @throws ORMException */ - public function getMenuAssignation(TranslationInterface $translation = null, bool $absolute = false) + public function getMenuAssignation(TranslationInterface $translation = null, bool $absolute = false): array { if (null !== $translation) { $this->translationViewer->setTranslation($translation); diff --git a/lib/RoadizTwoFactorBundle/src/Console/DisableTwoFactorUserCommand.php b/lib/RoadizTwoFactorBundle/src/Console/DisableTwoFactorUserCommand.php index d882ee2c..51aa511e 100644 --- a/lib/RoadizTwoFactorBundle/src/Console/DisableTwoFactorUserCommand.php +++ b/lib/RoadizTwoFactorBundle/src/Console/DisableTwoFactorUserCommand.php @@ -4,10 +4,7 @@ namespace RZ\Roadiz\TwoFactorBundle\Console; -use Doctrine\Persistence\ManagerRegistry; -use RZ\Roadiz\CoreBundle\Console\UsersCommand; use RZ\Roadiz\TwoFactorBundle\Entity\TwoFactorUser; -use RZ\Roadiz\TwoFactorBundle\Security\Provider\TwoFactorUserProviderInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -20,18 +17,6 @@ )] final class DisableTwoFactorUserCommand extends UsersCommand { - private TwoFactorUserProviderInterface $twoFactorUserProvider; - - public function __construct( - ManagerRegistry $managerRegistry, - TwoFactorUserProviderInterface $twoFactorUserProvider, - string $name = null - ) { - parent::__construct($managerRegistry, $name); - $this->twoFactorUserProvider = $twoFactorUserProvider; - $this->managerRegistry = $managerRegistry; - } - protected function configure(): void { $this->addArgument( diff --git a/lib/RoadizTwoFactorBundle/src/Console/UsersCommand.php b/lib/RoadizTwoFactorBundle/src/Console/UsersCommand.php index 05dcf572..729aa16a 100644 --- a/lib/RoadizTwoFactorBundle/src/Console/UsersCommand.php +++ b/lib/RoadizTwoFactorBundle/src/Console/UsersCommand.php @@ -13,17 +13,14 @@ name: 'users:list', description: 'List all users or just one' )] -final class UsersCommand extends \RZ\Roadiz\CoreBundle\Console\UsersCommand +class UsersCommand extends \RZ\Roadiz\CoreBundle\Console\UsersCommand { - private TwoFactorUserProviderInterface $twoFactorUserProvider; - public function __construct( - TwoFactorUserProviderInterface $twoFactorUserProvider, + protected readonly TwoFactorUserProviderInterface $twoFactorUserProvider, ManagerRegistry $managerRegistry, string $name = null ) { parent::__construct($managerRegistry, $name); - $this->twoFactorUserProvider = $twoFactorUserProvider; } protected function getUserTableRow(User $user): array