Polyscope - The agent-first dev environment for Laravel

Larastan

nunomaduro/larastan image

Larastan stats

Downloads
25.8M
Stars
4,830
Open Issues
72
Forks
365

View on GitHub →

Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper for Laravel

Larastan: Enhance Your Laravel Code Quality

Larastan is a powerful tool developed by Can Vural and Nuno Maduro, designed to improve code quality in Laravel applications by leveraging PHPStan, a popular PHP static analysis tool. It aims to detect potential errors in your code before you even run tests, effectively enhancing productivity and maintaining high code standards.

Key Features:

  • Static Typing for Laravel: Integrates static typing into Laravel, supporting most of Laravel's dynamic features while ensuring code reliability.
  • Early Bug Detection: Identifies bugs and issues early in the development process, saving time and reducing potential technical debt.
  • Ease of Setup: Can be easily integrated into any Laravel project (version 9.0 and above) with just a few commands.

Installation and Usage:

  1. Install via Composer:

    composer require nunomaduro/larastan:^2.0 --dev

    For Laravel package analysis, installation of orchestra/testbench might be necessary.

  2. Configuration: Create a phpstan.neon or phpstan.neon.dist in your project root with the necessary configurations:

    includes:
    - ./vendor/nunomaduro/larastan/extension.neon
     
    parameters:
    paths:
    - app/
    level: 5 # Level 9 is the most strict
  3. Analyse Your Code: Run PHPStan to analyze your project's code:

    ./vendor/bin/phpstan analyse

    Use the --memory-limit option if you encounter memory issues:

    ./vendor/bin/phpstan analyse --memory-limit=2G

Advanced Configuration:

  • Ignoring Errors: Specific errors can be ignored directly in the code or via the configuration file using regex patterns.
  • Baseline File: For legacy projects, generate a baseline file to exclude existing errors, allowing you to enforce stricter rules for new code.
  • Custom Rules and PHPDoc Types: Extend PHPStan with Laravel-specific rules and custom PHPDoc types to tailor the analysis to your needs.

Getting Involved:

Contributions are welcome, and the contribution guidelines can be found in the project's repository. Keep up with updates and community discussions via the official Twitter accounts and GitHub.

Larastan is an essential tool for any developer looking to maintain high standards in their Laravel applications, ensuring robust and error-free code.

nunomaduro photo

Software engineer at @laravel — working on Laravel, Forge, and Vapor. Created @pestphp, @laravel-zero, collision, @openai-php, php insights, termwind, etc.


Nunomaduro Larastan Related Articles

Larastan v1.0 Released image

Larastan v1.0 Released

Read article
PestPHP Released as Open-Source image

PestPHP Released as Open-Source

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell