2017 © Pedro Peláez
 

library larastan

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

image

nunomaduro/larastan

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

  • Wednesday, July 25, 2018
  • by nunomaduro
  • Repository
  • 22 Watchers
  • 413 Stars
  • 2,002 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 20 Forks
  • 27 Open issues
  • 22 Versions
  • 0 % Grown

The README.md

Larastan Logo

Larastan Example , (*1)

Build Status Total Downloads Latest Version License , (*2)


⚗️ About Larastan

Larastan was created by Can Vural and Nuno Maduro, got artwork designed by @Caneco, is maintained by Can Vural and Viktor Szépe, and is a PHPStan extension for Laravel. Larastan focuses on finding errors in your code. It catches whole classes of bugs even before you write tests for the code., (*3)

  • Adds static typing to Laravel to improve developer productivity and code quality
  • Supports most of Laravel's beautiful magic
  • Discovers bugs in your code

While by definition, "static analysis" doesn't load any of your application's code. Larastan boots your application's container, so it can resolve types that are only possible to compute at runtime. That's why we use the term "code analysis" instead of "static analysis"., (*4)

Supported Laravel versions

Laravel Version Larastan Version
< 9 1.x
> 9.0 && <11.15 2.x
11.15+ 3.0+

✨ Getting Started In 3 Steps

Requires: - PHP 8.2+ - Laravel 11.15+, (*5)

1: First, you may use Composer to install Larastan as a development dependency into your Laravel project:, (*6)

composer require --dev "larastan/larastan:^3.0"

Using Larastan for analysing Laravel packages? You may need to install orchestra/testbench., (*7)

2: Then, create a phpstan.neon or phpstan.neon.dist file in the root of your application. It might look like this:, (*8)

includes:
    - vendor/larastan/larastan/extension.neon
    - vendor/nesbot/carbon/extension.neon

parameters:

    paths:
        - app/

    # Level 10 is the highest level
    level: 5

#    ignoreErrors:
#        - '#PHPDoc tag @var#'
#
#    excludePaths:
#        - ./*/*/FileToBeExcluded.php

For all available options, please take a look at the PHPStan documentation: https://phpstan.org/config-reference, (*9)

3: Finally, you may start analyzing your code using the phpstan console command:, (*10)

./vendor/bin/phpstan analyse

If you are getting the error Allowed memory size exhausted, then you can use the --memory-limit option fix the problem:, (*11)

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

Ignoring errors

Ignoring a specific error can be done either with a php comment or in the configuration file:, (*12)

// @phpstan-ignore-next-line
$test->badMethod();

$test->badMethod(); // @phpstan-ignore-line

When ignoring errors in PHPStan's configuration file, they are ignored by writing a regex based on error messages:, (*13)

parameters:
    ignoreErrors:
        - '#Call to an undefined method .*badMethod\(\)#'

Baseline file

In older codebases it might be hard to spend the time fixing all the code to pass a high PHPStan Level., (*14)

To get around this a baseline file can be generated. The baseline file will create a configuration file with all of the current errors, so new code can be written following a higher standard than the old code. (PHPStan Docs), (*15)

./vendor/bin/phpstan analyse --generate-baseline

Rules

A list of configurable rules specific to Laravel can be found here., (*16)

Features

A list of Larastan features can be found here., (*17)

Custom PHPDoc types

A list of PHPDoc types specific to Larastan can be found here., (*18)

Custom PHPStan config parameters

A list of custom config parameters that you can use in your PHPStan config file can be found here., (*19)

Errors To Ignore

Some parts of Laravel are currently too magical for Larastan/PHPStan to understand. We listed common errors to ignore, add them as needed, (*20)

👊🏻 Contributing

Thank you for considering contributing to Larastan. All the contribution guidelines are mentioned here., (*21)

📖 License

Larastan is an open-sourced software licensed under the MIT license., (*22)

The Versions

25/07 2018

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

25/07 2018

dev-analysis-zdO1kw

dev-analysis-zdO1kw

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

24/07 2018

v0.2.4

0.2.4.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

23/07 2018

v0.2.3

0.2.3.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

23/07 2018

v0.2.2

0.2.2.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

23/07 2018

v0.2.1

0.2.1.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.2.0

0.2.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.10

0.1.10.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.9

0.1.9.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

dev-szepeviktor-patch-1

dev-szepeviktor-patch-1

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

dev-ondrejmirtes-phpstan-fixes

dev-ondrejmirtes-phpstan-fixes

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

dev-ondrejmirtes-fixes

dev-ondrejmirtes-fixes

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.8

0.1.8.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

dev-analysis-8n3Yly

dev-analysis-8n3Yly

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.7

0.1.7.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.6

0.1.6.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.5

0.1.5.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

22/07 2018

v0.1.4

0.1.4.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

20/07 2018

v0.1.3

0.1.3.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

20/07 2018

v0.1.2

0.1.2.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

18/07 2018

v0.1.1

0.1.1.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan

17/07 2018

v0.1.0

0.1.0.0

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

  Sources   Download

MIT

The Requires

 

The Development Requires

by Nuno Maduro

laravel php package static analysis code analysis phpstan code analyse larastan