diff --git a/src/Collector/ContainerInterfaceProxy.php b/src/Collector/ContainerInterfaceProxy.php index 2c53f06b..68cdaa45 100644 --- a/src/Collector/ContainerInterfaceProxy.php +++ b/src/Collector/ContainerInterfaceProxy.php @@ -7,6 +7,7 @@ use Exception; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; +use Yiisoft\Proxy\ObjectProxy; use Yiisoft\Proxy\ProxyManager; use Yiisoft\Proxy\ProxyTrait; use Yiisoft\Yii\Debug\ProxyDecoratedCalls; @@ -30,6 +31,9 @@ final class ContainerInterfaceProxy implements ContainerInterface private array $decoratedServices = []; + /** + * @psalm-var array + */ private array $serviceProxy = []; public function __construct( @@ -40,6 +44,9 @@ public function __construct( $this->proxyManager = new ProxyManager($this->config->getProxyCachePath()); } + /** + * @psalm-param array $decoratedServices + */ public function withDecoratedServices(array $decoratedServices): self { $new = clone $this; @@ -108,10 +115,12 @@ private function getServiceProxy(string $service, object $instance): ?object } if ($this->config->hasDecoratedServiceCallableConfig($service)) { + /** @psalm-suppress MixedArgument */ return $this->getServiceProxyFromCallable($this->config->getDecoratedServiceConfig($service), $instance); } if ($this->config->hasDecoratedServiceArrayConfigWithStringKeys($service)) { + /** @psalm-suppress MixedArgument */ return $this->getCommonMethodProxy( interface_exists($service) || class_exists($service) ? $service : $instance::class, $instance, @@ -120,6 +129,7 @@ interface_exists($service) || class_exists($service) ? $service : $instance::cla } if ($this->config->hasDecoratedServiceArrayConfig($service)) { + /** @psalm-suppress MixedArgument */ return $this->getServiceProxyFromArray($instance, $this->config->getDecoratedServiceConfig($service)); } @@ -130,6 +140,9 @@ interface_exists($service) || class_exists($service) ? $service : $instance::cla return null; } + /** + * @psalm-param callable(ContainerInterface, object):(object|null) $callback + */ private function getServiceProxyFromCallable(callable $callback, object $instance): ?object { return $callback($this, $instance); @@ -138,7 +151,7 @@ private function getServiceProxyFromCallable(callable $callback, object $instanc /** * @psalm-param class-string $service */ - private function getCommonMethodProxy(string $service, object $instance, array $callbacks): ?object + private function getCommonMethodProxy(string $service, object $instance, array $callbacks): ObjectProxy { $methods = []; foreach ($callbacks as $method => $callback) { @@ -163,10 +176,11 @@ private function getServiceProxyFromArray(object $instance, array $params): ?obj try { $params[$index] = $this->get($param); } catch (Exception) { - //leave as is + // leave as is } } } + /** @psalm-suppress MixedMethodCall */ return new $proxyClass($instance, ...$params); } catch (Exception) { return null; diff --git a/src/Collector/ContainerProxyConfig.php b/src/Collector/ContainerProxyConfig.php index 969096bd..933cd75e 100644 --- a/src/Collector/ContainerProxyConfig.php +++ b/src/Collector/ContainerProxyConfig.php @@ -7,6 +7,7 @@ use Psr\EventDispatcher\EventDispatcherInterface; use function in_array; +use function is_array; use function is_callable; final class ContainerProxyConfig @@ -64,6 +65,9 @@ public function withCollector(ServiceCollector $collector): self return $config; } + /** + * @psalm-param array $decoratedServices + */ public function withDecoratedServices(array $decoratedServices): self { $config = clone $this;