All Projects → phpstan → Phpstan Symfony

phpstan / Phpstan Symfony

Licence: mit
Symfony extension for PHPStan

Projects that are alternatives of or similar to Phpstan Symfony

Semgrep
Lightweight static analysis for many languages. Find bug variants with patterns that look like source code.
Stars: ✭ 5,668 (+1474.44%)
Mutual labels:  static-analysis, static-code-analysis
Chronos
Chronos - A static race detector for the go language
Stars: ✭ 272 (-24.44%)
Mutual labels:  static-analysis, static-code-analysis
qodana-action
⚙️ Scan your Java, Kotlin, PHP, Python, JavaScript, TypeScript projects at GitHub with Qodana
Stars: ✭ 112 (-68.89%)
Mutual labels:  static-code-analysis, static-analysis
Phpstan Doctrine
Doctrine extensions for PHPStan
Stars: ✭ 338 (-6.11%)
Mutual labels:  static-analysis, static-code-analysis
Reviewdog
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language
Stars: ✭ 4,541 (+1161.39%)
Mutual labels:  static-analysis, static-code-analysis
static-code-analysis-plugin
A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Stars: ✭ 36 (-90%)
Mutual labels:  static-code-analysis, static-analysis
codeclimate-duplication
Code Climate engine for code duplication analysis
Stars: ✭ 96 (-73.33%)
Mutual labels:  static-code-analysis, static-analysis
analysis-model
A library to read static analysis reports into a Java object model
Stars: ✭ 74 (-79.44%)
Mutual labels:  static-code-analysis, static-analysis
Phpstan Strict Rules
Extra strict and opinionated rules for PHPStan
Stars: ✭ 295 (-18.06%)
Mutual labels:  static-analysis, static-code-analysis
Sonar Php
🐘 SonarPHP: PHP static analyzer for SonarQube & SonarLint
Stars: ✭ 288 (-20%)
Mutual labels:  static-analysis, static-code-analysis
codeclimate-eslint
Code Climate Engine for ESLint
Stars: ✭ 86 (-76.11%)
Mutual labels:  static-code-analysis, static-analysis
Pylint
It's not just a linter that annoys you!
Stars: ✭ 3,733 (+936.94%)
Mutual labels:  static-analysis, static-code-analysis
codeclimate-phpcodesniffer
Code Climate Engine for PHP Code Sniffer
Stars: ✭ 27 (-92.5%)
Mutual labels:  static-code-analysis, static-analysis
analysis-net
Static analysis framework for .NET programs.
Stars: ✭ 19 (-94.72%)
Mutual labels:  static-code-analysis, static-analysis
OpenStaticAnalyzer
OpenStaticAnalyzer is a source code analyzer tool, which can perform deep static analysis of the source code of complex systems.
Stars: ✭ 19 (-94.72%)
Mutual labels:  static-code-analysis, static-analysis
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-66.94%)
Mutual labels:  static-code-analysis, static-analysis
nakedret
nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length.
Stars: ✭ 82 (-77.22%)
Mutual labels:  static-code-analysis, static-analysis
eba
EBA is a static bug finder for C.
Stars: ✭ 14 (-96.11%)
Mutual labels:  static-code-analysis, static-analysis
Nullaway
A tool to help eliminate NullPointerExceptions (NPEs) in your Java code with low build-time overhead
Stars: ✭ 3,035 (+743.06%)
Mutual labels:  static-analysis, static-code-analysis
Pytype
A static type analyzer for Python code
Stars: ✭ 3,545 (+884.72%)
Mutual labels:  static-analysis, static-code-analysis

PHPStan Symfony Framework extensions and rules

Build 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.
  • Provides correct return type for HeaderBag::get() method based on the $first parameter.
  • Provides correct return type for Envelope::all() method based on the $stampFqcn parameter.
  • Provides correct return types for TreeBuilder and NodeDefinition objects.
  • 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.
  • Optionally correct return types for InputInterface::getArgument(), ::getOption, ::hasArgument, and ::hasOption.

Installation

To use this extension, require it in Composer:

composer require --dev phpstan/phpstan-symfony

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/phpstan/phpstan-symfony/extension.neon

To perform framework-specific checks, include also this file:

includes:
    - vendor/phpstan/phpstan-symfony/rules.neon

Configuration

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

parameters:
    symfony:
        container_xml_path: var/cache/dev/srcDevDebugProjectContainer.xml
        # or with Symfony 4.2+
        container_xml_path: var/cache/dev/srcApp_KernelDevDebugContainer.xml
        # or with Symfony 5+
        container_xml_path: var/cache/dev/App_KernelDevDebugContainer.xml

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.

Console command analysis

You can opt in for more advanced analysis by providing the console application from your own application. This will allow the correct argument and option types to be inferred when accessing $input->getArgument() or $input->getOption().

parameters:
	symfony:
		console_application_loader: tests/console-application.php

For example, in a Symfony project, console-application.php would look something like this:

require __DIR__.'/../config/bootstrap.php';
$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
return new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);

You may then encounter an error with PhpParser:

Compile Error: Cannot Declare interface PhpParser\NodeVisitor, because the name is already in use

If this is the case, you should create a new environment for your application that will disable inlining. In config/packages/phpstan_env/parameters.yaml:

parameters:
    container.dumper.inline_class_loader: false

Call the new env in your console-application.php:

$kernel = new \App\Kernel('phpstan_env', (bool) $_SERVER['APP_DEBUG']);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].