diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 3567d9d1..ffddff3b 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + new $requestedName(...$arguments) @@ -405,7 +405,7 @@ $names[$name] $object[$shared ? $method : 'build'] - + $callSequence $first $idx1 @@ -502,9 +502,6 @@ $autoload - - $instance - assertIsArray assertIsArray diff --git a/src/AbstractPluginManager.php b/src/AbstractPluginManager.php index 21128a98..8b5569a5 100644 --- a/src/AbstractPluginManager.php +++ b/src/AbstractPluginManager.php @@ -32,6 +32,8 @@ * The implementation extends `ServiceManager`, thus providing the same set * of capabilities as found in that implementation. * + * @template InstanceType of object + * @implements PluginManagerInterface * @psalm-import-type ServiceManagerConfiguration from ServiceManager * @psalm-suppress PropertyNotSetInConstructor */ @@ -48,7 +50,7 @@ abstract class AbstractPluginManager extends ServiceManager implements PluginMan * An object type that the created instance must be instanced of * * @var null|string - * @psalm-var null|class-string + * @psalm-var null|class-string */ protected $instanceOf; @@ -131,6 +133,10 @@ public function configure(array $config) * Override setService for additional plugin validation. * * {@inheritDoc} + * + * @param string|class-string $name + * @param InstanceType $service + * @psalm-suppress MoreSpecificImplementedParamType */ public function setService($name, $service) { @@ -139,9 +145,10 @@ public function setService($name, $service) } /** - * @param string $name Service name of plugin to retrieve. + * @param class-string|string $name Service name of plugin to retrieve. * @param null|array $options Options to use when creating the instance. * @return mixed + * @psalm-return ($name is class-string ? InstanceType : mixed) * @throws Exception\ServiceNotFoundException If the manager does not have * a service definition for the instance, and the service is not * auto-invokable. @@ -162,7 +169,6 @@ public function get($name, ?array $options = null) $this->setFactory($name, Factory\InvokableFactory::class); } - /** @psalm-suppress MixedAssignment */ $instance = ! $options ? parent::get($name) : $this->build($name, $options); $this->validate($instance); return $instance; @@ -170,6 +176,8 @@ public function get($name, ?array $options = null) /** * {@inheritDoc} + * + * @psalm-assert InstanceType $instance */ public function validate($instance) { diff --git a/src/ServiceLocatorInterface.php b/src/ServiceLocatorInterface.php index 44272f3e..a0dc4600 100644 --- a/src/ServiceLocatorInterface.php +++ b/src/ServiceLocatorInterface.php @@ -15,9 +15,11 @@ interface ServiceLocatorInterface extends ContainerInterface /** * Build a service by its name, using optional options (such services are NEVER cached). * - * @param string $name + * @template T of object + * @param string|class-string $name * @param null|array $options * @return mixed + * @psalm-return ($name is class-string ? T : mixed) * @throws Exception\ServiceNotFoundException If no factory/abstract * factory could be found to create the instance. * @throws Exception\ServiceNotCreatedException If factory/delegator fails