PHPackages                             dpanta94/phpstan-containers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. dpanta94/phpstan-containers

ActivePhpstan-extension[PSR &amp; Standards](/categories/psr-standards)

dpanta94/phpstan-containers
===========================

PHPStan extensions for Containers

0.1.0(5mo ago)016.4k↓39.1%MITPHPPHP ^7.4 || ^8.0CI passing

Since Dec 11Pushed 5mo agoCompare

[ Source](https://github.com/dpanta94/phpstan-containers)[ Packagist](https://packagist.org/packages/dpanta94/phpstan-containers)[ RSS](/packages/dpanta94-phpstan-containers/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

PHPStan Container Extensions
============================

[](#phpstan-container-extensions)

[![PHPStan](https://camo.githubusercontent.com/c961f520ec74aa0d9e60565e511aebb1c4930b5a0ea635e9be3e99bf562be287/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d323339393232)](https://github.com/phpstan/phpstan)

PHPStan extensions for dependency injection containers. Provides dynamic return type resolution so PHPStan understands that `$container->get(Foo::class)` returns `Foo`.

Supported Containers
--------------------

[](#supported-containers)

- [StellarWP Container Contract](https://github.com/stellarwp/container-contract) (`StellarWP\ContainerContract\ContainerInterface`)
- [PSR-11 Container](https://www.php-fig.org/psr/psr-11/) (`Psr\Container\ContainerInterface`)

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- PHPStan 2.0 or higher

Installation
------------

[](#installation)

```
composer require --dev dpanta94/phpstan-containers
```

If you use [phpstan/extension-installer](https://github.com/phpstan/extension-installer), you're all set!

### Manual Installation

[](#manual-installation)

If you don't use the extension installer, add the extension to your `phpstan.neon`:

```
includes:
    - vendor/dpanta94/phpstan-containers/extension.neon
```

Usage
-----

[](#usage)

Once installed, PHPStan will automatically understand container return types:

```
use Psr\Container\ContainerInterface;

class MyService {
    public function __construct(private ContainerInterface $container) {}

    public function doSomething(): void {
        // PHPStan knows $logger is an instance of Logger
        $logger = $this->container->get(Logger::class);
        $logger->info('Hello world');

        // PHPStan knows $mailer is an instance of MailerInterface
        $mailer = $this->container->get(MailerInterface::class);
        $mailer->send($message);
    }
}
```

The extension resolves types when:

- The argument to `get()` is a class-string constant (e.g., `Foo::class`)
- The class or interface exists in the codebase

When using string service IDs (e.g., `$container->get('mailer')`), the extension falls back to the default `mixed` return type.

License
-------

[](#license)

MIT

Credits
-------

[](#credits)

This package is inspired by [Phil Nelson](https://github.com/phil-nelson)'s [phpstan-container-extension](https://packagist.org/packages/phil-nelson/phpstan-container-extension).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance72

Regular maintenance activity

Popularity28

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

158d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/70a2847a265444714b48c64eceb3ca742baa3a56757ce65b18bd7bbbbf910312?d=identicon)[dpanta94](/maintainers/dpanta94)

---

Top Contributors

[![dpanta94](https://avatars.githubusercontent.com/u/29694484?v=4)](https://github.com/dpanta94 "dpanta94 (13 commits)")

---

Tags

containerPSR-11PHPStanstatic analysisdependency-injectioncode analysiscode analyze

###  Code Quality

TestsPHPUnit

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dpanta94-phpstan-containers/health.svg)

```
[![Health](https://phpackages.com/badges/dpanta94-phpstan-containers/health.svg)](https://phpackages.com/packages/dpanta94-phpstan-containers)
```

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
