Symfony extension for PHPStan
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 4 commits behind phpstan:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.coveralls.yml
.editorconfig
.gitattributes
.gitignore
.travis.yml
LICENSE
README.md
build.xml
composer.json
extension.neon
phpcs.xml
phpstan.neon

README.md

PHPStan Symfony Framework extensions and rules

Build Status Latest Stable Version License

This extension provides following features:

  • Provides correct return type for ContainerInterface::get() and ::has() methods.
  • Provides correct return type for Controller::get() and ::has() methods.
  • Provides correct return type for Request::getContent() method based on the $asResource parameter.
  • Notifies you when you try to get an unregistered service from the container.
  • Notifies you when you try to get a private service from the container.

Usage

To use this extension, require it in Composer:

composer require --dev phpstan/phpstan-symfony

And include extension.neon in your project's PHPStan config:

includes:
	- vendor/phpstan/phpstan-symfony/extension.neon
parameters:
	symfony:
		container_xml_path: %rootDir%/../../../var/cache/dev/srcDevDebugProjectContainer.xml

You have to provide a path to srcDevDebugProjectContainer.xml or similar xml file describing your container.

Constant hassers

Sometimes, when you are dealing with optional dependencies, the ::has() methods can cause problems. For example, the following construct would complain that the condition is always either on or off, depending on whether you have the dependency for service installed:

if ($this->has('service')) {
    // ...
}

In that case, you can disable the ::has() method return type resolving like this:

parameters:
	symfony:
		constant_hassers: false

Be aware that it may hide genuine errors in your application.