Skip to content

๐Ÿ‘“ Provides additional rules for phpstan/phpstan.

License

Notifications You must be signed in to change notification settings

WyriHaximus/phpstan-rules

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

phpstan-rules

Build Status codecov Latest Stable Version Total Downloads

Provides additional rules for phpstan/phpstan.

Installation

Run

$ composer require --dev localheinz/phpstan-rules

Usage

All of the rules provided (and used) by this library are included in rules.neon. The easiest way to use these rules in your project is to include rules.neon in your phpstan.neon:

includes:
	- vendor/localheinz/phpstan-rules/rules.neon

๐Ÿ’ก You probably want to use these rules on top of the rules provided by:

Rules

This package provides the following rules for use with phpstan/phpstan:

Classes

Classes\FinalRule

This rule reports an error when a non-anonymous class is not final.

Disallowing abstract classes

By default, this rule allows to declare abstract classes. If you want to disallow declaring abstract classes, you can set the allowAbstractClasses parameter to false:

parameters:
	allowAbstractClasses: false
Excluding classes from inspection

If you want to exclude classes from being inspected by this rule, you can set the classesNotRequiredToBeAbstractOrFinal parameter to a list of class names:

parameters:
	classesNotRequiredToBeAbstractOrFinal:
		- Foo\Bar\NeitherAbstractNorFinal
		- Bar\Baz\NeitherAbstractNorFinal

Classes\NoExtendsRule

This rule reports an error when a class extends another class.

Defaults

By default, this rule allows the following classes to be extended:

Allowing classes to be extended

If you want to allow additional classes to be extended, you can set the classesAllowedToBeExtended parameter to a list of class names:

parameters:
	classesAllowedToBeExtended:
		- Localheinz\PHPStan\Rules\Test\Integration\AbstractTestCase
		- PHPStan\Testing\RuleTestCase

Closures

Closures\NoNullableReturnTypeDeclarationRule

This rule reports an error when a closure uses a nullable return type declaration.

Closures\NoParameterWithNullableTypeDeclarationRule

This rule reports an error when a closure has a parameter with a nullable type declaration.

Closures\NoParameterWithNullDefaultValueRule

This rule reports an error when a closure has a parameter with null as default value.

Functions

Functions\NoNullableReturnTypeDeclarationRule

This rule reports an error when a function uses a nullable return type declaration.

Functions\NoParameterWithNullableTypeDeclarationRule

This rule reports an error when a function has a parameter with a nullable type declaration.

Functions\NoParameterWithNullDefaultValueRule

This rule reports an error when a function has a parameter with null as default value.

Methods

Methods\NoConstructorParameterWithDefaultValueRule

This rule reports an error when a constructor declared in

  • an anonymous class
  • a class

has a default value.

Methods\NoNullableReturnTypeDeclarationRule

This rule reports an error when a method declared in

  • an anonymous class
  • a class
  • an interface

uses a nullable return type declaration.

Methods\NoParameterWithNullableTypeDeclarationRule

This rule reports an error when a method declared in

  • an anonymous class
  • a class
  • an interface

has a parameter with a nullable type declaration.

Methods\NoParameterWithNullDefaultValueRule

This rule reports an error when a method declared in

  • an anonymous class
  • a class
  • an interface

has a parameter with null as default value.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

About

๐Ÿ‘“ Provides additional rules for phpstan/phpstan.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • PHP 98.6%
  • Other 1.4%