Giter Site home page Giter Site logo

larastan's Introduction

Larastan Logo

Larastan Example

Build Status Quality Score Total Downloads Latest Version License


About Larastan

Larastan was created by, and is maintained by Nuno Maduro, and is a phpstan/phpstan wrapper for Laravel. Larastan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code.

  • Supports Laravel's beautiful magic.
  • This package is still in development. Please report false positives using GitHub issues.

Installation & Usage

Requires:

You may use Composer to install Larastan as a development dependency into your Laravel project:

composer require --dev nunomaduro/larastan

Usage in Laravel Applications

Once you have installed Larastan, you may start analyzing your code using the code:analyse Artisan command.

php artisan code:analyse

Custom configuration

If you would like to provide your own configuration, you can create a phpstan.neon or phpstan.neon.dist file in the root of your application. It might look like this:

includes:
    - ./vendor/nunomaduro/larastan/extension.neon
parameters:
    level: 5
    ignoreErrors:
        - '#Access to an undefined property App\\Demo\\[a-zA-Z0-9\\_]+::\$[a-zA-Z0-9\\_]+\.#'
        - '#Call to an undefined method App\\Http\\Resources\\DemoResource::DemoMethod\(\)\.#'
    excludes_analyse:
        - /*/*/FileToBeExcluded.php

For all available options, please take a look at the PHPStan documentation.

Lumen installation

Add the following lines into your app/Providers/AppServiceProvider:

public function register()
{
    $this->app->register(\NunoMaduro\Larastan\LarastanServiceProvider::class);
    $this->app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');
    $this->app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
}

Usage in Packages for Laravel

Requires:

Once you have installed Larastan, also install orchestra/testbench:

composer require --dev orchestra/testbench

Then create a file named phpstan.neon.dist in the root of your package with the content:

includes:
    - ./vendor/nunomaduro/larastan/extension.neon
parameters:
    level: 5
    paths:
        - src

Start analyzing your code using the analyse PHPStan command.

./vendor/bin/phpstan analyse

Rule levels

You can choose from currently 8 levels: (0 is the loosest and 7 is the strictest) by passing --level to analyse command. Default level is 5. You can also use --level max as an alias for the highest level.

php artisan code:analyse --level=max

Paths

You can choose which directories you want to analyze, by default, the analyzed directory will be the app.

php artisan code:analyse --paths="modules,app,domain"

Error formats

By default, Larastan outputs found errors into tables grouped by files to be easily human-readable. To change the output, you can use the --error-format CLI option.

The available options are: checkstyle, raw, table, json, prettyJson.

php artisan code:analyse --error-format table

Contributing

Thank you for considering to contribute to Larastan. All the contribution guidelines are mentioned here.

You can have a look at the CHANGELOG for constant updates & detailed information about the changes. You can also follow the Twitter account for latest announcements or just come say hi!: @enunomaduro.

Support the development

Do you like this project? Support it by donating

Credits

License

Larastan is an open-sourced software licensed under the MIT license.

larastan's People

Contributors

nunomaduro avatar szepeviktor avatar ondrejmirtes avatar kylekatarnls avatar mvdnbrk avatar johanvanhelden avatar uksusoff avatar j3j5 avatar staudenmeir avatar deleugpn avatar ijpatricio avatar alnutile avatar ankitjain28may avatar schursin avatar raphaelstolt avatar j3rrey avatar devfrey avatar danielruf avatar adrianhl avatar tswestendorp avatar ntzm avatar mfn avatar bolmstedt avatar kieranbrown avatar jmarcher avatar aso824 avatar mr-feek avatar hartman avatar spawnia avatar axelitus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.