localheinz/phpstan-rules

Provides additional rules for phpstan/phpstan.

Installs: 36 537

Dependents: 39

Suggesters: 0

Stars: 101

Watchers: 5

Forks: 5

Open Issues: 5

Type:phpstan-extension

0.10.0 2019-05-22 20:35 UTC

README

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.

When you are using phpstan/extension-installer, rules.neon will be automatically included.

Otherwise you need 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.

💡 Doctrine entities are currently ignored when they are annotated with @ORM\Entity or @Entity.

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.

Expressions

Expressions\NoIssetRule

This rule reports an error when the language construct isset() is used.

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.

Credits

The method FinalRule::isWhitelistedClass() is inspired by the work on FinalClassFixer and FinalInternalClassFixer, contributed by Dariusz Rumiński, Filippo Tessarotto, and Spacepossum for friendsofphp/php-cs-fixer (originally licensed under MIT).