diff --git a/composer.json b/composer.json index 7b74a17d6..b4313a58a 100644 --- a/composer.json +++ b/composer.json @@ -65,11 +65,11 @@ "pamil/phpspec-skip-example-extension": "^4.2", "phpspec/phpspec": "^7.5", "phpspec/prophecy-phpunit": "^2.2", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-phpunit": "^1.4", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.0", - "rector/rector": "^0.18.2", + "rector/rector": "^2.0", "sylius-labs/coding-standard": "^4.4", "sylius/grid-bundle": "^1.13", "symfony/console": "^6.4 || ^7.1", @@ -137,7 +137,8 @@ "analyse": [ "@composer validate --strict", "vendor/bin/ecs check", - "vendor/bin/phpstan analyse --ansi --memory-limit=256M -c phpstan.neon -l max src" + "vendor/bin/phpstan analyse --ansi --memory-limit=256M -c phpstan.neon -l max src", + "vendor/bin/rector process --dry-run" ], "fix": [ "vendor/bin/ecs check --fix" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..6db708769 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,847 @@ +parameters: + ignoreErrors: + - + message: '#^Parameter \#1 \$pass of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:addCompilerPass\(\) expects Symfony\\Component\\DependencyInjection\\Compiler\\CompilerPassInterface, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/AbstractResourceBundle.php + + - + message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Command/DebugResourceCommand.php + + - + message: '#^Parameter \#1 \$alias of method Sylius\\Resource\\Metadata\\RegistryInterface\:\:get\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Context/Initiator/LegacyRequestContextInitiator.php + + - + message: '#^Parameter \#1 \$className of method Sylius\\Resource\\Metadata\\RegistryInterface\:\:getByClass\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Context/Initiator/LegacyRequestContextInitiator.php + + - + message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Context/Initiator/LegacyRequestContextInitiator.php + + - + message: '#^Cannot access offset ''classes'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php + + - + message: '#^Cannot access offset ''interface'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php + + - + message: '#^Cannot access offset ''model'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php + + - + message: '#^Method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\Compiler\\Helper\\TargetEntitiesResolver\:\:getModel\(\) should return string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php + + - + message: '#^Parameter \#2 \$configuration of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\Compiler\\Helper\\TargetEntitiesResolver\:\:getModel\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php + + - + message: '#^Parameter \#3 \$attributes of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\Compiler\\PrioritizedCompositeServicePass\:\:addMethodCall\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Compiler/PrioritizedCompositeServicePass.php + + - + message: '#^Cannot access offset ''type'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterFormBuilderPass.php + + - + message: '#^Parameter \#2 \$parameters of static method Sylius\\Resource\\Metadata\\Metadata\:\:fromAliasAndConfiguration\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php + + - + message: '#^Cannot access offset ''state_machine_component'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourceStateMachinePass.php + + - + message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourceStateMachinePass.php + + - + message: '#^Cannot access offset ''classes'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php + + - + message: '#^Cannot access offset ''model'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php + + - + message: '#^PHPDoc tag @var with type array is not subtype of native type array\\|false\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php + + - + message: '#^Parameter \#1 \$class of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\Compiler\\RegisterResourcesPass\:\:validateSyliusResource\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php + + - + message: '#^Parameter \#2 \$stateMachine of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\Compiler\\RegisterStateMachinePass\:\:setStateMachine\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Compiler/RegisterStateMachinePass.php + + - + message: '#^PHPDoc tag @var with type array is not subtype of native type array\\|false\.$#' + identifier: varTag.nativeType + count: 2 + path: src/Bundle/DependencyInjection/Driver/AbstractDriver.php + + - + message: '#^Parameter \#2 \$type of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:registerAliasForArgument\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Driver/AbstractDriver.php + + - + message: '#^PHPDoc tag @var with type array is not subtype of native type array\\|false\.$#' + identifier: varTag.nativeType + count: 2 + path: src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php + + - + message: '#^Parameter \#2 \$type of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:registerAliasForArgument\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/Driver/Doctrine/DoctrineORMDriver.php + + - + message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/DependencyInjection/Extension/AbstractResourceExtension.php + + - + message: '#^Parameter \#2 \$config of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:prependExtensionConfig\(\) expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/PagerfantaExtension.php + + - + message: '#^Parameter \#2 \$value of method Symfony\\Component\\DependencyInjection\\Container\:\:setParameter\(\) expects array\|bool\|float\|int\|string\|UnitEnum\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/PagerfantaExtension.php + + - + message: '#^Cannot access offset ''driver'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Cannot access offset ''enabled'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Cannot access offset ''locale_provider'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Cannot access offset ''translation'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#1 \$configuredDrivers of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\SyliusResourceExtension\:\:checkConfiguredDrivers\(\) expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#1 \$drivers of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\SyliusResourceExtension\:\:loadPersistence\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#1 \$haystack of function str_starts_with expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#1 \$loadedResources of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\SyliusResourceExtension\:\:loadResources\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#1 \$paths of static method Sylius\\Resource\\Reflection\\ClassReflection\:\:getResourcesByPaths\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$availableDrivers of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\SyliusResourceExtension\:\:checkConfiguredDrivers\(\) expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(bool, mixed\)\: bool, Closure\(bool, string\)\: bool given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$id of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:setAlias\(\) expects string\|Symfony\\Component\\DependencyInjection\\Alias, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$parameters of static method Sylius\\Resource\\Metadata\\Metadata\:\:fromAliasAndConfiguration\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$resources of method Sylius\\Bundle\\ResourceBundle\\DependencyInjection\\SyliusResourceExtension\:\:loadPersistence\(\) expects array\, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$value of method Symfony\\Component\\DependencyInjection\\Container\:\:setParameter\(\) expects array\|bool\|float\|int\|string\|UnitEnum\|null, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/DependencyInjection/SyliusResourceExtension.php + + - + message: '#^Parameter \#2 \$order of method Doctrine\\ORM\\QueryBuilder\:\:addOrderBy\(\) expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Doctrine/ORM/EntityRepository.php + + - + message: '#^Parameter \#1 \$className of method Doctrine\\ORM\\EntityManagerInterface\:\:getClassMetadata\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php + + - + message: '#^PHPDoc tag @var with type class\-string\\|null is not subtype of native type string\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Bundle/EventListener/ORMRepositoryClassSubscriber.php + + - + message: '#^Cannot access offset ''columns'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Bundle/EventListener/ORMTranslatableListener.php + + - + message: '#^Parameter \#1 \$array of function array_diff expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/EventListener/ORMTranslatableListener.php + + - + message: '#^PHPDoc tag @var with type Psr\\Cache\\CacheItemPoolInterface is not subtype of native type Symfony\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheAdapter\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Bundle/ExpressionLanguage/ExpressionLanguage.php + + - + message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php + + - + message: '#^Cannot access offset string on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 3 + path: src/Bundle/Form/Registry/FormTypeRegistry.php + + - + message: '#^Method Sylius\\Bundle\\ResourceBundle\\Form\\Registry\\FormTypeRegistry\:\:get\(\) should return string\|null but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Bundle/Form/Registry/FormTypeRegistry.php + + - + message: '#^Binary operation "\." between ''\['' and mixed results in an error\.$#' + identifier: binaryOp.invalid + count: 1 + path: src/Bundle/Form/Type/FixedCollectionType.php + + - + message: '#^Parameter \#1 \$child of method Symfony\\Component\\Form\\FormBuilderInterface\:\:add\(\) expects string\|Symfony\\Component\\Form\\FormBuilderInterface, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Form/Type/FixedCollectionType.php + + - + message: '#^Parameter \#2 \$type of method Symfony\\Component\\Form\\FormBuilderInterface\:\:add\(\) expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Form/Type/FixedCollectionType.php + + - + message: '#^Parameter \#2 \.\.\.\$replacements of function array_replace expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Form/Type/FixedCollectionType.php + + - + message: '#^Parameter \#1 \$parameters of class Sylius\\Component\\Grid\\Parameters constructor expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Grid/Controller/ResourcesResolver.php + + - + message: '#^Parameter \#2 \$callback of function preg_replace_callback expects callable\(array\\)\: string, Closure\(array\)\: mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Grid/Parser/OptionsParser.php + + - + message: '#^Parameter \#1 \$name of method Twig\\Environment\:\:render\(\) expects string\|Twig\\TemplateWrapper, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Grid/Renderer/TwigBulkActionGridRenderer.php + + - + message: '#^Parameter \#1 \$name of method Twig\\Environment\:\:render\(\) expects string\|Twig\\TemplateWrapper, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Grid/Renderer/TwigGridRenderer.php + + - + message: '#^Parameter \#1 \$paths of static method Sylius\\Resource\\Reflection\\ClassReflection\:\:getResourcesByPaths\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/CrudRoutesAttributesLoader.php + + - + message: '#^Parameter \#1 \$name of method Symfony\\Component\\Routing\\RouteCollection\:\:add\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#1 \$path of class Symfony\\Component\\Routing\\Route constructor expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#3 \$priority of method Symfony\\Component\\Routing\\RouteCollection\:\:add\(\) expects int, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#3 \$requirements of class Symfony\\Component\\Routing\\Route constructor expects array\, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#4 \$options of class Symfony\\Component\\Routing\\Route constructor expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#5 \$host of class Symfony\\Component\\Routing\\Route constructor expects string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#6 \$schemes of class Symfony\\Component\\Routing\\Route constructor expects array\\|string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#7 \$methods of class Symfony\\Component\\Routing\\Route constructor expects array\\|string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteAttributesFactory.php + + - + message: '#^Parameter \#3 \$requirements of class Symfony\\Component\\Routing\\Route constructor expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteFactory.php + + - + message: '#^Parameter \#6 \$schemes of class Symfony\\Component\\Routing\\Route constructor expects array\\|string, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteFactory.php + + - + message: '#^Parameter \#7 \$methods of class Symfony\\Component\\Routing\\Route constructor expects array\\|string, array given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RouteFactory.php + + - + message: '#^Parameter \#1 \$paths of static method Sylius\\Resource\\Reflection\\ClassReflection\:\:getResourcesByPaths\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Bundle/Routing/RoutesAttributesLoader.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:nullOrString\(\) with string\|null will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Bundle/Storage/CookieStorage.php + + - + message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Bundle/Validator/UniqueWithinCollectionConstraintValidator.php + + - + message: '#^Method Sylius\\Resource\\Context\\Context\:\:get\(\) never returns null so it can be removed from the return type\.$#' + identifier: return.unusedType + count: 1 + path: src/Component/src/Context/Context.php + + - + message: '#^Call to function method_exists\(\) with Doctrine\\ORM\\Mapping\\ClassMetadata and ''isChangeTrackingDef…'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Component/src/Doctrine/Common/State/PersistProcessor.php + + - + message: '#^PHPDoc tag @var with type array is not subtype of native type array\\|false\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Component/src/Doctrine/Persistence/InMemoryRepository.php + + - + message: '#^Parameter \#2 \$offset of function array_slice expects int, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Doctrine/Persistence/InMemoryRepository.php + + - + message: '#^Parameter \#3 \$length of function array_slice expects int\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Doctrine/Persistence/InMemoryRepository.php + + - + message: '#^Deprecated in PHP 8\.4\: Parameter \#2 \$previous \(Exception\) is implicitly nullable via default value null\.$#' + identifier: parameter.implicitlyNullable + count: 1 + path: src/Component/src/Exception/StorageUnavailableException.php + + - + message: '#^Method Sylius\\Resource\\Grid\\State\\RequestGridProvider\:\:provide\(\) never returns array so it can be removed from the return type\.$#' + identifier: return.unusedType + count: 1 + path: src/Component/src/Grid/State/RequestGridProvider.php + + - + message: '#^Method Sylius\\Resource\\Grid\\State\\RequestGridProvider\:\:resolveMaxPerPage\(\) should return int but returns mixed\.$#' + identifier: return.type + count: 2 + path: src/Component/src/Grid/State/RequestGridProvider.php + + - + message: '#^Parameter \#1 \$parameters of class Sylius\\Component\\Grid\\Parameters constructor expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Grid/State/RequestGridProvider.php + + - + message: '#^Cannot access offset string on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 2 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Method Sylius\\Resource\\Metadata\\Metadata\:\:getClass\(\) should return class\-string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Method Sylius\\Resource\\Metadata\\Metadata\:\:getDriver\(\) never returns false so it can be removed from the return type\.$#' + identifier: return.unusedType + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Method Sylius\\Resource\\Metadata\\Metadata\:\:getParameter\(\) should return array\|string but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Method Sylius\\Resource\\Metadata\\Metadata\:\:getTemplatesNamespace\(\) never returns null so it can be removed from the return type\.$#' + identifier: return.unusedType + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Parameter \#1 \$name of class Sylius\\Resource\\Metadata\\Metadata constructor expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Parameter \#2 \$applicationName of class Sylius\\Resource\\Metadata\\Metadata constructor expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Property Sylius\\Resource\\Metadata\\Metadata\:\:\$driver \(string\) does not accept mixed\.$#' + identifier: assign.propertyType + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Property Sylius\\Resource\\Metadata\\Metadata\:\:\$stateMachineComponent \(string\|null\) does not accept mixed\.$#' + identifier: assign.propertyType + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Property Sylius\\Resource\\Metadata\\Metadata\:\:\$templatesNamespace \(string\) does not accept mixed\.$#' + identifier: assign.propertyType + count: 1 + path: src/Component/src/Metadata/Metadata.php + + - + message: '#^Parameter \#1 \$alias of method Sylius\\Resource\\Metadata\\RegistryInterface\:\:get\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Operation/HttpOperationInitiator.php + + - + message: '#^Parameter \#1 \$className of method Sylius\\Resource\\Metadata\\RegistryInterface\:\:getByClass\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Operation/HttpOperationInitiator.php + + - + message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Operation/HttpOperationInitiator.php + + - + message: '#^Method Sylius\\Resource\\Metadata\\Operations\:\:get\(\) should return Sylius\\Resource\\Metadata\\Operation but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Metadata/Operations.php + + - + message: '#^Parameter \#1 \$key of method Sylius\\Resource\\Metadata\\Operations\:\:add\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php + + - + message: '#^Parameter \#1 \$operations of class Sylius\\Resource\\Metadata\\Operations constructor expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php + + - + message: '#^Parameter \#2 \$value of method Sylius\\Resource\\Metadata\\Operations\:\:add\(\) expects Sylius\\Resource\\Metadata\\Operation, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Resource/Factory/AttributesResourceMetadataCollectionFactory.php + + - + message: '#^Parameter \#1 \$array of class Sylius\\Resource\\Metadata\\Resource\\ResourceMetadataCollection constructor expects array\\|object, mixed given\.$#' + identifier: argument.type + count: 2 + path: src/Component/src/Metadata/Resource/Factory/CachedResourceMetadataCollectionFactory.php + + - + message: '#^Call to function method_exists\(\) with Sylius\\Resource\\Metadata\\MetadataInterface and ''getStateMachineComp…'' will always evaluate to true\.$#' + identifier: function.alreadyNarrowedType + count: 1 + path: src/Component/src/Metadata/Resource/Factory/StateMachineResourceMetadataCollectionFactory.php + + - + message: '#^PHPDoc tag @var with type Sylius\\Resource\\Metadata\\Operation is not subtype of native type Sylius\\Resource\\Metadata\\StateMachineAwareOperationInterface\.$#' + identifier: varTag.nativeType + count: 1 + path: src/Component/src/Metadata/Resource/Factory/StateMachineResourceMetadataCollectionFactory.php + + - + message: '#^Parameter \#2 \.\.\.\$values of function sprintf expects bool\|float\|int\|string\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/Resource/Factory/TemplatesDirResourceMetadataCollectionFactory.php + + - + message: '#^Parameter \#1 \$operations of class Sylius\\Resource\\Metadata\\Operations constructor expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Metadata/ResourceMetadata.php + + - + message: '#^Trait Sylius\\Resource\\Model\\ArchivableTrait is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: src/Component/src/Model/ArchivableTrait.php + + - + message: '#^Trait Sylius\\Resource\\Model\\TimestampableTrait is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: src/Component/src/Model/TimestampableTrait.php + + - + message: '#^Trait Sylius\\Resource\\Model\\ToggleableTrait is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: src/Component/src/Model/ToggleableTrait.php + + - + message: '#^Trait Sylius\\Resource\\Model\\TranslatableTrait is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: src/Component/src/Model/TranslatableTrait.php + + - + message: '#^Parameter \#1 \$objectOrMethod of class ReflectionMethod constructor expects object\|string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Reflection/CallableReflection.php + + - + message: '#^Parameter \#2 \$method of class ReflectionMethod constructor expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Reflection/CallableReflection.php + + - + message: '#^Generator expects value type class\-string, mixed given\.$#' + identifier: generator.valueType + count: 1 + path: src/Component/src/Reflection/ClassReflection.php + + - + message: '#^Parameter \#1 \$path of static method Sylius\\Resource\\Reflection\\ClassReflection\:\:getResourcesByPath\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Reflection/ClassReflection.php + + - + message: '#^Method Sylius\\Resource\\State\\Factory\:\:create\(\) should return object\|null but returns mixed\.$#' + identifier: return.type + count: 2 + path: src/Component/src/State/Factory.php + + - + message: '#^Parameter \#1 \$expression of method Sylius\\Resource\\Symfony\\ExpressionLanguage\\ArgumentParserInterface\:\:parseExpression\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/State/Factory.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\Resource\\State\\ProcessorInterface and ''Sylius\\\\Resource\\\\State\\\\ProcessorInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Component/src/State/Processor.php + + - + message: '#^Method Sylius\\Resource\\State\\Provider\:\:provide\(\) should return array\|object\|null but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/State/Provider.php + + - + message: '#^Cannot access offset ''from'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Cannot access offset ''to'' on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 1 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Cannot access offset mixed on mixed\.$#' + identifier: offsetAccess.nonOffsetAccessible + count: 2 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Method Sylius\\Resource\\StateMachine\\StateMachine\:\:getTransitionFromState\(\) should return string\|null but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Method Sylius\\Resource\\StateMachine\\StateMachine\:\:getTransitionToState\(\) should return string\|null but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Parameter \#2 \$haystack of function in_array expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/StateMachine/StateMachine.php + + - + message: '#^Strict comparison using \!\=\= between null and Symfony\\Component\\HttpFoundation\\Request will always evaluate to true\.$#' + identifier: notIdentical.alwaysTrue + count: 1 + path: src/Component/src/Symfony/EventDispatcher/OperationEventHandler.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:allIsInstanceOf\(\) with iterable\ and ''Sylius\\\\Resource\\\\Symfony\\\\ExpressionLanguage\\\\VariablesInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Component/src/Symfony/ExpressionLanguage/VariablesCollection.php + + - + message: '#^Parameter \#1 \$arguments of method Sylius\\Resource\\Symfony\\Request\\RepositoryArgumentResolver\:\:filterPrivateArguments\(\) expects array\, array given\.$#' + identifier: argument.type + count: 2 + path: src/Component/src/Symfony/Request/RepositoryArgumentResolver.php + + - + message: '#^Method Sylius\\Resource\\Symfony\\Request\\State\\Provider\:\:provide\(\) should return array\|object\|null but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Symfony/Request/State/Provider.php + + - + message: '#^Parameter \#1 \$expression of method Sylius\\Resource\\Symfony\\ExpressionLanguage\\ArgumentParserInterface\:\:parseExpression\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Request/State/Provider.php + + - + message: '#^Parameter \$methods of class Symfony\\Component\\Routing\\Route constructor expects array\\|string, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Routing/Factory/OperationRouteFactory.php + + - + message: '#^Parameter \#1 \$expression of method Sylius\\Resource\\Symfony\\ExpressionLanguage\\ArgumentParserInterface\:\:parseExpression\(\) expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Routing/RedirectHandler.php + + - + message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Routing/RedirectHandler.php + + - + message: '#^Parameter \#1 \$string of function substr expects string, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Routing/RedirectHandler.php + + - + message: '#^Parameter \#4 \$context of method Symfony\\Component\\Serializer\\SerializerInterface\:\:deserialize\(\) expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Serializer/State/DeserializeProvider.php + + - + message: '#^Parameter \#3 \$context of method Symfony\\Component\\Serializer\\SerializerInterface\:\:serialize\(\) expects array\, array given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Serializer/State/SerializeProcessor.php + + - + message: '#^Deprecated in PHP 8\.4\: Parameter \#4 \$previous \(Exception\) is implicitly nullable via default value null\.$#' + identifier: parameter.implicitlyNullable + count: 1 + path: src/Component/src/Symfony/Validator/Exception/ValidationException.php + + - + message: '#^Parameter \$groups of method Symfony\\Component\\Validator\\Validator\\ValidatorInterface\:\:validate\(\) expects array\\|string\|Symfony\\Component\\Validator\\Constraints\\GroupSequence\|null, mixed given\.$#' + identifier: argument.type + count: 1 + path: src/Component/src/Symfony/Validator/State/ValidateProvider.php + + - + message: '#^Method Sylius\\Resource\\Translation\\Provider\\ImmutableTranslationLocaleProvider\:\:getDefinedLocalesCodes\(\) should return array\ but returns array\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Translation/Provider/ImmutableTranslationLocaleProvider.php + + - + message: '#^Call to static method Webmozart\\Assert\\Assert\:\:isInstanceOf\(\) with Sylius\\Resource\\Twig\\Context\\Factory\\ContextFactoryInterface and ''Sylius\\\\Resource\\\\Twig\\\\Context\\\\Factory\\\\ContextFactoryInterface'' will always evaluate to true\.$#' + identifier: staticMethod.alreadyNarrowedType + count: 1 + path: src/Component/src/Twig/Context/Factory/ContextFactory.php + + - + message: '#^Method Sylius\\Resource\\Twig\\Context\\Factory\\ContextFactory\:\:create\(\) should return array but returns mixed\.$#' + identifier: return.type + count: 1 + path: src/Component/src/Twig/Context/Factory/ContextFactory.php diff --git a/phpstan.neon b/phpstan.neon index e73d8ed81..079866e60 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,6 +3,7 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon + - phpstan-baseline.neon parameters: reportUnmatchedIgnoredErrors: false diff --git a/rector.php b/rector.php index 6566b71df..80dbaef08 100644 --- a/rector.php +++ b/rector.php @@ -2,17 +2,14 @@ declare(strict_types=1); -use Rector\Core\Configuration\Option; -use Rector\Php74\Rector\Property\TypedPropertyRector; -use Rector\Set\ValueObject\SetList; -use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; - -return static function (ContainerConfigurator $containerConfigurator): void -{ - $parameters = $containerConfigurator->parameters(); - $parameters->set(Option::AUTO_IMPORT_NAMES, true); - $parameters->set(Option::IMPORT_SHORT_CLASSES, false); - - $services = $containerConfigurator->services(); - $services->set(TypedPropertyRector::class); -}; +use Rector\Config\RectorConfig; + +return RectorConfig::configure() + ->withPaths([ + __DIR__ . '/src' + ]) + ->withSkipPath('src/Bundle/spec') + ->withSkipPath('src/Component/legacy/spec') + ->withSkipPath('src/Component/spec') + ->withPhpSets(php80: true) +; diff --git a/src/Bundle/AbstractResourceBundle.php b/src/Bundle/AbstractResourceBundle.php index 1445ebb72..15a52f7da 100644 --- a/src/Bundle/AbstractResourceBundle.php +++ b/src/Bundle/AbstractResourceBundle.php @@ -94,7 +94,7 @@ protected function getModelNamespace(): ?string /** * Return mapping compiler pass class depending on driver. * - * + * @return string[] * * @throws UnknownDriverException */ diff --git a/src/Bundle/Controller/ControllerTrait.php b/src/Bundle/Controller/ControllerTrait.php index 0076a8e7d..552e80d8a 100644 --- a/src/Bundle/Controller/ControllerTrait.php +++ b/src/Bundle/Controller/ControllerTrait.php @@ -146,7 +146,7 @@ protected function json($data, int $status = 200, array $headers = [], array $co protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse { $response = new BinaryFileResponse($file); - $response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName); + $response->setContentDisposition($disposition, $fileName ?? $response->getFile()->getFilename()); return $response; } diff --git a/src/Bundle/Controller/EventDispatcher.php b/src/Bundle/Controller/EventDispatcher.php index 62ab1ee23..5a6d32b52 100644 --- a/src/Bundle/Controller/EventDispatcher.php +++ b/src/Bundle/Controller/EventDispatcher.php @@ -19,11 +19,8 @@ final class EventDispatcher implements EventDispatcherInterface { - private SymfonyEventDispatcherInterface $eventDispatcher; - - public function __construct(SymfonyEventDispatcherInterface $eventDispatcher) + public function __construct(private SymfonyEventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; } public function dispatch( diff --git a/src/Bundle/Controller/FlashHelper.php b/src/Bundle/Controller/FlashHelper.php index e65951470..3eb96de2a 100644 --- a/src/Bundle/Controller/FlashHelper.php +++ b/src/Bundle/Controller/FlashHelper.php @@ -27,14 +27,10 @@ final class FlashHelper implements FlashHelperInterface /** @var RequestStack|SessionInterface */ private $requestStack; - private TranslatorInterface $translator; - - private string $defaultLocale; - /** * @param RequestStack|SessionInterface $requestStack */ - public function __construct(/* RequestStack */ $requestStack, TranslatorInterface $translator, string $defaultLocale) + public function __construct(/* RequestStack */ $requestStack, private TranslatorInterface $translator, private string $defaultLocale) { /** @phpstan-ignore-next-line */ if (!$requestStack instanceof SessionInterface && !$requestStack instanceof RequestStack) { @@ -53,8 +49,6 @@ public function __construct(/* RequestStack */ $requestStack, TranslatorInterfac } $this->requestStack = $requestStack; - $this->translator = $translator; - $this->defaultLocale = $defaultLocale; } public function addSuccessFlash( diff --git a/src/Bundle/Controller/ParametersParser.php b/src/Bundle/Controller/ParametersParser.php index da70e37b0..125a508d1 100644 --- a/src/Bundle/Controller/ParametersParser.php +++ b/src/Bundle/Controller/ParametersParser.php @@ -21,14 +21,8 @@ final class ParametersParser implements ParametersParserInterface { - private ContainerInterface $container; - - private ExpressionLanguage $expression; - - public function __construct(ContainerInterface $container, ExpressionLanguage $expression) + public function __construct(private ContainerInterface $container, private ExpressionLanguage $expression) { - $this->container = $container; - $this->expression = $expression; } public function parseRequestValues(array $parameters, Request $request): array @@ -61,15 +55,15 @@ private function parseRequestValue($parameter, Request $request) return $parameter; } - if (0 === strpos($parameter, '$')) { + if (str_starts_with($parameter, '$')) { return RequestParameterProvider::provide($request, substr($parameter, 1)); } - if (0 === strpos($parameter, 'expr:')) { + if (str_starts_with($parameter, 'expr:')) { return $this->parseRequestValueExpression(substr($parameter, 5), $request); } - if (0 === strpos($parameter, '!!')) { + if (str_starts_with($parameter, '!!')) { return $this->parseRequestValueTypecast($parameter, $request); } diff --git a/src/Bundle/Controller/RedirectHandler.php b/src/Bundle/Controller/RedirectHandler.php index 028d489af..e76af84c9 100644 --- a/src/Bundle/Controller/RedirectHandler.php +++ b/src/Bundle/Controller/RedirectHandler.php @@ -22,11 +22,8 @@ final class RedirectHandler implements RedirectHandlerInterface { - private RouterInterface $router; - - public function __construct(RouterInterface $router) + public function __construct(private RouterInterface $router) { - $this->router = $router; } public function redirectToResource(RequestConfiguration $configuration, ResourceInterface $resource): Response @@ -37,7 +34,7 @@ public function redirectToResource(RequestConfiguration $configuration, Resource (string) $configuration->getRedirectRoute(ResourceActions::SHOW), $configuration->getRedirectParameters($resource), ); - } catch (RouteNotFoundException $exception) { + } catch (RouteNotFoundException) { return $this->redirectToRoute( $configuration, (string) $configuration->getRedirectRoute(ResourceActions::INDEX), diff --git a/src/Bundle/Controller/RequestConfiguration.php b/src/Bundle/Controller/RequestConfiguration.php index 23201d2be..e749651f2 100644 --- a/src/Bundle/Controller/RequestConfiguration.php +++ b/src/Bundle/Controller/RequestConfiguration.php @@ -20,17 +20,8 @@ class RequestConfiguration { - private Request $request; - - private MetadataInterface $metadata; - - private Parameters $parameters; - - public function __construct(MetadataInterface $metadata, Request $request, Parameters $parameters) + public function __construct(private MetadataInterface $metadata, private Request $request, private Parameters $parameters) { - $this->metadata = $metadata; - $this->request = $request; - $this->parameters = $parameters; } /** @@ -82,7 +73,7 @@ public function getDefaultTemplate($name) { $templatesNamespace = (string) $this->metadata->getTemplatesNamespace(); - if (false !== strpos($templatesNamespace, ':')) { + if (str_contains($templatesNamespace, ':')) { return sprintf('%s:%s.%s', $templatesNamespace ?: ':', $name, 'twig'); } @@ -128,11 +119,8 @@ public function getFormType() public function getFormOptions() { $form = $this->parameters->get('form'); - if (isset($form['options'])) { - return $form['options']; - } - return []; + return $form['options'] ?? []; } /** @@ -541,7 +529,7 @@ private function parseResourceValues(array $parameters, $resource): array $parameters[$key] = $this->parseResourceValues($value, $resource); } - if (is_string($value) && 0 === strpos($value, 'resource.')) { + if (is_string($value) && str_starts_with($value, 'resource.')) { $parameters[$key] = $accessor->getValue($resource, substr($value, 9)); } } diff --git a/src/Bundle/Controller/RequestConfigurationFactory.php b/src/Bundle/Controller/RequestConfigurationFactory.php index 09cc1129d..9f00409ec 100644 --- a/src/Bundle/Controller/RequestConfigurationFactory.php +++ b/src/Bundle/Controller/RequestConfigurationFactory.php @@ -26,24 +26,17 @@ final class RequestConfigurationFactory implements RequestConfigurationFactoryIn private const API_GROUPS_REGEXP = '/(g|groups)=(?P[a-z,_\s]+)/i'; - private ParametersParserInterface $parametersParser; - - /** - * @var string - * @psalm-var class-string - */ - private $configurationClass; - - private array $defaultParameters; - /** * @psalm-param class-string $configurationClass */ - public function __construct(ParametersParserInterface $parametersParser, string $configurationClass, array $defaultParameters = []) - { - $this->parametersParser = $parametersParser; - $this->configurationClass = $configurationClass; - $this->defaultParameters = $defaultParameters; + public function __construct( + private ParametersParserInterface $parametersParser, + /** + * @psalm-param class-string + */ + private string $configurationClass, + private array $defaultParameters = [], + ) { } public function create(MetadataInterface $metadata, Request $request): RequestConfiguration diff --git a/src/Bundle/Controller/ResourceController.php b/src/Bundle/Controller/ResourceController.php index defd989de..92cde4154 100644 --- a/src/Bundle/Controller/ResourceController.php +++ b/src/Bundle/Controller/ResourceController.php @@ -36,76 +36,25 @@ class ResourceController use ControllerTrait; use ContainerAwareTrait; - protected MetadataInterface $metadata; - - protected RequestConfigurationFactoryInterface $requestConfigurationFactory; - - protected ?ViewHandlerInterface $viewHandler; - - protected RepositoryInterface $repository; - - protected FactoryInterface $factory; - - protected NewResourceFactoryInterface $newResourceFactory; - - protected ObjectManager $manager; - - protected SingleResourceProviderInterface $singleResourceProvider; - - protected ResourcesCollectionProviderInterface $resourcesCollectionProvider; - - protected ResourceFormFactoryInterface $resourceFormFactory; - - protected RedirectHandlerInterface $redirectHandler; - - protected FlashHelperInterface $flashHelper; - - protected AuthorizationCheckerInterface $authorizationChecker; - - protected EventDispatcherInterface $eventDispatcher; - - protected ?StateMachineInterface $stateMachine; - - protected ResourceUpdateHandlerInterface $resourceUpdateHandler; - - protected ResourceDeleteHandlerInterface $resourceDeleteHandler; - public function __construct( - MetadataInterface $metadata, - RequestConfigurationFactoryInterface $requestConfigurationFactory, - ?ViewHandlerInterface $viewHandler, - RepositoryInterface $repository, - FactoryInterface $factory, - NewResourceFactoryInterface $newResourceFactory, - ObjectManager $manager, - SingleResourceProviderInterface $singleResourceProvider, - ResourcesCollectionProviderInterface $resourcesFinder, - ResourceFormFactoryInterface $resourceFormFactory, - RedirectHandlerInterface $redirectHandler, - FlashHelperInterface $flashHelper, - AuthorizationCheckerInterface $authorizationChecker, - EventDispatcherInterface $eventDispatcher, - ?StateMachineInterface $stateMachine, - ResourceUpdateHandlerInterface $resourceUpdateHandler, - ResourceDeleteHandlerInterface $resourceDeleteHandler, + protected MetadataInterface $metadata, + protected RequestConfigurationFactoryInterface $requestConfigurationFactory, + protected ?ViewHandlerInterface $viewHandler, + protected RepositoryInterface $repository, + protected FactoryInterface $factory, + protected NewResourceFactoryInterface $newResourceFactory, + protected ObjectManager $manager, + protected SingleResourceProviderInterface $singleResourceProvider, + protected ResourcesCollectionProviderInterface $resourcesCollectionProvider, + protected ResourceFormFactoryInterface $resourceFormFactory, + protected RedirectHandlerInterface $redirectHandler, + protected FlashHelperInterface $flashHelper, + protected AuthorizationCheckerInterface $authorizationChecker, + protected EventDispatcherInterface $eventDispatcher, + protected ?StateMachineInterface $stateMachine, + protected ResourceUpdateHandlerInterface $resourceUpdateHandler, + protected ResourceDeleteHandlerInterface $resourceDeleteHandler, ) { - $this->metadata = $metadata; - $this->requestConfigurationFactory = $requestConfigurationFactory; - $this->viewHandler = $viewHandler; - $this->repository = $repository; - $this->factory = $factory; - $this->newResourceFactory = $newResourceFactory; - $this->manager = $manager; - $this->singleResourceProvider = $singleResourceProvider; - $this->resourcesCollectionProvider = $resourcesFinder; - $this->resourceFormFactory = $resourceFormFactory; - $this->redirectHandler = $redirectHandler; - $this->flashHelper = $flashHelper; - $this->authorizationChecker = $authorizationChecker; - $this->eventDispatcher = $eventDispatcher; - $this->stateMachine = $stateMachine; - $this->resourceUpdateHandler = $resourceUpdateHandler; - $this->resourceDeleteHandler = $resourceDeleteHandler; } public function showAction(Request $request): Response diff --git a/src/Bundle/Controller/ResourceFormFactory.php b/src/Bundle/Controller/ResourceFormFactory.php index be8088401..8f41024be 100644 --- a/src/Bundle/Controller/ResourceFormFactory.php +++ b/src/Bundle/Controller/ResourceFormFactory.php @@ -19,11 +19,8 @@ final class ResourceFormFactory implements ResourceFormFactoryInterface { - private FormFactoryInterface $formFactory; - - public function __construct(FormFactoryInterface $formFactory) + public function __construct(private FormFactoryInterface $formFactory) { - $this->formFactory = $formFactory; } public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource): FormInterface diff --git a/src/Bundle/Controller/ResourceUpdateHandler.php b/src/Bundle/Controller/ResourceUpdateHandler.php index f041183bc..f0501ca91 100644 --- a/src/Bundle/Controller/ResourceUpdateHandler.php +++ b/src/Bundle/Controller/ResourceUpdateHandler.php @@ -18,11 +18,8 @@ final class ResourceUpdateHandler implements ResourceUpdateHandlerInterface { - private ?StateMachineInterface $stateMachine; - - public function __construct(?StateMachineInterface $stateMachine) + public function __construct(private ?StateMachineInterface $stateMachine) { - $this->stateMachine = $stateMachine; } public function handle( diff --git a/src/Bundle/Controller/StateMachine.php b/src/Bundle/Controller/StateMachine.php index 056592c5b..941352c03 100644 --- a/src/Bundle/Controller/StateMachine.php +++ b/src/Bundle/Controller/StateMachine.php @@ -18,11 +18,8 @@ final class StateMachine implements StateMachineInterface { - private FactoryInterface $stateMachineFactory; - - public function __construct(FactoryInterface $stateMachineFactory) + public function __construct(private FactoryInterface $stateMachineFactory) { - $this->stateMachineFactory = $stateMachineFactory; } public function can(RequestConfiguration $configuration, ResourceInterface $resource): bool diff --git a/src/Bundle/Controller/Workflow.php b/src/Bundle/Controller/Workflow.php index 0fb33534b..9305b4b71 100644 --- a/src/Bundle/Controller/Workflow.php +++ b/src/Bundle/Controller/Workflow.php @@ -19,12 +19,8 @@ final class Workflow implements StateMachineInterface { - /** @var Registry */ - private $registry; - - public function __construct(Registry $registry) + public function __construct(private Registry $registry) { - $this->registry = $registry; } /** diff --git a/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php b/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php index e32495160..b76948dea 100644 --- a/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php +++ b/src/Bundle/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php @@ -24,11 +24,8 @@ */ final class DoctrineTargetEntitiesResolverPass implements CompilerPassInterface { - private TargetEntitiesResolverInterface $targetEntitiesResolver; - - public function __construct(TargetEntitiesResolverInterface $targetEntitiesResolver) + public function __construct(private TargetEntitiesResolverInterface $targetEntitiesResolver) { - $this->targetEntitiesResolver = $targetEntitiesResolver; } public function process(ContainerBuilder $container): void @@ -37,7 +34,7 @@ public function process(ContainerBuilder $container): void /** @var array $resources */ $resources = $container->getParameter('sylius.resources'); $resolveTargetEntityListener = $container->findDefinition('doctrine.orm.listeners.resolve_target_entity'); - } catch (InvalidArgumentException $exception) { + } catch (InvalidArgumentException) { return; } diff --git a/src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php b/src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php index b115680c7..b4da2798a 100644 --- a/src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php +++ b/src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php @@ -39,13 +39,9 @@ public function resolve(array $resourcesConfiguration): array } } - $interfaces = array_filter($interfaces, static function (array $classes): bool { - return count($classes) === 1; - }); + $interfaces = array_filter($interfaces, static fn (array $classes): bool => count($classes) === 1); - $interfaces = array_map(static function (array $classes): string { - return current($classes); - }, $interfaces); + $interfaces = array_map(static fn (array $classes): string => current($classes), $interfaces); foreach ($resourcesConfiguration as $alias => $configuration) { if (isset($configuration['classes']['interface'])) { diff --git a/src/Bundle/DependencyInjection/Compiler/PrioritizedCompositeServicePass.php b/src/Bundle/DependencyInjection/Compiler/PrioritizedCompositeServicePass.php index 7987f2b94..7645c6eb9 100644 --- a/src/Bundle/DependencyInjection/Compiler/PrioritizedCompositeServicePass.php +++ b/src/Bundle/DependencyInjection/Compiler/PrioritizedCompositeServicePass.php @@ -20,20 +20,12 @@ abstract class PrioritizedCompositeServicePass implements CompilerPassInterface { - private string $serviceId; - - private string $compositeId; - - private string $tagName; - - private string $methodName; - - public function __construct(string $serviceId, string $compositeId, string $tagName, string $methodName) - { - $this->serviceId = $serviceId; - $this->compositeId = $compositeId; - $this->tagName = $tagName; - $this->methodName = $methodName; + public function __construct( + private string $serviceId, + private string $compositeId, + private string $tagName, + private string $methodName, + ) { } public function process(ContainerBuilder $container): void diff --git a/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php b/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php index ec4211bb6..83ffab3b8 100644 --- a/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php +++ b/src/Bundle/DependencyInjection/Compiler/RegisterFqcnControllersPass.php @@ -28,7 +28,7 @@ public function process(ContainerBuilder $container): void try { /** @var array $resources */ $resources = $container->getParameter('sylius.resources'); - } catch (InvalidArgumentException $exception) { + } catch (InvalidArgumentException) { return; } diff --git a/src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php b/src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php index 6ba244ff9..b44ab3827 100644 --- a/src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php +++ b/src/Bundle/DependencyInjection/Compiler/RegisterResourcesPass.php @@ -26,7 +26,7 @@ public function process(ContainerBuilder $container): void /** @var array $resources */ $resources = $container->getParameter('sylius.resources'); $registry = $container->findDefinition('sylius.resource_registry'); - } catch (InvalidArgumentException $exception) { + } catch (InvalidArgumentException) { return; } diff --git a/src/Bundle/DependencyInjection/Driver/DriverProvider.php b/src/Bundle/DependencyInjection/Driver/DriverProvider.php index 74c2084ba..493b9e5b4 100644 --- a/src/Bundle/DependencyInjection/Driver/DriverProvider.php +++ b/src/Bundle/DependencyInjection/Driver/DriverProvider.php @@ -39,15 +39,11 @@ public static function get(MetadataInterface $metadata): DriverInterface Assert::notFalse($type, sprintf('No driver was configured on the resource "%s".', $metadata->getAlias())); - switch ($type) { - case SyliusResourceBundle::DRIVER_DOCTRINE_ORM: - return self::$drivers[$type] = new DoctrineORMDriver(); - case SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM: - return self::$drivers[$type] = new DoctrineODMDriver(); - case SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM: - return self::$drivers[$type] = new DoctrinePHPCRDriver(); - } - - throw new UnknownDriverException($type); + return self::$drivers[$type] = match ($type) { + SyliusResourceBundle::DRIVER_DOCTRINE_ORM => new DoctrineORMDriver(), + SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM => new DoctrineODMDriver(), + SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM => new DoctrinePHPCRDriver(), + default => throw new UnknownDriverException($type), + }; } } diff --git a/src/Bundle/DependencyInjection/SyliusResourceExtension.php b/src/Bundle/DependencyInjection/SyliusResourceExtension.php index ba3c013c6..73bb019ac 100644 --- a/src/Bundle/DependencyInjection/SyliusResourceExtension.php +++ b/src/Bundle/DependencyInjection/SyliusResourceExtension.php @@ -189,9 +189,7 @@ private function loadPersistence(array $drivers, array $resources, LoaderInterfa $this->checkConfiguredDrivers($drivers, $availableDrivers, $resourceDrivers); - $integrateDoctrine = array_reduce($drivers, function (bool $result, string $driver): bool { - return $result || in_array($driver, [SyliusResourceBundle::DRIVER_DOCTRINE_ORM, SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM], true); - }, false); + $integrateDoctrine = array_reduce($drivers, fn (bool $result, string $driver): bool => $result || in_array($driver, [SyliusResourceBundle::DRIVER_DOCTRINE_ORM, SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM], true), false); if ($integrateDoctrine) { $loader->load('services/integrations/doctrine.xml'); @@ -223,14 +221,10 @@ private function loadPersistence(array $drivers, array $resources, LoaderInterfa */ private function getResourceDrivers(array $resources): array { - $resourceDrivers = array_map(function (array $resource): string|false { - return $resource['driver'] ?? false; - }, $resources); + $resourceDrivers = array_map(fn (array $resource): string|false => $resource['driver'] ?? false, $resources); // Remove resources with disabled driver - return array_filter($resourceDrivers, function (string|false $driver): bool { - return false !== $driver; - }); + return array_filter($resourceDrivers, fn (string|false $driver): bool => false !== $driver); } private function getAvailableDrivers(ContainerBuilder $container): array diff --git a/src/Bundle/Doctrine/ODM/PHPCR/DocumentRepository.php b/src/Bundle/Doctrine/ODM/PHPCR/DocumentRepository.php index 40ae3d6f8..97b5f2c39 100644 --- a/src/Bundle/Doctrine/ODM/PHPCR/DocumentRepository.php +++ b/src/Bundle/Doctrine/ODM/PHPCR/DocumentRepository.php @@ -98,7 +98,7 @@ protected function applySorting(QueryBuilder $queryBuilder, array $sorting = []) protected function getPropertyName(string $name): string { - if (false === strpos($name, '.')) { + if (!str_contains($name, '.')) { return $this->getAlias() . '.' . $name; } diff --git a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/DefaultParentListener.php b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/DefaultParentListener.php index 5bee1ea2c..ad6cdc99b 100644 --- a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/DefaultParentListener.php +++ b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/DefaultParentListener.php @@ -28,33 +28,19 @@ class DefaultParentListener /** @var DocumentManagerInterface */ private $documentManager; - private string $parentPath; - - private bool $autocreate; - - private bool $force; - - /** - * @param string $parentPath - * @param bool $autocreate - * @param bool $force - */ public function __construct( DocumentManagerInterface $documentManager, - $parentPath, - $autocreate = false, - $force = false, + private string $parentPath, + private bool $autocreate = false, + private bool $force = false, ) { $this->documentManager = $documentManager; - $this->parentPath = $parentPath; - $this->autocreate = $autocreate; - $this->force = $force; } public function onPreCreate(ResourceControllerEvent $event) { $document = $event->getSubject(); - $class = get_class($document); + $class = $document::class; $this->resolveParent( $document, @@ -69,7 +55,7 @@ private function resolveParent( if (!$parentField = $metadata->parentMapping) { throw new \RuntimeException(sprintf( 'A default parent path has been specified, but no parent mapping has been applied to document "%s"', - get_class($document), + $document::class, )); } diff --git a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameFilterListener.php b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameFilterListener.php index 958f8919e..04ab9cedb 100644 --- a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameFilterListener.php +++ b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameFilterListener.php @@ -30,27 +30,26 @@ class NameFilterListener /** @var DocumentManagerInterface */ private $documentManager; - /** @var string */ - private $replacementCharacter; - + /** + * @param string $replacementCharacter + */ public function __construct( DocumentManagerInterface $documentManager, - $replacementCharacter = ' ', + private $replacementCharacter = ' ', ) { $this->documentManager = $documentManager; - $this->replacementCharacter = $replacementCharacter; } public function onEvent(ResourceControllerEvent $event) { $document = $event->getSubject(); - $metadata = $this->documentManager->getClassMetadata(get_class($document)); + $metadata = $this->documentManager->getClassMetadata($document::class); if (null === $nameField = $metadata->nodename) { throw new \RuntimeException(sprintf( 'In order to use the node name filter on "%s" it is necessary to map a field as the "nodename"', - get_class($document), + $document::class, )); } diff --git a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameResolverListener.php b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameResolverListener.php index a3e2a969a..f4f726f77 100644 --- a/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameResolverListener.php +++ b/src/Bundle/Doctrine/ODM/PHPCR/EventListener/NameResolverListener.php @@ -40,12 +40,12 @@ public function onEvent(ResourceControllerEvent $event) { $document = $event->getSubject(); - $metadata = $this->documentManager->getClassMetadata(get_class($document)); + $metadata = $this->documentManager->getClassMetadata($document::class); if ($metadata->idGenerator !== ClassMetadata::GENERATOR_TYPE_PARENT) { throw new \RuntimeException(sprintf( 'Document of class "%s" must be using the GENERATOR_TYPE_PARENT identificatio strategy (value %s), it is current using "%s" (this may be an automatic configuration: be sure to map both the `nodename` and the `parentDocument`).', - get_class($document), + $document::class, ClassMetadata::GENERATOR_TYPE_PARENT, $metadata->idGenerator, )); diff --git a/src/Bundle/Doctrine/ORM/ContainerRepositoryFactory.php b/src/Bundle/Doctrine/ORM/ContainerRepositoryFactory.php index 334ba3267..ee79fb340 100644 --- a/src/Bundle/Doctrine/ORM/ContainerRepositoryFactory.php +++ b/src/Bundle/Doctrine/ORM/ContainerRepositoryFactory.php @@ -20,21 +20,14 @@ final class ContainerRepositoryFactory implements RepositoryFactory { - private RepositoryFactory $doctrineFactory; - - /** @var string[] */ - private array $genericEntities; - /** @var DoctrineEntityRepository[] */ private array $managedRepositories = []; /** * @param string[] $genericEntities */ - public function __construct(RepositoryFactory $doctrineFactory, array $genericEntities) + public function __construct(private RepositoryFactory $doctrineFactory, private array $genericEntities) { - $this->doctrineFactory = $doctrineFactory; - $this->genericEntities = $genericEntities; } /** diff --git a/src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php b/src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php index fec68ac2d..d1395ea62 100644 --- a/src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php +++ b/src/Bundle/Doctrine/ORM/Form/Builder/DefaultFormBuilder.php @@ -19,15 +19,11 @@ use Sylius\Bundle\ResourceBundle\Form\Builder\DefaultFormBuilderInterface; use Sylius\Resource\Metadata\MetadataInterface; use Symfony\Component\Form\FormBuilderInterface; -use Webmozart\Assert\Assert; class DefaultFormBuilder implements DefaultFormBuilderInterface { - private EntityManagerInterface $entityManager; - - public function __construct(EntityManagerInterface $entityManager) + public function __construct(private EntityManagerInterface $entityManager) { - $this->entityManager = $entityManager; } public function build(MetadataInterface $metadata, FormBuilderInterface $formBuilder, array $options): void @@ -53,7 +49,7 @@ private function doBuild(ClassMetadata $classMetadata, FormBuilderInterface $for $options = []; // Skip fields coming from embeddables - if (strpos($fieldName, '.') !== false) { + if (str_contains($fieldName, '.')) { continue; } @@ -71,8 +67,6 @@ private function doBuild(ClassMetadata $classMetadata, FormBuilderInterface $for foreach ($classMetadata->embeddedClasses as $fieldName => $embeddedMapping) { $nestedFormBuilder = $formBuilder->create($fieldName, null, ['data_class' => $embeddedMapping['class'], 'compound' => true]); - Assert::stringNotEmpty($embeddedMapping['class']); - $this->doBuild($this->entityManager->getClassMetadata($embeddedMapping['class']), $nestedFormBuilder); $formBuilder->add($nestedFormBuilder); diff --git a/src/Bundle/Doctrine/ORM/ResourceRepositoryTrait.php b/src/Bundle/Doctrine/ORM/ResourceRepositoryTrait.php index abd6fad6c..a1d5a3774 100644 --- a/src/Bundle/Doctrine/ORM/ResourceRepositoryTrait.php +++ b/src/Bundle/Doctrine/ORM/ResourceRepositoryTrait.php @@ -113,7 +113,7 @@ protected function applySorting(QueryBuilder $queryBuilder, array $sorting = []) protected function getPropertyName(string $name): string { - if (false === strpos($name, '.')) { + if (!str_contains($name, '.')) { return 'o' . '.' . $name; } diff --git a/src/Bundle/Doctrine/ResourceMappingDriverChain.php b/src/Bundle/Doctrine/ResourceMappingDriverChain.php index 209005a5c..9eb66f234 100644 --- a/src/Bundle/Doctrine/ResourceMappingDriverChain.php +++ b/src/Bundle/Doctrine/ResourceMappingDriverChain.php @@ -25,12 +25,8 @@ */ final class ResourceMappingDriverChain extends MappingDriverChain { - private RegistryInterface $resourceRegistry; - - public function __construct(MappingDriver $mappingDriver, RegistryInterface $resourceRegistry) + public function __construct(MappingDriver $mappingDriver, private RegistryInterface $resourceRegistry) { - $this->resourceRegistry = $resourceRegistry; - $this->setDefaultDriver($mappingDriver); } @@ -56,7 +52,7 @@ private function convertResourceMappedSuperclass(ClassMetadata $metadata): void try { $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName()); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } diff --git a/src/Bundle/EventListener/AbstractDoctrineListener.php b/src/Bundle/EventListener/AbstractDoctrineListener.php index 8b7c175cc..3258f6e28 100644 --- a/src/Bundle/EventListener/AbstractDoctrineListener.php +++ b/src/Bundle/EventListener/AbstractDoctrineListener.php @@ -21,13 +21,10 @@ abstract class AbstractDoctrineListener { - protected RegistryInterface $resourceRegistry; - private ?RuntimeReflectionService $reflectionService = null; - public function __construct(RegistryInterface $resourceRegistry) + public function __construct(protected RegistryInterface $resourceRegistry) { - $this->resourceRegistry = $resourceRegistry; } protected function isResource(ClassMetadata $metadata): bool diff --git a/src/Bundle/EventListener/ODMMappedSuperClassSubscriber.php b/src/Bundle/EventListener/ODMMappedSuperClassSubscriber.php index 18c67e37c..0d6109fdc 100644 --- a/src/Bundle/EventListener/ODMMappedSuperClassSubscriber.php +++ b/src/Bundle/EventListener/ODMMappedSuperClassSubscriber.php @@ -56,7 +56,7 @@ private function convertToDocumentIfNeeded(ClassMetadataInfo $metadata) try { $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName()); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } diff --git a/src/Bundle/EventListener/ODMRepositoryClassSubscriber.php b/src/Bundle/EventListener/ODMRepositoryClassSubscriber.php index d502f0c2e..508179c65 100644 --- a/src/Bundle/EventListener/ODMRepositoryClassSubscriber.php +++ b/src/Bundle/EventListener/ODMRepositoryClassSubscriber.php @@ -40,7 +40,7 @@ private function setCustomRepositoryClass(ClassMetadata $metadata) { try { $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName()); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } diff --git a/src/Bundle/EventListener/ODMTranslatableListener.php b/src/Bundle/EventListener/ODMTranslatableListener.php index b05f60d9f..b034f78ee 100644 --- a/src/Bundle/EventListener/ODMTranslatableListener.php +++ b/src/Bundle/EventListener/ODMTranslatableListener.php @@ -28,17 +28,8 @@ final class ODMTranslatableListener implements EventSubscriber /** @var string */ private $currentLocale; - private string $fallbackLocale; - - private array $mappings; - - /** - * @param string $fallbackLocale - */ - public function __construct(array $mappings, $fallbackLocale) + public function __construct(private array $mappings, private string $fallbackLocale) { - $this->mappings = $mappings; - $this->fallbackLocale = $fallbackLocale; } public function setCurrentLocale($currentLocale) @@ -145,7 +136,7 @@ public function postLoad(LifecycleEventArgs $args) $document = $args->getDocument(); // Sometimes $document is a doctrine proxy class, we therefore need to retrieve it's real class - $name = $args->getDocumentManager()->getClassMetadata(get_class($document))->getName(); + $name = $args->getDocumentManager()->getClassMetadata($document::class)->getName(); if (!isset($this->mappings[$name])) { return; diff --git a/src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php b/src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php index 585dfd316..f7db1bf38 100644 --- a/src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php +++ b/src/Bundle/EventListener/ORMMappedSuperClassSubscriber.php @@ -85,6 +85,7 @@ private function setAssociationMappings(ClassMetadata $metadata, Configuration $ * @var AssociationMapping|array{type: int} $value */ foreach ($parentMetadata->getAssociationMappings() as $key => $value) { + /** @var int $type */ $type = \is_array($value) ? $value['type'] : $value->type(); if ($this->isRelation($type) && !isset($metadata->associationMappings[$key])) { $metadata->associationMappings[$key] = $value; /** @phpstan-ignore-line */ @@ -105,6 +106,7 @@ private function unsetAssociationMappings(ClassMetadata $metadata): void * @var AssociationMapping|array{type: int} $value */ foreach ($metadata->getAssociationMappings() as $key => $value) { + /** @var int $type */ $type = \is_array($value) ? $value['type'] : $value->type(); if ($this->isRelation($type)) { unset($metadata->associationMappings[$key]); diff --git a/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php b/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php index 8ec682080..87da88a0d 100644 --- a/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php +++ b/src/Bundle/EventListener/ORMRepositoryClassSubscriber.php @@ -40,7 +40,7 @@ private function setCustomRepositoryClass(ClassMetadata $metadata): void { try { $resourceMetadata = $this->resourceRegistry->getByClass($metadata->getName()); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } diff --git a/src/Bundle/EventListener/ORMTranslatableListener.php b/src/Bundle/EventListener/ORMTranslatableListener.php index 5b95d861b..16500774e 100644 --- a/src/Bundle/EventListener/ORMTranslatableListener.php +++ b/src/Bundle/EventListener/ORMTranslatableListener.php @@ -27,15 +27,12 @@ final class ORMTranslatableListener implements EventSubscriber { - private RegistryInterface $resourceMetadataRegistry; - private TranslatableEntityLocaleAssignerInterface $translatableEntityLocaleAssigner; public function __construct( - RegistryInterface $resourceMetadataRegistry, + private RegistryInterface $resourceMetadataRegistry, object $translatableEntityLocaleAssigner, ) { - $this->resourceMetadataRegistry = $resourceMetadataRegistry; $this->translatableEntityLocaleAssigner = $this->processTranslatableEntityLocaleAssigner($translatableEntityLocaleAssigner); } @@ -92,7 +89,7 @@ private function mapTranslatable(ClassMetadata $metadata): void try { $resourceMetadata = $this->resourceMetadataRegistry->getByClass($className); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } @@ -125,7 +122,7 @@ private function mapTranslation(ClassMetadata $metadata): void try { $resourceMetadata = $this->resourceMetadataRegistry->getByClass($className); - } catch (\InvalidArgumentException $exception) { + } catch (\InvalidArgumentException) { return; } @@ -210,7 +207,7 @@ private function processTranslatableEntityLocaleAssigner(object $translatableEnt throw new \InvalidArgumentException(sprintf( '`$translatableEntityLocaleAssigner` was expected to return an instance of "%s" , "%s" found', TranslatableEntityLocaleAssignerInterface::class, - get_class($translatableEntityLocaleAssigner), + $translatableEntityLocaleAssigner::class, )); } diff --git a/src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php b/src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php index c92b0b5a4..a48a0955d 100644 --- a/src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php +++ b/src/Bundle/ExpressionLanguage/NotNullExpressionFunctionProvider.php @@ -27,9 +27,7 @@ public function getFunctions(): array /** * @param mixed $result */ - function ($result): string { - return sprintf('(null !== %1$s) ? %1$s : throw new NotFoundHttpException(\'Requested page is invalid.\')', $result); - }, + fn ($result): string => sprintf('(null !== %1$s) ? %1$s : throw new NotFoundHttpException(\'Requested page is invalid.\')', $result), /** * @param mixed $arguments * @param mixed $result diff --git a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php index 74f800d9d..070cb6a06 100644 --- a/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php +++ b/src/Bundle/Form/DataTransformer/CollectionToStringTransformer.php @@ -20,11 +20,8 @@ final class CollectionToStringTransformer implements DataTransformerInterface { - private string $delimiter; - - public function __construct(string $delimiter) + public function __construct(private string $delimiter) { - $this->delimiter = $delimiter; } public function transform($value): string @@ -34,7 +31,7 @@ public function transform($value): string sprintf( 'Expected "%s", but got "%s"', Collection::class, - is_object($value) ? get_class($value) : gettype($value), + get_debug_type($value), ), ); } @@ -52,7 +49,7 @@ public function reverseTransform($value): Collection throw new TransformationFailedException( sprintf( 'Expected string, but got "%s"', - is_object($value) ? get_class($value) : gettype($value), + get_debug_type($value), ), ); } diff --git a/src/Bundle/Form/DataTransformer/RecursiveTransformer.php b/src/Bundle/Form/DataTransformer/RecursiveTransformer.php index 5fca79116..018defa3d 100644 --- a/src/Bundle/Form/DataTransformer/RecursiveTransformer.php +++ b/src/Bundle/Form/DataTransformer/RecursiveTransformer.php @@ -21,11 +21,8 @@ final class RecursiveTransformer implements DataTransformerInterface { - private DataTransformerInterface $decoratedTransformer; - - public function __construct(DataTransformerInterface $decoratedTransformer) + public function __construct(private DataTransformerInterface $decoratedTransformer) { - $this->decoratedTransformer = $decoratedTransformer; } /** @param Collection|null $value */ @@ -43,9 +40,7 @@ public function transform($value): ReadableCollection * * @return mixed */ - function ($currentValue) { - return $this->decoratedTransformer->transform($currentValue); - }, + fn ($currentValue) => $this->decoratedTransformer->transform($currentValue), ); } @@ -64,9 +59,7 @@ public function reverseTransform($value): ReadableCollection * * @return mixed */ - function ($currentValue) { - return $this->decoratedTransformer->reverseTransform($currentValue); - }, + fn ($currentValue) => $this->decoratedTransformer->reverseTransform($currentValue), ); } @@ -82,7 +75,7 @@ private function assertTransformationValueType($value, string $expectedType): vo sprintf( 'Expected "%s", but got "%s"', $expectedType, - is_object($value) ? get_class($value) : gettype($value), + get_debug_type($value), ), ); } diff --git a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php index 8b52bdbf9..ec3b8907f 100644 --- a/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php +++ b/src/Bundle/Form/DataTransformer/ResourceToIdentifierTransformer.php @@ -22,13 +22,10 @@ final class ResourceToIdentifierTransformer implements DataTransformerInterface { - private RepositoryInterface $repository; - private string $identifier; - public function __construct(RepositoryInterface $repository, ?string $identifier = null) + public function __construct(private RepositoryInterface $repository, ?string $identifier = null) { - $this->repository = $repository; $this->identifier = $identifier ?? 'id'; } diff --git a/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php b/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php index 64dc849d7..0fb1d4324 100644 --- a/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php +++ b/src/Bundle/Form/EventSubscriber/AddCodeFormSubscriber.php @@ -24,12 +24,9 @@ final class AddCodeFormSubscriber implements EventSubscriberInterface { private string $type; - private array $options; - - public function __construct(?string $type = null, array $options = []) + public function __construct(?string $type = null, private array $options = []) { $this->type = $type ?? TextType::class; - $this->options = $options; } public static function getSubscribedEvents(): array diff --git a/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php b/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php index 078cc9f9c..b0e4a97f1 100644 --- a/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php +++ b/src/Bundle/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php @@ -42,7 +42,7 @@ public function __construct(ServerParams $serverParams = null) public function handleRequest(FormInterface $form, mixed $request = null): void { if (!$request instanceof Request) { - throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request'); + throw new UnexpectedTypeException($request, \Symfony\Component\HttpFoundation\Request::class); } $name = $form->getName(); diff --git a/src/Bundle/Form/Type/AbstractResourceType.php b/src/Bundle/Form/Type/AbstractResourceType.php index 20829535c..6b61c4d49 100644 --- a/src/Bundle/Form/Type/AbstractResourceType.php +++ b/src/Bundle/Form/Type/AbstractResourceType.php @@ -18,19 +18,12 @@ abstract class AbstractResourceType extends AbstractType { - protected string $dataClass; - - /** @var string[] */ - protected array $validationGroups = []; - /** * @param string $dataClass FQCN * @param string[] $validationGroups */ - public function __construct(string $dataClass, array $validationGroups = []) + public function __construct(protected string $dataClass, protected array $validationGroups = []) { - $this->dataClass = $dataClass; - $this->validationGroups = $validationGroups; } public function configureOptions(OptionsResolver $resolver): void diff --git a/src/Bundle/Form/Type/DefaultResourceType.php b/src/Bundle/Form/Type/DefaultResourceType.php index 9fac863c6..7b1758ea9 100644 --- a/src/Bundle/Form/Type/DefaultResourceType.php +++ b/src/Bundle/Form/Type/DefaultResourceType.php @@ -22,14 +22,8 @@ final class DefaultResourceType extends AbstractType { - private RegistryInterface $metadataRegistry; - - private ServiceRegistryInterface $formBuilderRegistry; - - public function __construct(RegistryInterface $metadataRegistry, ServiceRegistryInterface $formBuilderRegistry) + public function __construct(private RegistryInterface $metadataRegistry, private ServiceRegistryInterface $formBuilderRegistry) { - $this->metadataRegistry = $metadataRegistry; - $this->formBuilderRegistry = $formBuilderRegistry; } public function buildForm(FormBuilderInterface $builder, array $options): void @@ -42,7 +36,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void Assert::notFalse($driver, sprintf( 'Form "%s" cannot be used with no driver configured on the resource "%s". Please define a form.', - __CLASS__, + self::class, $metadata->getAlias(), )); diff --git a/src/Bundle/Form/Type/FixedCollectionType.php b/src/Bundle/Form/Type/FixedCollectionType.php index 1d9600699..8f3f099a5 100644 --- a/src/Bundle/Form/Type/FixedCollectionType.php +++ b/src/Bundle/Form/Type/FixedCollectionType.php @@ -53,9 +53,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setRequired('entry_name'); $resolver->setAllowedTypes('entry_name', ['callable']); - $resolver->setDefault('entry_options', function () { - return []; - }); + $resolver->setDefault('entry_options', fn () => []); $resolver->setAllowedTypes('entry_options', ['array', 'callable']); $resolver->setNormalizer('entry_options', $this->optionalCallableNormalizer()); } @@ -78,9 +76,7 @@ function (Options $options, $value) { return $value; } - return /** @return mixed */ function () use ($value) { - return $value; - }; + return /** @return mixed */ fn () => $value; } ; } diff --git a/src/Bundle/Form/Type/ResourceAutocompleteChoiceType.php b/src/Bundle/Form/Type/ResourceAutocompleteChoiceType.php index ecc01e6c8..ccc4defbb 100644 --- a/src/Bundle/Form/Type/ResourceAutocompleteChoiceType.php +++ b/src/Bundle/Form/Type/ResourceAutocompleteChoiceType.php @@ -29,11 +29,8 @@ class ResourceAutocompleteChoiceType extends AbstractType { - protected ServiceRegistryInterface $resourceRepositoryRegistry; - - public function __construct(ServiceRegistryInterface $resourceRepositoryRegistry) + public function __construct(protected ServiceRegistryInterface $resourceRepositoryRegistry) { - $this->resourceRepositoryRegistry = $resourceRepositoryRegistry; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Bundle/Form/Type/ResourceToIdentifierType.php b/src/Bundle/Form/Type/ResourceToIdentifierType.php index 357330f69..3a950b5dd 100644 --- a/src/Bundle/Form/Type/ResourceToIdentifierType.php +++ b/src/Bundle/Form/Type/ResourceToIdentifierType.php @@ -24,14 +24,8 @@ final class ResourceToIdentifierType extends AbstractType { - private RepositoryInterface $repository; - - private MetadataInterface $metadata; - - public function __construct(RepositoryInterface $repository, MetadataInterface $metadata) + public function __construct(private RepositoryInterface $repository, private MetadataInterface $metadata) { - $this->repository = $repository; - $this->metadata = $metadata; } public function buildForm(FormBuilderInterface $builder, array $options): void diff --git a/src/Bundle/Form/Type/ResourceTranslationsType.php b/src/Bundle/Form/Type/ResourceTranslationsType.php index f0ebcd808..da1ffa163 100644 --- a/src/Bundle/Form/Type/ResourceTranslationsType.php +++ b/src/Bundle/Form/Type/ResourceTranslationsType.php @@ -67,14 +67,10 @@ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ 'entries' => $this->definedLocalesCodes, - 'entry_name' => function (string $localeCode): string { - return $localeCode; - }, - 'entry_options' => function (string $localeCode): array { - return [ - 'required' => $localeCode === $this->defaultLocaleCode, - ]; - }, + 'entry_name' => fn (string $localeCode): string => $localeCode, + 'entry_options' => fn (string $localeCode): array => [ + 'required' => $localeCode === $this->defaultLocaleCode, + ], ]); } diff --git a/src/Bundle/Grid/Controller/ResourcesResolver.php b/src/Bundle/Grid/Controller/ResourcesResolver.php index 8d0f1ce56..0b258cf97 100644 --- a/src/Bundle/Grid/Controller/ResourcesResolver.php +++ b/src/Bundle/Grid/Controller/ResourcesResolver.php @@ -22,20 +22,11 @@ final class ResourcesResolver implements ResourcesResolverInterface { - private ResourcesResolverInterface $decoratedResolver; - - private GridProviderInterface $gridProvider; - - private ResourceGridViewFactoryInterface $gridViewFactory; - public function __construct( - ResourcesResolverInterface $decoratedResolver, - GridProviderInterface $gridProvider, - ResourceGridViewFactoryInterface $gridViewFactory, + private ResourcesResolverInterface $decoratedResolver, + private GridProviderInterface $gridProvider, + private ResourceGridViewFactoryInterface $gridViewFactory, ) { - $this->decoratedResolver = $decoratedResolver; - $this->gridProvider = $gridProvider; - $this->gridViewFactory = $gridViewFactory; } /** diff --git a/src/Bundle/Grid/Parser/OptionsParser.php b/src/Bundle/Grid/Parser/OptionsParser.php index bf7741e86..6f7c538e6 100644 --- a/src/Bundle/Grid/Parser/OptionsParser.php +++ b/src/Bundle/Grid/Parser/OptionsParser.php @@ -20,20 +20,11 @@ final class OptionsParser implements OptionsParserInterface { - private ContainerInterface $container; - - private ExpressionLanguage $expression; - - private PropertyAccessorInterface $propertyAccessor; - public function __construct( - ContainerInterface $container, - ExpressionLanguage $expression, - PropertyAccessorInterface $propertyAccessor, + private ContainerInterface $container, + private ExpressionLanguage $expression, + private PropertyAccessorInterface $propertyAccessor, ) { - $this->container = $container; - $this->expression = $expression; - $this->propertyAccessor = $propertyAccessor; } /** @@ -70,19 +61,19 @@ private function parseOption($parameter, Request $request, $data) return $parameter; } - if (0 === strpos($parameter, '$')) { + if (str_starts_with($parameter, '$')) { return $request->get(substr($parameter, 1)); } - if (0 === strpos($parameter, 'expr:')) { + if (str_starts_with($parameter, 'expr:')) { return $this->parseOptionExpression(substr($parameter, 5), $request); } - if (0 === strpos($parameter, 'resource.')) { + if (str_starts_with($parameter, 'resource.')) { return $this->parseOptionResourceField(substr($parameter, 9), $data); } - if (0 === strpos($parameter, 'resource[')) { + if (str_starts_with($parameter, 'resource[')) { return $this->parseOptionResourceField(substr($parameter, 8), $data); } diff --git a/src/Bundle/Grid/Renderer/TwigBulkActionGridRenderer.php b/src/Bundle/Grid/Renderer/TwigBulkActionGridRenderer.php index 50b65920c..4ab2e0465 100644 --- a/src/Bundle/Grid/Renderer/TwigBulkActionGridRenderer.php +++ b/src/Bundle/Grid/Renderer/TwigBulkActionGridRenderer.php @@ -23,20 +23,8 @@ final class TwigBulkActionGridRenderer implements BulkActionGridRendererInterface { - private Environment $twig; - - private OptionsParserInterface $optionsParser; - - private array $bulkActionTemplates; - - public function __construct( - Environment $twig, - OptionsParserInterface $optionsParser, - array $bulkActionTemplates = [], - ) { - $this->twig = $twig; - $this->optionsParser = $optionsParser; - $this->bulkActionTemplates = $bulkActionTemplates; + public function __construct(private Environment $twig, private OptionsParserInterface $optionsParser, private array $bulkActionTemplates = []) + { } public function renderBulkAction(GridViewInterface $gridView, Action $bulkAction, $data = null): string diff --git a/src/Bundle/Grid/Renderer/TwigGridRenderer.php b/src/Bundle/Grid/Renderer/TwigGridRenderer.php index 2a8608b26..d1c23a3f9 100644 --- a/src/Bundle/Grid/Renderer/TwigGridRenderer.php +++ b/src/Bundle/Grid/Renderer/TwigGridRenderer.php @@ -25,24 +25,12 @@ final class TwigGridRenderer implements GridRendererInterface { - private GridRendererInterface $gridRenderer; - - private Environment $twig; - - private OptionsParserInterface $optionsParser; - - private array $actionTemplates; - public function __construct( - GridRendererInterface $gridRenderer, - Environment $twig, - OptionsParserInterface $optionsParser, - array $actionTemplates = [], + private GridRendererInterface $gridRenderer, + private Environment $twig, + private OptionsParserInterface $optionsParser, + private array $actionTemplates = [], ) { - $this->gridRenderer = $gridRenderer; - $this->twig = $twig; - $this->optionsParser = $optionsParser; - $this->actionTemplates = $actionTemplates; } public function render(GridViewInterface $gridView, ?string $template = null): string diff --git a/src/Bundle/Grid/View/ResourceGridView.php b/src/Bundle/Grid/View/ResourceGridView.php index 021ac9344..c66f2872f 100644 --- a/src/Bundle/Grid/View/ResourceGridView.php +++ b/src/Bundle/Grid/View/ResourceGridView.php @@ -21,10 +21,6 @@ class ResourceGridView extends GridView { - private MetadataInterface $metadata; - - private RequestConfiguration $requestConfiguration; - /** * @param mixed $data */ @@ -32,13 +28,10 @@ public function __construct( $data, Grid $gridDefinition, Parameters $parameters, - MetadataInterface $resourceMetadata, - RequestConfiguration $requestConfiguration, + private MetadataInterface $metadata, + private RequestConfiguration $requestConfiguration, ) { parent::__construct($data, $gridDefinition, $parameters); - - $this->metadata = $resourceMetadata; - $this->requestConfiguration = $requestConfiguration; } public function getMetadata(): MetadataInterface diff --git a/src/Bundle/Grid/View/ResourceGridViewFactory.php b/src/Bundle/Grid/View/ResourceGridViewFactory.php index b5f1b6b65..5a8d6265a 100644 --- a/src/Bundle/Grid/View/ResourceGridViewFactory.php +++ b/src/Bundle/Grid/View/ResourceGridViewFactory.php @@ -22,14 +22,10 @@ final class ResourceGridViewFactory implements ResourceGridViewFactoryInterface { - private DataProviderInterface $dataProvider; - - private ParametersParserInterface $parametersParser; - - public function __construct(DataProviderInterface $dataProvider, ParametersParserInterface $parametersParser) - { - $this->dataProvider = $dataProvider; - $this->parametersParser = $parametersParser; + public function __construct( + private DataProviderInterface $dataProvider, + private ParametersParserInterface $parametersParser, + ) { } public function create( diff --git a/src/Bundle/ResourceBundleInterface.php b/src/Bundle/ResourceBundleInterface.php index 76e5ce41a..5e697204d 100644 --- a/src/Bundle/ResourceBundleInterface.php +++ b/src/Bundle/ResourceBundleInterface.php @@ -28,6 +28,8 @@ interface ResourceBundleInterface /** * Returns a vector of supported drivers. * + * @return string[] + * * @see SyliusResourceBundle::DRIVER_DOCTRINE_ORM * @see SyliusResourceBundle::DRIVER_DOCTRINE_MONGODB_ODM * @see SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM diff --git a/src/Bundle/Routing/CrudRoutesAttributesLoader.php b/src/Bundle/Routing/CrudRoutesAttributesLoader.php index 6427ff95b..75bdd7a62 100644 --- a/src/Bundle/Routing/CrudRoutesAttributesLoader.php +++ b/src/Bundle/Routing/CrudRoutesAttributesLoader.php @@ -22,16 +22,8 @@ final class CrudRoutesAttributesLoader implements RouteLoaderInterface { - private array $mapping; - - private ResourceLoader $resourceLoader; - - public function __construct( - array $mapping, - ResourceLoader $resourceLoader, - ) { - $this->mapping = $mapping; - $this->resourceLoader = $resourceLoader; + public function __construct(private array $mapping, private ResourceLoader $resourceLoader) + { } public function __invoke(): RouteCollection diff --git a/src/Bundle/Routing/ResourceLoader.php b/src/Bundle/Routing/ResourceLoader.php index 639182163..029e6d707 100644 --- a/src/Bundle/Routing/ResourceLoader.php +++ b/src/Bundle/Routing/ResourceLoader.php @@ -24,19 +24,12 @@ final class ResourceLoader extends Loader { - private RegistryInterface $resourceRegistry; - - private RouteFactoryInterface $routeFactory; - public function __construct( - RegistryInterface $resourceRegistry, - RouteFactoryInterface $routeFactory, + private RegistryInterface $resourceRegistry, + private RouteFactoryInterface $routeFactory, ?string $env = null, ) { parent::__construct($env); - - $this->resourceRegistry = $resourceRegistry; - $this->routeFactory = $routeFactory; } public function load($resource, $type = null): RouteCollection @@ -148,7 +141,7 @@ private function createRoute( } if (isset($configuration['templates']) && in_array($actionName, ['show', 'index', 'create', 'update'], true)) { $defaults['_sylius']['template'] = sprintf( - false === strpos($configuration['templates'], ':') ? '%s/%s.html.twig' : '%s:%s.html.twig', + !str_contains($configuration['templates'], ':') ? '%s/%s.html.twig' : '%s:%s.html.twig', $configuration['templates'], $actionName, ); diff --git a/src/Bundle/Validator/DisabledValidator.php b/src/Bundle/Validator/DisabledValidator.php index af101cd2a..5bce1c49f 100644 --- a/src/Bundle/Validator/DisabledValidator.php +++ b/src/Bundle/Validator/DisabledValidator.php @@ -32,7 +32,7 @@ public function validate(mixed $value, Constraint $constraint): void if (!$value instanceof ToggleableInterface) { throw new \InvalidArgumentException(sprintf( '"%s" validates "%s" instances only', - __CLASS__, + self::class, ToggleableInterface::class, )); } diff --git a/src/Bundle/Validator/EnabledValidator.php b/src/Bundle/Validator/EnabledValidator.php index 75631549e..81635f9e1 100644 --- a/src/Bundle/Validator/EnabledValidator.php +++ b/src/Bundle/Validator/EnabledValidator.php @@ -32,7 +32,7 @@ public function validate(mixed $value, Constraint $constraint): void if (!$value instanceof ToggleableInterface) { throw new \InvalidArgumentException(sprintf( '"%s" validates "%s" instances only', - __CLASS__, + self::class, ToggleableInterface::class, )); } diff --git a/src/Component/src/Annotation/SyliusCrudRoutes.php b/src/Component/src/Annotation/SyliusCrudRoutes.php index d350fd49c..6f7aa883b 100644 --- a/src/Component/src/Annotation/SyliusCrudRoutes.php +++ b/src/Component/src/Annotation/SyliusCrudRoutes.php @@ -16,68 +16,23 @@ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] final class SyliusCrudRoutes { - public ?string $alias = null; - - public ?string $path = null; - - public ?string $identifier = null; - - public ?array $criteria = null; - - public ?bool $filterable = null; - - public ?string $form = null; - - public ?string $serializationVersion = null; - - public ?string $section = null; - - public ?string $redirect = null; - - public ?string $templates = null; - - public ?string $grid = null; - - public ?bool $permission = null; - - public ?array $except = null; - - public ?array $only = null; - - public ?array $vars = null; - public function __construct( - ?string $alias = null, - ?string $path = null, - ?string $identifier = null, - ?array $criteria = null, - ?bool $filterable = null, - ?string $form = null, - ?string $serializationVersion = null, - ?string $section = null, - ?string $redirect = null, - ?string $templates = null, - ?string $grid = null, - ?bool $permission = null, - ?array $except = null, - ?array $only = null, - ?array $vars = null, + public ?string $alias = null, + public ?string $path = null, + public ?string $identifier = null, + public ?array $criteria = null, + public ?bool $filterable = null, + public ?string $form = null, + public ?string $serializationVersion = null, + public ?string $section = null, + public ?string $redirect = null, + public ?string $templates = null, + public ?string $grid = null, + public ?bool $permission = null, + public ?array $except = null, + public ?array $only = null, + public ?array $vars = null, ) { - $this->alias = $alias; - $this->path = $path; - $this->identifier = $identifier; - $this->criteria = $criteria; - $this->filterable = $filterable; - $this->form = $form; - $this->serializationVersion = $serializationVersion; - $this->section = $section; - $this->redirect = $redirect; - $this->templates = $templates; - $this->grid = $grid; - $this->permission = $permission; - $this->except = $except; - $this->only = $only; - $this->vars = $vars; } } diff --git a/src/Component/src/Context/Context.php b/src/Component/src/Context/Context.php index cb5c09a52..05dfeb2d2 100644 --- a/src/Component/src/Context/Context.php +++ b/src/Component/src/Context/Context.php @@ -25,7 +25,7 @@ public function __construct(object ...$options) { $map = []; foreach ($options as $option) { - $map[get_class($option)] = $option; + $map[$option::class] = $option; } $this->optionMap = $map; diff --git a/src/Component/src/Doctrine/Persistence/InMemoryRepository.php b/src/Component/src/Doctrine/Persistence/InMemoryRepository.php index 2aee74057..31b41259b 100644 --- a/src/Component/src/Doctrine/Persistence/InMemoryRepository.php +++ b/src/Component/src/Doctrine/Persistence/InMemoryRepository.php @@ -71,9 +71,7 @@ public function add(ResourceInterface $resource): void public function remove(ResourceInterface $resource): void { - $newResources = array_filter($this->findAll(), static function ($object) use ($resource) { - return $object !== $resource; - }); + $newResources = array_filter($this->findAll(), static fn ($object) => $object !== $resource); $this->arrayObject->exchangeArray($newResources); } diff --git a/src/Component/src/Exception/DeleteHandlingException.php b/src/Component/src/Exception/DeleteHandlingException.php index 905c27571..ec9fbb1f7 100644 --- a/src/Component/src/Exception/DeleteHandlingException.php +++ b/src/Component/src/Exception/DeleteHandlingException.php @@ -15,21 +15,14 @@ class DeleteHandlingException extends RuntimeException { - protected string $flash; - - protected int $apiResponseCode; - public function __construct( string $message = 'Ups, something went wrong during deleting a resource, please try again.', - string $flash = 'something_went_wrong_error', - int $apiResponseCode = 500, + protected string $flash = 'something_went_wrong_error', + protected int $apiResponseCode = 500, int $code = 0, ?\Throwable $previous = null, ) { parent::__construct($message, $code, $previous); - - $this->flash = $flash; - $this->apiResponseCode = $apiResponseCode; } public function getFlash(): string diff --git a/src/Component/src/Exception/UpdateHandlingException.php b/src/Component/src/Exception/UpdateHandlingException.php index 3469df933..fa002af15 100644 --- a/src/Component/src/Exception/UpdateHandlingException.php +++ b/src/Component/src/Exception/UpdateHandlingException.php @@ -15,21 +15,14 @@ class UpdateHandlingException extends Exception { - protected string $flash; - - protected int $apiResponseCode; - public function __construct( string $message = 'Ups, something went wrong during updating a resource, please try again.', - string $flash = 'something_went_wrong_error', - int $apiResponseCode = 400, + protected string $flash = 'something_went_wrong_error', + protected int $apiResponseCode = 400, int $code = 0, ?\Exception $previous = null, ) { parent::__construct($message, $code, $previous); - - $this->flash = $flash; - $this->apiResponseCode = $apiResponseCode; } public function getFlash(): string diff --git a/src/Component/src/Factory/Factory.php b/src/Component/src/Factory/Factory.php index 9d28f0676..8f8ade2dc 100644 --- a/src/Component/src/Factory/Factory.php +++ b/src/Component/src/Factory/Factory.php @@ -18,15 +18,11 @@ */ final class Factory implements FactoryInterface { - /** @var class-string */ - private $className; - /** * @param class-string $className */ - public function __construct(string $className) + public function __construct(private string $className) { - $this->className = $className; } public function createNew() diff --git a/src/Component/src/Factory/TranslatableFactory.php b/src/Component/src/Factory/TranslatableFactory.php index 8ddafa26a..66e48885b 100644 --- a/src/Component/src/Factory/TranslatableFactory.php +++ b/src/Component/src/Factory/TranslatableFactory.php @@ -19,14 +19,10 @@ final class TranslatableFactory implements TranslatableFactoryInterface { - private FactoryInterface $factory; - - private TranslationLocaleProviderInterface $localeProvider; - - public function __construct(FactoryInterface $factory, TranslationLocaleProviderInterface $localeProvider) - { - $this->factory = $factory; - $this->localeProvider = $localeProvider; + public function __construct( + private FactoryInterface $factory, + private TranslationLocaleProviderInterface $localeProvider, + ) { } /** diff --git a/src/Component/src/Generator/RandomnessGenerator.php b/src/Component/src/Generator/RandomnessGenerator.php index fa70eed07..2988439e2 100644 --- a/src/Component/src/Generator/RandomnessGenerator.php +++ b/src/Component/src/Generator/RandomnessGenerator.php @@ -23,13 +23,13 @@ final class RandomnessGenerator implements RandomnessGeneratorInterface public function __construct() { - $this->digits = implode(range(0, 9)); + $this->digits = implode('', range(0, 9)); $this->uriSafeAlphabet = - implode(range(0, 9)) - . implode(range('a', 'z')) - . implode(range('A', 'Z')) - . implode(['-', '_', '~']) + implode('', range(0, 9)) + . implode('', range('a', 'z')) + . implode('', range('A', 'Z')) + . implode('', ['-', '_', '~']) ; } diff --git a/src/Component/src/Metadata/Metadata.php b/src/Component/src/Metadata/Metadata.php index 9bedda3d8..125b9a378 100644 --- a/src/Component/src/Metadata/Metadata.php +++ b/src/Component/src/Metadata/Metadata.php @@ -18,10 +18,6 @@ final class Metadata implements MetadataInterface { - private string $name; - - private string $applicationName; - /** @var string */ private $driver; @@ -35,11 +31,8 @@ final class Metadata implements MetadataInterface private static ?InflectorObject $inflectorInstance = null; - private function __construct(string $name, string $applicationName, array $parameters) + private function __construct(private string $name, private string $applicationName, array $parameters) { - $this->name = $name; - $this->applicationName = $applicationName; - $this->driver = $parameters['driver']; $this->templatesNamespace = array_key_exists('templates', $parameters) ? $parameters['templates'] : null; $this->stateMachineComponent = $parameters['state_machine_component'] ?? null; @@ -155,7 +148,7 @@ public function getPermissionCode(string $permissionName): string private static function parseAlias(string $alias): array { - if (false === strpos($alias, '.')) { + if (!str_contains($alias, '.')) { throw new \InvalidArgumentException(sprintf('Invalid alias "%s" supplied, it should conform to the following format ".".', $alias)); } diff --git a/src/Component/src/Symfony/Form/Factory/FormFactory.php b/src/Component/src/Symfony/Form/Factory/FormFactory.php index 031c55984..dcdeda0e0 100644 --- a/src/Component/src/Symfony/Form/Factory/FormFactory.php +++ b/src/Component/src/Symfony/Form/Factory/FormFactory.php @@ -24,11 +24,8 @@ */ final class FormFactory implements FormFactoryInterface { - private SymfonyFormFactoryInterface $formFactory; - - public function __construct(SymfonyFormFactoryInterface $formFactory) + public function __construct(private SymfonyFormFactoryInterface $formFactory) { - $this->formFactory = $formFactory; } public function create(Operation $operation, Context $context, mixed $data = null): FormInterface diff --git a/src/Component/src/Symfony/Request/RepositoryArgumentResolver.php b/src/Component/src/Symfony/Request/RepositoryArgumentResolver.php index 23f912c67..41b60e46b 100644 --- a/src/Component/src/Symfony/Request/RepositoryArgumentResolver.php +++ b/src/Component/src/Symfony/Request/RepositoryArgumentResolver.php @@ -63,9 +63,7 @@ public function getArguments(Request $request, \ReflectionFunctionAbstract $refl */ private function filterPrivateArguments(array $arguments): array { - return array_filter($arguments, function (string $key): bool { - return !str_starts_with($key, '_'); - }, \ARRAY_FILTER_USE_KEY); + return array_filter($arguments, fn (string $key): bool => !str_starts_with($key, '_'), \ARRAY_FILTER_USE_KEY); } private function hasOnlyOneRequiredArrayParameter(\ReflectionFunctionAbstract $reflector): bool @@ -73,9 +71,7 @@ private function hasOnlyOneRequiredArrayParameter(\ReflectionFunctionAbstract $r /** @var array|\ReflectionParameter[] $parameters */ $parameters = $reflector->getParameters(); - $parameters = array_filter($parameters, function ($parameter): bool { - return !$parameter->isDefaultValueAvailable(); - }); + $parameters = array_filter($parameters, fn ($parameter): bool => !$parameter->isDefaultValueAvailable()); if (1 !== \count($parameters)) { return false;