• Stars
    star
    4,882
  • Rank 8,104 (Top 0.2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚗️ Adds code analysis to Laravel improving developer productivity and code quality.

Larastan Logo

Larastan Example

Build Status Total Downloads Latest Version License


⚗️ About Larastan

If you are using a Laravel version older than 9.x, please refer to Larastan v1.x with PHPStan 1.8.x.

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

  • 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".

Getting Started In 3 Steps

Requires:

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

composer require nunomaduro/larastan:^2.0 --dev

Using Larastan for analysing Laravel packages? You may need to install orchestra/testbench.

2: Then, 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:

    paths:
        - app/

    # Level 9 is the highest level
    level: 5

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

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

3: Finally, you may start analyzing your code using the phpstan console command:

./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:

./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:

// @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:

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.

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)

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

Rules

A list of configurable rules specific to Laravel can be found here.

Features

A list of Larastan features can be found here.

Custom PHPDoc types

A list of PHPDoc types specific to Larastan can be found here.

Custom PHPStan config parameters

A list of custom config parameters that you can use in your PHPStan config file can be found here.

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

👊🏻 Contributing

Thank you for considering contributing 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 the latest announcements or just come say hi!: @enunomaduro, @can__vural.

📖 License

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

More Repositories

1

phpinsights

🔰 Instant PHP quality checks from your console
PHP
5,176
star
2

collision

💥 Collision is a beautiful error reporting tool for command-line applications
PHP
4,408
star
3

termwind

🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
PHP
2,087
star
4

laravel-console-menu

🔘 Beautiful PHP CLI menus. Is a php-school/cli-menu wrapper for Laravel/Artisan Console Commands
PHP
794
star
5

skeleton-php

⚡️ This package provides a wonderful PHP skeleton to start building your next package idea.
PHP
647
star
6

laravel-desktop-notifier

💻 Send notifications to your desktop from your Laravel Artisan Commands. An JoliNotif wrapper for Laravel.
PHP
415
star
7

laravel-mojito

🍹 A lightweight package for testing Laravel views in isolation
PHP
372
star
8

pest

This repository contains an old version of PEST. A new and better version is being coded in private and will be out soon: https://github.com/pestphp/pest.
342
star
9

patrol

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.
PHP
254
star
10

laravel-console-task

✅ Laravel Console Task is a output method for Laravel Console Commands.
PHP
252
star
11

awesome-php-src

🚀 A curated list of awesome resources related to PHP source code
224
star
12

curryable

An elegant and simple curry(f) implementation in PHP.
PHP
175
star
13

dd

✨ The most popular way of debugging in PHP is now available in JavaScript.
JavaScript
159
star
14

yorn

⚗️ Modules in PHP with the `import` and `export` syntax
PHP
146
star
15

laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.
PHP
144
star
16

laracon-schedule

👨🏻‍🚀 A command-line tool that gives you the @LaraconOnline schedule in your timezone. 🚀
PHP
101
star
17

laravel-pot

Provides Artisan commands to inspect Laravel Application's container. 🪴
PHP
88
star
18

mock-final-classes

🏄‍♂️ Allows mocking final classes in PHP.
PHP
83
star
19

awesome-laravel-vapor

🚀 A curated list of awesome resources related to Laravel Vapor.
80
star
20

laravel-console-summary

📖 Beautiful Laravel Console Summary for Artisan or Laravel Zero.
PHP
62
star
21

collision-adapter-symfony

Collision's adapter for Symfony applications. Error Reporting for console/command-line PHP applications.
PHP
45
star
22

dig

👨🏻‍🎨 A beautiful debug tool for the command line.
PHP
40
star
23

laravel-any

🏓 Laravel collection macro that determine if `any` item from the collection passes the given truth test.
PHP
38
star
24

nunomaduro.com

Rust
34
star
25

skeleton-c

⚡️ This package provides a wonderful C skeleton to start building your next package idea.
Makefile
33
star
26

php-interminal

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.
PHP
32
star
27

bombe

Bombe is a tool for benchmarking the given url response status and response time.
C
23
star
28

skeleton-js

👨🏻‍💻 A skeleton repository for my open source JavaScript packages
JavaScript
21
star
29

elegant-sublime

👔An collection of sublime text preferences
17
star
30

alpine-day-schedule

👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀
PHP
11
star
31

pint-strict-preset

Pint strict preset is an insanely defensive coding style preset for those who demand meticulous precision in their projects.
11
star
32

talks

🎤 My talks about PHP, Laravel or side projects of mine
10
star
33

laravel-meetups

🍕It's Meetup time! Find out Laravel Meetups near you!
PHP
8
star
34

laravel-console-spinner

❃ A spinning activity indicator for Laravel/Laravel Zero artisan commands.
7
star
35

laravel-9-test

PHP
5
star
36

forge-octane

PHP
5
star
37

scout-extended-demo

PHP
3
star
38

skeleton-typescript

⚗️ The perfect starting for typescript libraries.
3
star
39

laravel-zero-weather

PHP
3
star
40

nextjs-blog-wqdqwdqwd

JavaScript
2
star
41

dotfiles

2
star
42

twitter-stream

An demo application of Laravel Zero that works with the Twitter Streaming API
PHP
2
star
43

learn-javascript

2
star
44

scout

PHP
1
star
45

my-site

HTML
1
star
46

vapor-github-test

PHP
1
star
47

qwdpowkqdopwqkd

JavaScript
1
star
48

skeleton-php-1

My PHP Package Skeleton
PHP
1
star
49

exclude-dev-files-bug

PHP
1
star
50

kpop-stack

TypeScript
1
star
51

nunomaduro

1
star
52

perna

🛋 Optimises the workflow around managing multi-package repositories.
1
star
53

helpers-tap

🚰 Tap that method
TypeScript
1
star
54

test

HTML
1
star
55

laravel-collections-examples

PHP
1
star
56

demo-p

PHP
1
star