aicrion/container-phpstan

PHPStan extension providing accurate type inference for Aicrion\Container resolution methods.

Maintainers

Package info

github.com/Aicrion/container-phpstan

Homepage

Type:phpstan-extension

pkg:composer/aicrion/container-phpstan

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2026-07-31 01:10 UTC

This package is auto-updated.

Last update: 2026-07-31 01:18:41 UTC


README

PHPStan extension that teaches static analysis the real return type of Aicrion\Container\Container::make() and ::get() calls, so tools like PHPStan can catch type errors in code that resolves services from the container.

Why this exists

Container::make() and Container::get() are declared with a mixed return type, since the container can resolve any registered service id at runtime. Without this extension, PHPStan sees:

$logger = $container->make(LoggerInterface::class);
$logger->nonExistentMethod(); // PHPStan: no error, because $logger is `mixed`

With this extension installed, PHPStan instead infers the real class:

$logger = $container->make(LoggerInterface::class);
// PHPStan now knows $logger is LoggerInterface
$logger->nonExistentMethod(); // PHPStan: Call to undefined method LoggerInterface::nonExistentMethod()

Installation

composer require --dev aicrion/container-phpstan

If you use phpstan/extension-installer (recommended), the extension is activated automatically. Otherwise, add it manually to your phpstan.neon:

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

Supported patterns

// Class constant -- fully supported
$service = $container->make(PaymentService::class);

// String literal -- fully supported
$service = $container->make('App\PaymentService');

// Dynamic string (variable, concatenation, etc.) -- falls back to the
// declared `mixed` return type, since PHPStan cannot know the value
// at analysis time.
$id = $this->resolveServiceId();
$service = $container->make($id);

Requirements

  • PHP 8.5+
  • aicrion/container ^1.0
  • phpstan/phpstan ^2.0

License

MIT