symplify/phpstan-extensions

This package is abandoned and no longer maintained. The author suggests using the symplify/phpstan-rules package instead.

Pre-escaped error messages in 'symplify' error format, container aware test case and other useful extensions for PHPStan

Maintainers

👁 TomasVotruba

Package info

github.com/symplify/phpstan-extensions

Type:phpstan-extension

pkg:composer/symplify/phpstan-extensions

Statistics

Installs: 6 616 925

Dependents: 107

Suggesters: 2

Stars: 39

Open Issues: 1

12.0.2 2025-11-12 16:46 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 5ce15cb084eb3bc7f92b77020c59ff3d318746d5

static analysisphpstan-extension

This package is auto-updated.

Last update: 2026-06-09 14:00:15 UTC


README

👁 Downloads total


Install

composer require symplify/phpstan-extensions --dev

Symplify Error Formatter

Update your phpstan.neon config:

parameters:
 errorFormat: symplify
  • Do you want to click the error and get right to the line in the file it's reported at?
  • Do you want to copy-paste regex escaped error to your ignoreErrors?

Works best with anthraxx/intellij-awesome-console

vendor/bin/phpstan analyse src

------------------------------------------------------------------------------------------
src/Command/ReleaseCommand.php:51
------------------------------------------------------------------------------------------
- "Call to an undefined method Symplify\\Command\\ReleaseCommand\:\:nonExistingCall\(\)"
------------------------------------------------------------------------------------------

Improved Symfony Types

ContainerGetTypeExtension

With Symfony container and type as an argument, you always know the same type is returned:

use Symfony\Component\DependencyInjection\Container;

/** @var Container $container */
// PHPStan: object ❌
$container->get(Type::class);
// Reality: Type ✅
$container->get(Type::class);

// same for in-controller/container-aware context
$this->get(Type::class);

KernelGetContainerAfterBootReturnTypeExtension

After Symfony Kernel boot, getContainer() always returns the container:

use Symfony\Component\HttpKernel\Kernel;

final class AppKernel extends Kernel
{
 // ...
}

$kernel = new AppKernel('prod', false);
$kernel->boot();

// PHPStan: null|ContainerInterface ❌
$kernel->getContainer();
// Reality: ContainerInterface ✅
$kernel->getContainer();
// Reality: ContainerInterface ✅

SplFileInfoTolerantReturnTypeExtension

Symfony Finder finds only existing files (obviously), so the getRealPath() always return string:

use Symfony\Component\Finder\Finder;

$finder = new Finder();

foreach ($finder as $fileInfo) {
 // PHPStan: false|string ❌
 $fileInfo->getRealPath();
 // Reality: string ✅
 $fileInfo->getRealPath();
}

Happy coding!