airlst/phpstan-config

PHPStan config for AirLST projects

5.0.0 2024-06-17 08:31 UTC

README

PHPStan config for AirLST projects

Latest Version on Packagist Total Downloads

PHPStan config for AirLST projects.

Installation

You can install the package via Composer:

composer require --dev airlst/phpstan-config

Make sure to allow the phpstan/extension-installer plugin to run in your composer.json:

{
    "config": {
        "allow-plugins": {
            "phpstan/extension-installer": true
        }
    }
}

Usage

Create a phpstan.php in the root of your project with the following contents:

<?php

declare(strict_types=1);

$factory = new Airlst\PhpstanConfig\Factory(['src']);

return $factory
    ->level(8)
    ->create();

The constructor of the Factory class takes an array of paths to be scanned for PHP files and analyzed. You can pass any number of paths to it.

Configuration

You can use following configuration options on the Factory class by chaining them before create() call:

  • level(int $level): Set the level of PHPStan
  • include(string $file): Include additional PHPStan neon file
  • exclude(string $file): Exclude provided PHPStan neon file
  • withBleedingEdge(): Use bleeding edge version of PHPStan
  • useCacheDir(string $cacheDir): Use cache directory for PHPStan
  • typeCoverage(int $return, int $param, int $property, int $constant): Set type coverage percentage, default is 100% for all
  • typePerfect(bool $nullOverFalse, bool $noMixed, bool $narrowParam): Set type perfect configuration, by default all turned on. See rectorphp/type-perfect README for more details.
  • addRule(string $file): Add additional rule to PHPStan
  • ignoreError(string $message, ?string $path, ?int $count, ?bool $reportUnmatched): Ignore provided error message
  • checkMissingIterableValueType(bool $enable = true): Enables/Disables checkMissingIterableValueType rule
  • checkGenericClassInNonGenericObjectType(bool $enable = true): Enables/Disables checkGenericClassInNonGenericObjectType rule
  • strictRules(): Enables/disables strict rules. For available method arguments you can check phpstan/phpstan-strict-rules documentation

Running PHPStan

Run PHPStan with the following command:

./vendor/bin/phpstan analyse -c phpstan.php

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.