diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index 004292eb..1e113e12 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -177,7 +177,7 @@ public function get($name, ?array $options = null) * * @psalm-assert InstanceType $instance */ - public function validate($instance) + public function validate(mixed $instance) { if (method_exists($this, 'validatePlugin')) { trigger_error(sprintf( diff --git a/src/Exception/CyclicAliasException.php b/src/Exception/CyclicAliasException.php index 51a42c2f..806da73c 100644 --- a/src/Exception/CyclicAliasException.php +++ b/src/Exception/CyclicAliasException.php @@ -43,7 +43,7 @@ public static function fromCyclicAlias(string $alias, array $aliases): self public static function fromAliasesMap(array $aliases) { $detectedCycles = array_filter(array_map( - static fn($alias) => self::getCycleFor($aliases, $alias), + static fn($alias): ?array => self::getCycleFor($aliases, $alias), array_keys($aliases) )); diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index e9c011eb..dd8ee808 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -17,10 +17,7 @@ */ class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface { - /** - * @param mixed $initializer - */ - public static function fromInvalidInitializer($initializer): self + public static function fromInvalidInitializer(mixed $initializer): self { return new self(sprintf( 'An invalid initializer was registered. Expected a callable or an' @@ -30,10 +27,7 @@ public static function fromInvalidInitializer($initializer): self )); } - /** - * @param mixed $abstractFactory - */ - public static function fromInvalidAbstractFactory($abstractFactory): self + public static function fromInvalidAbstractFactory(mixed $abstractFactory): self { return new self(sprintf( 'An invalid abstract factory was registered. Expected an instance of or a valid' diff --git a/src/InitializerInterface.php b/src/InitializerInterface.php index f092e763..dc29dd6f 100644 --- a/src/InitializerInterface.php +++ b/src/InitializerInterface.php @@ -29,8 +29,7 @@ interface InitializerInterface extends Initializer\InitializerInterface /** * Initialize * - * @param mixed $instance * @return mixed */ - public function initialize($instance, ServiceLocatorInterface $serviceLocator); + public function initialize(mixed $instance, ServiceLocatorInterface $serviceLocator); } diff --git a/src/PluginManagerInterface.php b/src/PluginManagerInterface.php index f0d1540b..cb82d4e6 100644 --- a/src/PluginManagerInterface.php +++ b/src/PluginManagerInterface.php @@ -19,12 +19,11 @@ interface PluginManagerInterface extends ServiceLocatorInterface /** * Validate an instance * - * @param mixed $instance * @return void * @throws InvalidServiceException If created instance does not respect the * constraint on type imposed by the plugin manager. * @throws ContainerExceptionInterface If any other error occurs. * @psalm-assert InstanceType $instance */ - public function validate($instance); + public function validate(mixed $instance); } diff --git a/src/Proxy/LazyServiceFactory.php b/src/Proxy/LazyServiceFactory.php index a873e8c7..65b04465 100644 --- a/src/Proxy/LazyServiceFactory.php +++ b/src/Proxy/LazyServiceFactory.php @@ -21,19 +21,12 @@ */ final class LazyServiceFactory implements DelegatorFactoryInterface { - private LazyLoadingValueHolderFactory $proxyFactory; - - /** @var array map of service names to class names */ - private array $servicesMap; - /** * @param array $servicesMap A map of service names to * class names of their respective classes */ - public function __construct(LazyLoadingValueHolderFactory $proxyFactory, array $servicesMap) + public function __construct(private LazyLoadingValueHolderFactory $proxyFactory, private array $servicesMap) { - $this->proxyFactory = $proxyFactory; - $this->servicesMap = $servicesMap; } /** @@ -45,7 +38,7 @@ public function __construct(LazyLoadingValueHolderFactory $proxyFactory, array $ public function __invoke(ContainerInterface $container, $name, callable $callback, ?array $options = null) { if (isset($this->servicesMap[$name])) { - $initializer = function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($callback) { + $initializer = static function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($callback): bool { $proxy->setProxyInitializer(null); $wrappedInstance = $callback(); diff --git a/src/ServiceManager.php b/src/ServiceManager.php index 647d978e..3947c25e 100644 --- a/src/ServiceManager.php +++ b/src/ServiceManager.php @@ -157,7 +157,6 @@ class ServiceManager implements ServiceLocatorInterface * See {@see \Laminas\ServiceManager\ServiceManager::configure()} for details * on what $config accepts. * - * @param array $config * @psalm-param ServiceManagerConfiguration $config */ public function __construct(array $config = []) @@ -285,7 +284,6 @@ public function getAllowOverride() } /** - * @param array $config * @psalm-param ServiceManagerConfiguration $config * @return self * @throws ContainerModificationsNotAllowedException If the allow diff --git a/src/Tool/ConfigDumper.php b/src/Tool/ConfigDumper.php index 6e7d99ec..6dd6b7f6 100644 --- a/src/Tool/ConfigDumper.php +++ b/src/Tool/ConfigDumper.php @@ -39,15 +39,11 @@ class ConfigDumper return %s; EOC; - private ?ContainerInterface $container; - - public function __construct(?ContainerInterface $container = null) + public function __construct(private ?ContainerInterface $container = null) { - $this->container = $container; } /** - * @param array $config * @param string $className * @param bool $ignoreUnresolved * @return array @@ -127,7 +123,6 @@ private function validateClassName($className) } /** - * @param array $config * @param string $className * @return array */ @@ -138,7 +133,6 @@ private function createInvokable(array $config, $className) } /** - * @param array $config * @return array * @throws InvalidArgumentException If ConfigAbstractFactory configuration * value is not an array. @@ -164,7 +158,6 @@ public function createFactoryMappingsFromConfig(array $config) } /** - * @param array $config * @param string $className * @return array */ @@ -185,7 +178,6 @@ public function createFactoryMappings(array $config, $className) } /** - * @param array $config * @return string */ public function dumpConfigFile(array $config) @@ -245,11 +237,10 @@ private function createConfigKey($key) } /** - * @param mixed $value * @param int $indentLevel * @return string */ - private function createConfigValue($value, $indentLevel) + private function createConfigValue(mixed $value, $indentLevel) { if (is_array($value) || $value instanceof Traversable) { return $this->prepareConfig($value, $indentLevel + 1); diff --git a/src/Tool/ConfigDumperCommand.php b/src/Tool/ConfigDumperCommand.php index 6ce1fda8..f9747868 100644 --- a/src/Tool/ConfigDumperCommand.php +++ b/src/Tool/ConfigDumperCommand.php @@ -68,15 +68,12 @@ class ConfigDumperCommand private ConsoleHelper $helper; - private string $scriptName; - /** * @param string $scriptName */ - public function __construct($scriptName = self::DEFAULT_SCRIPT_NAME, ?ConsoleHelper $helper = null) + public function __construct(private $scriptName = self::DEFAULT_SCRIPT_NAME, ?ConsoleHelper $helper = null) { - $this->scriptName = $scriptName; - $this->helper = $helper ?: new ConsoleHelper(); + $this->helper = $helper ?: new ConsoleHelper(); } /** @@ -128,7 +125,6 @@ public function __invoke(array $args) } /** - * @param array $args * @return object */ private function parseArgs(array $args) diff --git a/src/Tool/FactoryCreator.php b/src/Tool/FactoryCreator.php index 0e9b24df..6abcbf69 100644 --- a/src/Tool/FactoryCreator.php +++ b/src/Tool/FactoryCreator.php @@ -100,7 +100,7 @@ private function getConstructorParameters($className) $constructorParameters = array_filter( $constructorParameters, - function (ReflectionParameter $argument): bool { + static function (ReflectionParameter $argument): bool { if ($argument->isOptional()) { return false; } @@ -124,7 +124,7 @@ function (ReflectionParameter $argument): bool { return []; } - return array_map(function (ReflectionParameter $parameter): ?string { + return array_map(static function (ReflectionParameter $parameter): ?string { $type = $parameter->getType(); return $type instanceof ReflectionNamedType && ! $type->isBuiltin() ? $type->getName() : null; }, $constructorParameters); @@ -136,7 +136,7 @@ function (ReflectionParameter $argument): bool { */ private function createArgumentString($className) { - $arguments = array_map(fn(string $dependency): string + $arguments = array_map(static fn(string $dependency): string => sprintf('$container->get(\\%s::class)', $dependency), $this->getConstructorParameters($className)); switch (count($arguments)) { diff --git a/src/Tool/FactoryCreatorCommand.php b/src/Tool/FactoryCreatorCommand.php index ec6c1fc6..a89df165 100644 --- a/src/Tool/FactoryCreatorCommand.php +++ b/src/Tool/FactoryCreatorCommand.php @@ -45,15 +45,12 @@ class FactoryCreatorCommand private ConsoleHelper $helper; - private string $scriptName; - /** * @param string $scriptName */ - public function __construct($scriptName = self::DEFAULT_SCRIPT_NAME, ?ConsoleHelper $helper = null) + public function __construct(private $scriptName = self::DEFAULT_SCRIPT_NAME, ?ConsoleHelper $helper = null) { - $this->scriptName = $scriptName; - $this->helper = $helper ?: new ConsoleHelper(); + $this->helper = $helper ?: new ConsoleHelper(); } /** @@ -98,7 +95,6 @@ public function __invoke(array $args) } /** - * @param array $args * @return ArgumentObject */ private function parseArgs(array $args) diff --git a/test/AbstractFactory/TestAsset/ClassAcceptingConfigToConstructor.php b/test/AbstractFactory/TestAsset/ClassAcceptingConfigToConstructor.php index e505d633..c00d6ac8 100644 --- a/test/AbstractFactory/TestAsset/ClassAcceptingConfigToConstructor.php +++ b/test/AbstractFactory/TestAsset/ClassAcceptingConfigToConstructor.php @@ -6,10 +6,7 @@ final class ClassAcceptingConfigToConstructor { - public array $config; - - public function __construct(array $config) + public function __construct(public array $config) { - $this->config = $config; } } diff --git a/test/AbstractFactory/TestAsset/ClassAcceptingWellKnownServicesAsConstructorParameters.php b/test/AbstractFactory/TestAsset/ClassAcceptingWellKnownServicesAsConstructorParameters.php index 846dfdd0..c3c2a68d 100644 --- a/test/AbstractFactory/TestAsset/ClassAcceptingWellKnownServicesAsConstructorParameters.php +++ b/test/AbstractFactory/TestAsset/ClassAcceptingWellKnownServicesAsConstructorParameters.php @@ -6,10 +6,7 @@ final class ClassAcceptingWellKnownServicesAsConstructorParameters { - public ValidatorPluginManager $validators; - - public function __construct(ValidatorPluginManager $validators) + public function __construct(public ValidatorPluginManager $validators) { - $this->validators = $validators; } } diff --git a/test/AbstractFactory/TestAsset/ClassWithMixedConstructorParameters.php b/test/AbstractFactory/TestAsset/ClassWithMixedConstructorParameters.php index e66dedd5..dcff6578 100644 --- a/test/AbstractFactory/TestAsset/ClassWithMixedConstructorParameters.php +++ b/test/AbstractFactory/TestAsset/ClassWithMixedConstructorParameters.php @@ -6,23 +6,11 @@ final class ClassWithMixedConstructorParameters { - public array $config; - - public SampleInterface $sample; - - public ValidatorPluginManager $validators; - - public ?array $options; - public function __construct( - array $config, - SampleInterface $sample, - ValidatorPluginManager $validators, - ?array $options = null + public array $config, + public SampleInterface $sample, + public ValidatorPluginManager $validators, + public ?array $options = null ) { - $this->config = $config; - $this->sample = $sample; - $this->validators = $validators; - $this->options = $options; } } diff --git a/test/AbstractFactory/TestAsset/ClassWithScalarDependencyDefiningDefaultValue.php b/test/AbstractFactory/TestAsset/ClassWithScalarDependencyDefiningDefaultValue.php index 63c76806..063a55cb 100644 --- a/test/AbstractFactory/TestAsset/ClassWithScalarDependencyDefiningDefaultValue.php +++ b/test/AbstractFactory/TestAsset/ClassWithScalarDependencyDefiningDefaultValue.php @@ -6,10 +6,7 @@ final class ClassWithScalarDependencyDefiningDefaultValue { - public string $foo; - - public function __construct(string $foo = 'bar') + public function __construct(public string $foo = 'bar') { - $this->foo = $foo; } } diff --git a/test/AbstractFactory/TestAsset/ClassWithScalarParameters.php b/test/AbstractFactory/TestAsset/ClassWithScalarParameters.php index 95ea25a4..74f902ee 100644 --- a/test/AbstractFactory/TestAsset/ClassWithScalarParameters.php +++ b/test/AbstractFactory/TestAsset/ClassWithScalarParameters.php @@ -6,13 +6,7 @@ final class ClassWithScalarParameters { - public string $foo = 'foo'; - - public string $bar = 'bar'; - - public function __construct(string $foo, string $bar) + public function __construct(public string $foo, public string $bar) { - $this->foo = $foo; - $this->bar = $bar; } } diff --git a/test/AbstractFactory/TestAsset/ClassWithTypeHintedConstructorParameter.php b/test/AbstractFactory/TestAsset/ClassWithTypeHintedConstructorParameter.php index e5ba91e3..fcce2516 100644 --- a/test/AbstractFactory/TestAsset/ClassWithTypeHintedConstructorParameter.php +++ b/test/AbstractFactory/TestAsset/ClassWithTypeHintedConstructorParameter.php @@ -6,10 +6,7 @@ final class ClassWithTypeHintedConstructorParameter { - public SampleInterface $sample; - - public function __construct(SampleInterface $sample) + public function __construct(public SampleInterface $sample) { - $this->sample = $sample; } } diff --git a/test/AbstractPluginManagerTest.php b/test/AbstractPluginManagerTest.php index 2caaff93..2410f93d 100644 --- a/test/AbstractPluginManagerTest.php +++ b/test/AbstractPluginManagerTest.php @@ -265,10 +265,9 @@ public function invalidConstructorArguments(): array /** * @group migration - * @param mixed $arg * @dataProvider invalidConstructorArguments */ - public function testPassingNonContainerNonConfigNonNullFirstConstructorArgumentRaisesException($arg): void + public function testPassingNonContainerNonConfigNonNullFirstConstructorArgumentRaisesException(mixed $arg): void { $this->expectException(InvalidArgumentException::class); new TestAsset\LenientPluginManager($arg); diff --git a/test/CommonServiceLocatorBehaviorsTrait.php b/test/CommonServiceLocatorBehaviorsTrait.php index eec5ee41..e8a4e276 100644 --- a/test/CommonServiceLocatorBehaviorsTrait.php +++ b/test/CommonServiceLocatorBehaviorsTrait.php @@ -436,9 +436,8 @@ public function abstractFactories(): array /** * @group has * @dataProvider abstractFactories - * @param mixed $abstractFactory */ - public function testHasChecksAgainstAbstractFactories($abstractFactory, bool $expected): void + public function testHasChecksAgainstAbstractFactories(mixed $abstractFactory, bool $expected): void { $serviceManager = $this->createContainer([ 'abstract_factories' => [ @@ -572,11 +571,10 @@ public function invalidAbstractFactories(): array /** * @dataProvider invalidAbstractFactories - * @param mixed $factory * @covers \Laminas\ServiceManager\ServiceManager::configure */ public function testPassingInvalidAbstractFactoryTypeViaConfigurationRaisesException( - $factory, + mixed $factory, string $contains = 'invalid abstract factory' ): void { $this->expectException(InvalidArgumentException::class); @@ -617,11 +615,10 @@ public function invalidInitializers(): array /** * @dataProvider invalidInitializers - * @param mixed $initializer * @covers \Laminas\ServiceManager\ServiceManager::configure */ public function testPassingInvalidInitializerTypeViaConfigurationRaisesException( - $initializer, + mixed $initializer, string $contains = 'invalid initializer' ): void { $this->expectException(InvalidArgumentException::class); @@ -651,12 +648,11 @@ public function invalidDelegators(): array } /** - * @param mixed $delegator * @dataProvider invalidDelegators * @covers \Laminas\ServiceManager\ServiceManager::createDelegatorFromName */ public function testInvalidDelegatorShouldRaiseExceptionDuringCreation( - $delegator, + mixed $delegator, string $contains = 'non-callable delegator' ): void { /** @psalm-suppress InvalidArgument */ @@ -859,7 +855,7 @@ public function methodsAffectedByOverrideSettings(): array 'setFactory', [ 'foo', - function () { + static function (): void { }, ], ], @@ -870,7 +866,7 @@ function () { 'addDelegator', [ 'foo', - function () { + static function (): void { }, ], ], diff --git a/test/Proxy/LazyServiceFactoryTest.php b/test/Proxy/LazyServiceFactoryTest.php index 757ff425..a8227cb0 100644 --- a/test/Proxy/LazyServiceFactoryTest.php +++ b/test/Proxy/LazyServiceFactoryTest.php @@ -87,7 +87,7 @@ public function testCreates(): void ->expects(self::once()) ->method('createProxy') ->willReturnCallback( - static function ($className, $initializer) use ($expectedService, $proxy) { + static function ($className, $initializer) use ($expectedService, $proxy): MockObject { self::assertEquals('FooClass', $className, 'class name not match'); $wrappedInstance = null; diff --git a/test/ServiceManagerContainerInteropIntegrationTest.php b/test/ServiceManagerContainerInteropIntegrationTest.php index 815146dd..a4f54ac7 100644 --- a/test/ServiceManagerContainerInteropIntegrationTest.php +++ b/test/ServiceManagerContainerInteropIntegrationTest.php @@ -15,8 +15,7 @@ final class ServiceManagerContainerInteropIntegrationTest extends TestCase { - /** @var ServiceManager */ - private $container; + private ServiceManager $container; protected function setUp(): void { diff --git a/test/ServiceManagerTest.php b/test/ServiceManagerTest.php index 7346898b..d63eb116 100644 --- a/test/ServiceManagerTest.php +++ b/test/ServiceManagerTest.php @@ -17,8 +17,6 @@ use Psr\Container\ContainerInterface; use stdClass; -use function get_class; - /** * @see ConfigInterface * @@ -399,7 +397,7 @@ public function testFactoryMayBeStaticMethodDescribedByCallableString(): void ]; $serviceManager = new SimpleServiceManager($config); - self::assertEquals(stdClass::class, get_class($serviceManager->get(stdClass::class))); + self::assertEquals(stdClass::class, $serviceManager->get(stdClass::class)::class); } public function testResolvedAliasFromAbstractFactory(): void