fcpl/phpstan-container-extension

PHPStan 扩展,用于解决 PSR-11 容器(Psr\Container\ContainerInterface)和 Pimple 容器(ArrayAccess)的返回类型

安装数: 14,120

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 0

分支: 1

类型:phpstan-extension

v1.0.0 2022-08-31 18:41 UTC

This package is auto-updated.

Last update: 2024-08-29 06:13:05 UTC


README

这是一个为 PHPStan 扩展创建的扩展,用于解决 PSR-11 容器(Psr\Container\ContainerInterface)和 Pimple 容器(ArrayAccess)的返回类型

此包基于 phil-nelson/phpstan-container-extension

安装

使用以下命令安装

composer require --dev fcpl/phpstan-container-extension

extension.neon 文件添加到您的 PHPStan 配置中

includes:
  - vendor/fcpl/phpstan-container-extension/extension.neon

或者使用 phpstan/extension-installer

示例

use Monolog\Handler\HandlerInterface;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Pimple\Container;
use Pimple\Psr11\ServiceLocator;
use Psr\Log\LoggerInterface;
...
    $container = new Container();
    $container->offsetSet(HandlerInterface::class, new StreamHandler($this->getLogFile()));
    $container->offsetSet(
        LoggerInterface::class,
        function (Container $container): Logger {
            /** @var HandlerInterface $streamHandler */
            $streamHandler = $container->offsetGet(HandlerInterface::class);
            return new Logger(self::class, [$streamHandler]);
        }
    );
    return new ServiceLocator($container, [LoggerInterface::class, ConverterFileInterface::class]);
...

许可协议

本包所有内容均受 MIT 许可协议 许可。