# phpstan/phpstan

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/phpstan-phpstan).**

13,999 stars · 949 forks · PHP · MIT

## Links

- GitHub: https://github.com/phpstan/phpstan
- Homepage: https://phpstan.org/
- awesome-repositories: https://awesome-repositories.com/repository/phpstan-phpstan.md

## Topics

`php` `php7` `phpstan` `static-analysis` `static-analyzer` `static-code-analysis` `testing`

## Description

This project is a static analysis engine and type checker designed for PHP codebases. It evaluates source code structure and type annotations to identify potential bugs, type mismatches, and logic errors without executing the application. By parsing code into an abstract syntax tree and applying a rule-based validation framework, it enforces code quality and safety standards across a project.

What distinguishes this tool is its sophisticated type inference engine, which models dynamic language features, magic methods, and conditional types to maintain accuracy even in unconventional code. It supports incremental adoption of strictness through baseline management, allowing developers to suppress existing issues while enforcing higher quality standards for new code. The engine also provides deep framework integration, enabling it to recognize and validate patterns specific to popular development ecosystems.

The platform offers a comprehensive suite of capabilities for managing technical debt and ensuring architectural consistency. It includes features for parallel task distribution and result caching to optimize performance on large codebases, as well as extensive configuration options for defining custom validation rules and architectural constraints. Developers can further refine analysis precision through advanced type annotations, custom assertions, and environment simulation.

The tool integrates into development workflows by exporting findings in multiple formats, providing interactive visualizations for error management, and offering direct links to source code locations within local editors.

## Tags

### Development Tools & Productivity

- [Static Analysis Engines](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines.md) — Examines files and directories to identify bugs and type errors without executing the code, returning a status code based on findings. ([source](https://phpstan.org/user-guide/command-line-usage))
- [PHP Development Tools](https://awesome-repositories.com/f/development-tools-productivity/php-development-tools.md) — Provides a framework-agnostic platform for maintaining code quality through incremental analysis and custom validation rules.
- [Static Code Analysis](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines/static-code-analysis.md) — Scans source code to identify potential runtime errors, dead code, and violations of project-specific coding standards.
- [Static Analysis Rules](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines/static-analysis-tools/static-analysis-rules.md) — Customizes the strictness of code checks by defining rule levels, enabling preview features, or creating bespoke rulesets. ([source](https://phpstan.org/config-reference))
- [Analysis Suppression Mechanisms](https://awesome-repositories.com/f/development-tools-productivity/formatting-suppression/analysis-suppression-mechanisms.md) — Excludes particular code issues from the reporting process by referencing their unique identifiers within configuration files or inline source code comments. ([source](https://phpstan.org/error-identifiers))
- [Control Flow Analysis](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis/static-analysis-engines/static-analysis-tools/control-flow-analysis.md) — The static analysis tool marks functions that never return, such as those throwing exceptions or terminating the script, to help the analyzer track code paths. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Regression Analysis Tools](https://awesome-repositories.com/f/development-tools-productivity/debugging-tools/regression-analysis-tools.md) — Performs binary search across tool versions to identify the specific commit that introduced a regression in analysis behavior. ([source](https://phpstan.org/user-guide/command-line-usage))
- [Analysis Result Exporters](https://awesome-repositories.com/f/development-tools-productivity/static-analysis-tools/analysis-result-exporters.md) — Exports findings into various machine-readable or human-friendly formats including JSON, XML, and CI-specific schemas. ([source](https://phpstan.org/user-guide/output-format))

### Testing & Quality Assurance

- [Static Analysis](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis.md) — Identifies potential bugs, type mismatches, and logic errors by scanning source code without execution. ([source](https://phpstan.org/user-guide/troubleshooting-types))
- [Static Code Analysis Tools](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/code-quality-tools/static-code-analysis-tools.md) — Identifies bugs, type mismatches, and logic errors by scanning source code without executing the application.
- [Static Type Inference Engines](https://awesome-repositories.com/f/testing-quality-assurance/static-type-inference-engines.md) — The static analysis tool infers variable, return, or expression types dynamically based on arguments, context, or custom logic to improve analysis accuracy. ([source](https://phpstan.org/developing-extensions/extension-types))
- [Static Analysis Rules](https://awesome-repositories.com/f/testing-quality-assurance/static-analysis-rules.md) — The static analysis tool configures specific methods or functions as execution-terminating to prevent false reports of undefined variables in subsequent code paths. ([source](https://phpstan.org/writing-php-code/solving-undefined-variables))
- [Array Shape Validation](https://awesome-repositories.com/f/testing-quality-assurance/array-shape-validation.md) — Defines strict structures for arrays by specifying required keys, optional keys, and value types for each element. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Strictness Levels](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis/strictness-levels.md) — Adjusts the depth of static code analysis by selecting from multiple cumulative levels to incrementally enforce type safety. ([source](https://phpstan.org/user-guide/getting-started))
- [Analysis Result Dashboards](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis/analysis-result-dashboards.md) — Launches an interactive web interface to browse and manage identified code errors and ignored issues. ([source](https://phpstan.org/user-guide/command-line-usage))
- [Dynamic Behavior Validation](https://awesome-repositories.com/f/testing-quality-assurance/dynamic-behavior-validation.md) — The static analysis tool interprets and validates magic properties and methods created via dynamic class magic to ensure code correctness despite unconventional implementation patterns. ([source](https://phpstan.org/user-guide/extension-library))
- [Analysis Scope Filters](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/static-analysis/analysis-scope-filters.md) — Allows defining specific files and directories to include or exclude from analysis to focus on project code. ([source](https://phpstan.org/config-reference))
- [Constructor Validation Rules](https://awesome-repositories.com/f/testing-quality-assurance/constructor-validation-rules.md) — The static analysis tool identifies custom initialization methods as constructors to prevent false reports of uninitialized properties. ([source](https://phpstan.org/developing-extensions/extension-types))

### Programming Languages & Runtimes

- [Type Safety](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety.md) — Enforces strict type safety and validates complex data structures through advanced type inference and annotations.
- [Type Inference Refinement](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/variable-type-declarations/type-inference-refinement.md) — Analyzes conditional logic and assertions to narrow down variable types for more precise error detection. ([source](https://phpstan.org/writing-php-code/narrowing-types))
- [Static Analysis Modeling](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-execution-environments/runtime-environments/runtimes/type-definition-systems/abstract-classes/abstract-class-implementations/magic-method-implementations/static-analysis-modeling.md) — The static analysis tool exposes dynamically generated properties and methods to the static analyzer to ensure correct type checking for magic behavior. ([source](https://phpstan.org/developing-extensions/extension-types))
- [State Tracking](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/type-aliases/object-aliasing/object-type-restrictions/state-tracking.md) — The static analysis tool updates the inferred type of an object instance after specific methods are called to support mutable generic objects. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Local Variable](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/variable-type-declarations/type-narrowing/local-variable.md) — Refines inferred variable types within function bodies using assertions and inline annotations. ([source](https://phpstan.org/user-guide/troubleshooting-types))
- [Static Analysis Declarations](https://awesome-repositories.com/f/programming-languages-runtimes/magic-method-implementations/static-analysis-declarations.md) — The static analysis tool declares properties and methods that are handled dynamically via magic methods to ensure static analysis recognizes them as valid members. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Advanced Type Annotation Support](https://awesome-repositories.com/f/programming-languages-runtimes/type-annotations/advanced-type-annotation-support.md) — Provides complex type information to the analysis engine using prefixed tags while maintaining IDE compatibility. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Type Narrowing Assertion](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/variable-type-declarations/type-narrowing-assertion.md) — Informs the analysis engine about conditional type changes that occur after specific function or method calls. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Custom Type Constraint Enforcement](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety/type-integrity-enforcement/custom-type-constraint-enforcement.md) — Enforces specific type requirements across function boundaries using documentation annotations. ([source](https://phpstan.org/writing-php-code/narrowing-types))
- [Symbol Type Overriding](https://awesome-repositories.com/f/programming-languages-runtimes/symbol-type-overriding.md) — Refines inferred types for variables, properties, and methods when native typehints are insufficient. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Callable Behavior Descriptions](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/callable-signatures/callable-behavior-descriptions.md) — Specifies the execution timing and scope of closure arguments to ensure accurate analysis of callbacks. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [External Type Definition Overrides](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/external-type-definition-overrides.md) — Corrects imprecise type information in third-party code using custom documentation annotations. ([source](https://phpstan.org/user-guide/stub-files))
- [Type Aliasing](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-definitions/type-aliasing.md) — Creates reusable shorthand names for complex type definitions to simplify documentation and improve consistency. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Collection Type Refinement](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety/static-type-validation/collection-type-refinement.md) — Supplements native typehints with detailed information about array contents, key types, and object instances. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Function Signature Enforcement](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/functional/generic-function-definitions/function-signature-enforcement.md) — Enforces exact parameter and return types for callback functions to ensure they receive the correct data structures. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Conditional Types](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-execution-environments/runtime-environments/runtimes/type-definition-systems/conditional-types.md) — The static analysis tool infers function return types dynamically based on the provided input arguments or logical conditions within the code. ([source](https://phpstan.org/writing-php-code/phpdoc-types))

### Software Engineering & Architecture

- [Framework Integration](https://awesome-repositories.com/f/software-engineering-architecture/framework-integration.md) — Recognizes and validates framework-specific patterns, dependency injection, and dynamic class behaviors in PHP projects.
- [PHP Type Checkers](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/php-type-checkers.md) — Enforces strict type safety and validates complex data structures using advanced type inference and annotations.
- [Type Inference Engines](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling/type-inference-engines.md) — Calculates and propagates variable types through the codebase by evaluating expressions, assertions, and annotations.
- [Baseline Management](https://awesome-repositories.com/f/software-engineering-architecture/baseline-management.md) — Creates configuration files containing existing errors to ignore them in future runs, allowing for incremental adoption of stricter rules. ([source](https://phpstan.org/user-guide/command-line-usage))
- [Custom Rule Development](https://awesome-repositories.com/f/software-engineering-architecture/custom-rule-development.md) — Implements bespoke validation logic and architectural constraints to enforce project-specific coding standards.
- [Technical Debt Management](https://awesome-repositories.com/f/software-engineering-architecture/technical-debt-management/technical-debt-management.md) — Tracks and suppresses existing code issues through baselines to allow for the incremental adoption of stricter quality standards.
- [Abstract Syntax Tree Tools](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-tools.md) — Parses source code into an abstract syntax tree to perform deep structural validation and type checking.
- [Static Analysis Extensions](https://awesome-repositories.com/f/software-engineering-architecture/static-analysis-extensions.md) — Integrates framework-specific rules and plugins to extend the core analysis engine's capabilities. ([source](https://phpstan.org/user-guide/rule-levels))
- [Custom Validation Rules](https://awesome-repositories.com/f/software-engineering-architecture/custom-validation-rules.md) — Executes modular rules against the code tree to identify violations and enforce project-specific coding standards.
- [Object Shape Validation](https://awesome-repositories.com/f/software-engineering-architecture/data-schema-validation/data-type-validation/object-shape-validation.md) — Enforces specific property requirements on objects to ensure they contain the expected data fields and types. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Custom Analysis Rules](https://awesome-repositories.com/f/software-engineering-architecture/custom-analysis-rules.md) — Implements bespoke validation logic using abstract syntax trees and type inference to enforce project-specific coding standards. ([source](https://phpstan.org/user-guide/extension-library))
- [Extensible Plugin Architectures](https://awesome-repositories.com/f/software-engineering-architecture/extensible-plugin-architectures.md) — Allows developers to register custom logic and plugins that hook into the analysis pipeline to support framework-specific patterns.
- [Generic Type Definitions](https://awesome-repositories.com/f/software-engineering-architecture/generic-type-definitions.md) — The static analysis tool uses type parameters to create flexible, reusable components that maintain strict type safety across different data inputs. ([source](https://phpstan.org/writing-php-code/phpdoc-types))
- [Purity Annotations](https://awesome-repositories.com/f/software-engineering-architecture/static-analysis-rule-engines/purity-annotations.md) — The static analysis tool labels functions as pure or impure to control how the analysis engine handles repeated calls and global state dependencies. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Type-Aware Inspection Engines](https://awesome-repositories.com/f/software-engineering-architecture/type-systems/type-aware-inspection-engines.md) — Performs deep code inspection by accessing compiler type information to assist in debugging complex type resolution issues. ([source](https://phpstan.org/user-guide/troubleshooting-types))
- [Version Compatibility Analyzers](https://awesome-repositories.com/f/software-engineering-architecture/deterministic-simulation-environments/version-compatibility-analyzers.md) — The static analysis tool analyzes code against specific version targets to ensure compatibility across different runtime environments. ([source](https://phpstan.org/config-reference))
- [Exception Type Enforcers](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/exception-logic-structures/exception-hierarchies/exception-type-enforcers.md) — Enforces rules for checked and unchecked exceptions to ensure robust error management throughout the codebase. ([source](https://phpstan.org/config-reference))
- [Immutability Strategies](https://awesome-repositories.com/f/software-engineering-architecture/immutability-strategies.md) — The static analysis tool treats properties or entire classes as read-only to prevent unauthorized state changes during analysis. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Parallel Processing Utilities](https://awesome-repositories.com/f/software-engineering-architecture/parallel-processing-utilities.md) — Distributes analysis workloads across multiple CPU cores to maximize hardware utilization and reduce execution time.
- [Dynamic Return Type Inference](https://awesome-repositories.com/f/software-engineering-architecture/typescript-type-definitions/dynamic-return-type-inference.md) — The static analysis tool calculates return types for functions that vary based on input arguments by applying custom logic or registered extensions. ([source](https://phpstan.org/user-guide/troubleshooting-types))

### Data & Databases

- [Architectural Constraints](https://awesome-repositories.com/f/data-databases/schema-enforcement-tools/validation-constraints/architectural-constraints.md) — Enforces architectural requirements by mandating specific class inheritance or interface implementation patterns. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))
- [Analysis Result Caches](https://awesome-repositories.com/f/data-databases/data-engineering-infrastructure/caching-performance/caching-strategies/query-result-caching/method-result-caches/analysis-result-caches.md) — Stores intermediate results of processed files to skip redundant computations and accelerate subsequent analysis runs.
- [Codebase Data Aggregation](https://awesome-repositories.com/f/data-databases/data-processing-pipelines/data-transformation/data-aggregation-tools/codebase-data-aggregation.md) — Collects and processes information across multiple files to support complex analysis rules that require global context. ([source](https://phpstan.org/developing-extensions/extension-types))
- [Custom Type Assertion Mapping](https://awesome-repositories.com/f/data-databases/type-mapping-utilities/custom-type-assertion-mapping.md) — Maps complex validation logic or external assertion libraries to type-narrowing rules for the analysis engine. ([source](https://phpstan.org/writing-php-code/narrowing-types))

### DevOps & Infrastructure

- [Usage Policy Enforcement](https://awesome-repositories.com/f/devops-infrastructure/infrastructure/configuration-policy-enforcement/usage-policies/usage-policy-enforcement.md) — Prevents unauthorized access to symbols by marking code as deprecated, internal, or restricted. ([source](https://phpstan.org/writing-php-code/phpdocs-basics))

### Security & Cryptography

- [Remediation Guides](https://awesome-repositories.com/f/security-cryptography/security-guides/security-guidance-summaries/remediation-guides.md) — Provides detailed documentation, explanations, and code examples for resolving identified issues. ([source](https://phpstan.org/error-identifiers))
