# larastan/larastan

**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/larastan-larastan).**

6,430 stars · 493 forks · PHP · MIT

## Links

- GitHub: https://github.com/larastan/larastan
- awesome-repositories: https://awesome-repositories.com/repository/larastan-larastan.md

## Description

Larastan is a static analysis extension and type inference engine for PHP designed to detect bugs and type errors in Laravel applications. It extends PHPStan to resolve framework-specific patterns and magic methods, providing a rule-based scanning engine to audit code quality without executing the application.

The tool specializes in Eloquent analysis, verifying that model properties, casts, and relationships align with database schemas and migrations. It tracks types across Eloquent collections, custom builders, and model factories to ensure type safety during database operations and iteration.

Broad capability areas include configuration validation, view path verification, and the detection of inefficient database queries or redundant collection calls. The engine also audits job dispatch arguments, localization keys, and compatibility with long-running process environments.

Diagnostics include styled bootstrap error reporting to resolve startup failures, as well as mechanisms for error suppression and the establishment of legacy issue baselines.

## Tags

### Development Tools & Productivity

- [Code Quality and Analysis](https://awesome-repositories.com/f/development-tools-productivity/code-quality-analysis.md) — Provides static analysis and linting to identify bugs and quality issues in Laravel applications without executing code. ([source](https://github.com/larastan/larastan#readme))
- [Factory Type Validators](https://awesome-repositories.com/f/development-tools-productivity/factory-type-validators.md) — Analyzes model factories to verify they extend the base factory class with the correct model type. ([source](https://github.com/larastan/larastan/blob/3.x/UPGRADE.md))
- [Model Factory Type Analysis](https://awesome-repositories.com/f/development-tools-productivity/factory-type-validators/model-factory-type-analysis.md) — Verifies the relationship between models and factory classes using template types to prevent type mismatches. ([source](https://github.com/larastan/larastan/blob/3.x/docs/features.md))
- [Configuration Verification](https://awesome-repositories.com/f/development-tools-productivity/configuration-verification.md) — Verifies that the return types of configuration helper functions match the actual configuration files. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md))
- [Analysis Suppression Mechanisms](https://awesome-repositories.com/f/development-tools-productivity/formatting-suppression/analysis-suppression-mechanisms.md) — Disables specific error reports via inline comments or regex configurations to silence known issues. ([source](https://github.com/larastan/larastan/blob/3.x/README.md))

### Software Engineering & Architecture

- [Static Analysis Extensions](https://awesome-repositories.com/f/software-engineering-architecture/static-analysis-extensions.md) — Provides a rule-based scanning engine to find bugs and logical errors in Laravel applications without executing the code.
- [Eloquent Collection Type Inference](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/php-type-checkers/automated-type-hinting/eloquent-collection-type-inference.md) — Resolves collection type hints to specific model classes to ensure type safety during iteration. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-types.md))
- [Static Analysis Engines](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/php-type-checkers/static-analysis-engines.md) — Uses a rule-based scanning engine to detect bugs, type errors, and maintainability issues in PHP code.
- [Type Inference Engines](https://awesome-repositories.com/f/software-engineering-architecture/type-safe-data-handling/type-inference-engines.md) — Automatically determines the data types of model properties and collection elements to enable deeper static analysis.
- [Database](https://awesome-repositories.com/f/software-engineering-architecture/typescript-type-definitions/schema-driven-type-inference/schema-type-inference/database.md) — Analyzes database migrations and schema dumps to determine the types and existence of model properties. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md))
- [Configuration Validation](https://awesome-repositories.com/f/software-engineering-architecture/configuration-validation.md) — Checks that keys passed to configuration methods point to arrays to prevent runtime type errors. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Job Dispatch Type Verification](https://awesome-repositories.com/f/software-engineering-architecture/job-dispatch-type-verification.md) — Checks that arguments passed when dispatching a job are type-compatible with the job class constructor. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Long-Running Process Compatibility Analysis](https://awesome-repositories.com/f/software-engineering-architecture/long-running-process-compatibility-analysis.md) — Analyzes the codebase for patterns that are incompatible with long-running process environments. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Model Coding Standards Enforcement](https://awesome-repositories.com/f/software-engineering-architecture/model-coding-standards-enforcement.md) — Validates that appended computed properties exist and that local scopes and accessors are not public. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Provider Validation](https://awesome-repositories.com/f/software-engineering-architecture/service-providers/provider-validation.md) — Ensures deferrable service providers include the required provides method for correct bootstrapping. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Static Analysis Baselines](https://awesome-repositories.com/f/software-engineering-architecture/static-analysis-baselines.md) — Records existing issues in a configuration file to prevent legacy errors from blocking stricter analysis levels. ([source](https://github.com/larastan/larastan/blob/3.x/README.md))

### Data & Databases

- [Cast Configuration Validation](https://awesome-repositories.com/f/data-databases/data-type-casting/load-time-type-casting/attribute-casting/cast-configuration-validation.md) — Checks that the return type and array shape of model casts match the expected configuration. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md))
- [Relationship Validations](https://awesome-repositories.com/f/data-databases/object-relational-mappers/data-modeling/entity-relationship-models/association-models/relationship-validations.md) — Validates database relationship methods by checking return types and string arguments. ([source](https://github.com/larastan/larastan/blob/3.x/docs/features.md))
- [ORM Component Validation](https://awesome-repositories.com/f/data-databases/object-relational-mappings/code-to-relational-mappings/eloquent-orm-mappings/orm-component-validation.md) — Validates custom builders and relations using generic templates to maintain type integrity across extended classes. ([source](https://github.com/larastan/larastan/blob/3.x/UPGRADE.md))
- [Relation Validations](https://awesome-repositories.com/f/data-databases/object-relational-mappings/code-to-relational-mappings/eloquent-orm-mappings/relation-validations.md) — Verifies that relations passed to builder methods exist to prevent runtime errors. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Builder Chain Validation](https://awesome-repositories.com/f/data-databases/query-builders/builder-chain-validation.md) — Validates method chains in custom query builders to ensure type safety during database queries. ([source](https://github.com/larastan/larastan/blob/3.x/docs/features.md))
- [Database Column Validation](https://awesome-repositories.com/f/data-databases/schema-validation-libraries/deep-property-validation/database-column-validation.md) — Checks that strings used in model or builder methods correspond to actual database columns or properties. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-types.md))
- [Static Query Analysis](https://awesome-repositories.com/f/data-databases/query-performance-analyzers/static-query-analysis.md) — Identifies collection method calls that should be performed as direct database queries to reduce memory usage. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))

### Programming Languages & Runtimes

- [Type Safety](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/type-system-tools/type-safety.md) — Enforces data integrity and prevents runtime crashes by ensuring correct data types for models, collections, and database relations.
- [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) — Tracks the types of objects stored within custom collection classes to maintain type safety during iteration. ([source](https://github.com/larastan/larastan/blob/3.x/docs/features.md))
- [PHP Code Analysis](https://awesome-repositories.com/f/programming-languages-runtimes/php-code-analysis.md) — Scans PHP source code to identify inefficient database queries, unused views, and architectural violations.
- [Model Attribute Inference](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/model-attribute-inference.md) — Recognizes model properties defined via attributes by validating associated getter and setter method types. ([source](https://github.com/larastan/larastan/blob/3.x/docs/features.md))
- [Redundant Instantiation Detection](https://awesome-repositories.com/f/programming-languages-runtimes/instance-initialization-hooks/instance-variable-initializers/initialization-pattern-detections/redundant-initialization-detection/redundant-instantiation-detection.md) — Flags the use of static creation methods where a simple new instance is more efficient. ([source](https://github.com/larastan/larastan/blob/3.x/docs/rules.md))
- [Helper Call Constraints](https://awesome-repositories.com/f/programming-languages-runtimes/static-method-call-analysis/helper-call-constraints.md) — Flags calls to environment helpers outside of configuration files to prevent runtime instability when config is cached. ([source](https://github.com/larastan/larastan/blob/3.x/UPGRADE.md))
- [Redundant Call Detection](https://awesome-repositories.com/f/programming-languages-runtimes/static-method-call-analysis/redundant-call-detection.md) — Identifies unnecessary collection method calls that do not change the result and should be removed. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md))
- [Resource Type Inference](https://awesome-repositories.com/f/programming-languages-runtimes/static-method-call-analysis/resource-type-inference.md) — Infers the underlying model class used within API resources to validate property and method calls. ([source](https://github.com/larastan/larastan/blob/3.x/UPGRADE.md))

### Testing & Quality Assurance

- [Code Quality Tools](https://awesome-repositories.com/f/testing-quality-assurance/code-quality-review/code-quality-tools.md) — Provides static analysis to identify dead views, inefficient queries, and redundant method calls to improve overall code quality.

### Web Development

- [Laravel Integrations](https://awesome-repositories.com/f/web-development/laravel-integrations.md) — Extends PHPStan to resolve Laravel's magic methods and framework-specific architecture for deeper static analysis.
- [Schema Validation](https://awesome-repositories.com/f/web-development/laravel-integrations/database-modeling/schema-validation.md) — Verifies that model properties, casts, and relationships match the actual database schema and configuration.
- [Static Analysis Rules](https://awesome-repositories.com/f/web-development/laravel-integrations/static-analysis-rules.md) — Provides specialized rules for analyzing Laravel applications to resolve magic methods and framework-specific patterns.

### DevOps & Infrastructure

- [Environment Variable Type Coercions](https://awesome-repositories.com/f/devops-infrastructure/configuration-management/environment-management/environment-variable-management/environment-variable-configurations/environment-variable-configuration/environment-variable-type-coercions.md) — Infers the return type of environment functions based on provided default values to ensure type consistency. ([source](https://github.com/larastan/larastan/blob/3.x/docs/custom-config-parameters.md))

### Part of an Awesome List

- [Code Quality and Linting](https://awesome-repositories.com/f/awesome-lists/devtools/code-quality-and-linting.md) — Adds static analysis to Laravel via PHPStan.
- [Static Analysis](https://awesome-repositories.com/f/awesome-lists/devtools/static-analysis.md) — Adds static analysis capabilities to framework-specific projects.
- [Static Analysis Tools](https://awesome-repositories.com/f/awesome-lists/devtools/static-analysis-tools.md) — Static analysis wrapper for Laravel applications.
