fcpl / phpstan-container-extension
PHPStan extension to resolve return type for PSR-11 container (Psr\Container\ContainerInterface) and Pimple Container (ArrayAccess)
Installs: 15 005
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 1
Type:phpstan-extension
Requires
- php: ^7.3 || ^8.0 || ^8.1
- phpstan/phpstan: ^1.0
- psr/container: ^1.0 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
This is an extension for PHPStan extension to resolve return type for PSR-11 container (Psr\Container\ContainerInterface) and Pimple Container (ArrayAccess)
This pacckage based on phil-nelson/phpstan-container-extension
Installation
Install with:
composer require --dev fcpl/phpstan-container-extension
Add the extension.neon
file to your PHPStan config:
includes:
- vendor/fcpl/phpstan-container-extension/extension.neon
Or use phpstan/extension-installer
Sample
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]); ...
License
All contents of this package are licensed under the MIT license.