• Stars
    star
    345
  • Rank 122,750 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 1 month ago

Reviews

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

Repository Details

👓 Provides a composer package with rules for phpstan/phpstan.

phpstan-rules

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with rules for phpstan/phpstan.

Installation

Run

composer require --dev ergebnis/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/ergebnis/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.

💡 This rule ignores classes that

  • use @Entity, @ORM\Entity, or @ORM\Mapping\Entity annotations
  • use Doctrine\ORM\Mapping\Entity attributes

on the class level.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		final:
			enabled: false
Disallowing abstract classes

By default, this rule allows to declare abstract classes.

You can set the allowAbstractClasses parameter to false to disallow abstract classes.

parameters:
	ergebnis:
		final:
			allowAbstractClasses: false
Excluding classes from inspection

You can set the classesNotRequiredToBeAbstractOrFinal parameter to a list of class names that you want to exclude from inspection.

parameters:
	ergebnis:
		final:
			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:

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noExtends:
			enabled: false
Allowing classes to be extended

You can set the classesAllowedToBeExtended parameter to a list of class names that you want to allow to be extended.

parameters:
	ergebnis:
		noExtends:
			classesAllowedToBeExtended:
				- Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase
				- Ergebnis\PHPStan\Rules\Test\Integration\AbstractTestCase

Classes\PHPUnit\Framework\TestCaseWithSuffixRule

This rule reports an error when a concrete class is a sub-class of PHPUnit\Framework\TestCase but does not have a Test suffix.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		testCaseWithSuffix:
			enabled: false

Closures

Closures\NoNullableReturnTypeDeclarationRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false

Closures\NoParameterWithNullableTypeDeclarationRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false

Closures\NoParameterWithNullDefaultValueRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false

Expressions

Expressions\NoCompactRule

This rule reports an error when the function compact() is used.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noCompact:
			enabled: false

Expressions\NoEvalRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noEval:
			enabled: false

Expressions\NoErrorSuppressionRule

This rule reports an error when @ is used to suppress errors.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noErrorSuppression:
			enabled: false

Expressions\NoIssetRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noIsset:
			enabled: false

Files

Files\DeclareStrictTypesRule

This rule reports an error when a non-empty file does not contain a declare(strict_types=1) declaration.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		declareStrictTypes:
			enabled: false

Functions

Functions\NoNullableReturnTypeDeclarationRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false

Functions\NoParameterWithNullableTypeDeclarationRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false

Functions\NoParameterWithNullDefaultValueRule

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

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false

Methods

Methods\FinalInAbstractClassRule

This rule reports an error when a concrete public or protected method in an abstract class is not final.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		finalInAbstractClass:
			enabled: false

Methods\NoConstructorParameterWithDefaultValueRule

This rule reports an error when a constructor declared in

  • an anonymous class
  • a class

has a default value.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noConstructorParameterWithDefaultValue:
			enabled: false

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.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noNullableReturnTypeDeclaration:
			enabled: false

Methods\NoParameterWithContainerTypeDeclarationRule

This rule reports an error when a method has a type declaration for a known dependency injection container or service locator.

Defaults

By default, this rule disallows the use of type declarations indicating an implementation of

is expected to be injected into a method.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithContainerTypeDeclaration:
			enabled: false
Configuring container interfaces

You can set the interfacesImplementedByContainers parameter to a list of interface names of additional containers and service locators.

parameters:
	ergebnis:
		noParameterWithContainerTypeDeclaration:
			interfacesImplementedByContainers:
				- Fancy\DependencyInjection\ContainerInterface
				- Other\ServiceLocatorInterface
Configuring methods allowed to use parameters with container type declarations

You can set the methodsAllowedToUseContainerTypeDeclarations parameter to a list of method names that are allowed to use parameters with container type declarations.

parameters:
	ergebnis:
		noParameterWithContainerTypeDeclaration:
			methodsAllowedToUseContainerTypeDeclarations:
				- loadExtension

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.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullableTypeDeclaration:
			enabled: false

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.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noParameterWithNullDefaultValue:
			enabled: false

Methods\PrivateInFinalClassRule

This rule reports an error when a method in a final class is protected but could be private.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		privateInFinalClass:
			enabled: false

Statements

Statements\NoSwitchRule

This rule reports an error when the statement switch() is used.

Disabling the rule

You can set the the enabled parameter to false to disable this rule.

parameters:
	ergebnis:
		noSwitch:
			enabled: false

Changelog

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

You can support the maintenance of this project by sponsoring @localheinz or requesting an invoice for services related to this project.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses 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).

Social

Follow @localheinz and @ergebnis on Twitter.

More Repositories

1

composer-normalize

🎵 Provides a composer plugin for normalizing composer.json.
PHP
1,035
star
2

php-package-template

:octocat: + 📒 Provides a GitHub repository template for a composer package with GitHub Actions workflows using standard PHP development tools.
PHP
303
star
3

phpunit-slow-test-detector

⏱️ Provides a composer package with an extension for detecting slow tests in phpunit/phpunit.
PHP
115
star
4

http-method

📟 Provides a composer package with constants for HTTP request methods.
PHP
92
star
5

json-printer

📃 Provides a composer package with a JSON printer, allowing for flexible indentation.
PHP
86
star
6

factory-bot

🤖 Provides a composer package with a fixture factory for doctrine/orm entities.
PHP
78
star
7

json-normalizer

📃 Provides a composer package with generic and vendor-specific normalizers for normalizing JSON documents.
PHP
76
star
8

php-cs-fixer-config

📓 Provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
PHP
68
star
9

github-changelog

:octocat: Provides a command line tool that generates a changelog based on titles of pull requests merged between specified references.
PHP
47
star
10

environment-variables

🌳 Provides a composer package with an abstraction of environment variables.
PHP
39
star
11

classy

🔍 Provides a composer package with a finder for classy constructs (classes, enums, interfaces, and traits).
PHP
33
star
12

clock

⏰ Provides a composer package with abstractions of a clock.
PHP
30
star
13

json-schema-validator

📃 Provides a composer package with a JSON schema validator, building on top of justinrainbow/json-schema.
PHP
30
star
14

data-provider

👓 Provides a composer package with generic data providers for use with phpunit/phpunit.
PHP
27
star
15

composer-normalize-action

:octocat: + 🎵 Provides a GitHub action for running ergebnis/composer-normalize.
Makefile
26
star
16

composer-json-normalizer

🎵 Provides normalizers for normalizing composer.json.
PHP
20
star
17

json

📃 Provides a composer package with a Json value object for representing a valid JSON string.
PHP
20
star
18

.github

❤️ Provides default community health files and composite actions for the @ergebnis organization.
Shell
18
star
19

version

💾 Provides a composer package with an abstraction of a semantic version.
PHP
17
star
20

symfony-application-template

:octocat: + 🎼 Provides a GitHub template repository for a Symfony application, using GitHub Actions.
PHP
16
star
21

test-util

👓 Provides utilities for tests.
PHP
15
star
22

json-pointer

📃 Provides a composer package with an abstraction of a JSON pointer.
PHP
15
star
23

license

💼 Provides a composer package with an abstraction of an open-source license.
PHP
14
star
24

php-cs-fixer-config-template

:octocat: + 📓 Provides a GitHub repository template for a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
PHP
11
star
25

composer-root-version-action

:octocat: + 🎵 Provides a GitHub Action that sets a COMPOSER_ROOT_VERSION environment variable from the value of the branch alias defined in composer.json.
Shell
10
star
26

factory-girl-definition

👧 Provides an interface for, and an easy way to find and register entity definitions for breerly/factory-girl-php.
PHP
9
star
27

day-one-to-obsidian-converter

📓 Provides a composer package with a console command for converting DayOne journals to Obsidian notes.
PHP
8
star
28

rector-rules

👓 Provides a composer package with rules for rector/rector.
PHP
6
star
29

keep-a-changelog

📓 Provides a composer package with tools for keeping a changelog.
PHP
5
star
30

front-matter

👀 Provides a composer package with a front-matter parser.
PHP
4
star
31

factory-bot-example

🤖 + 📔 Provides usage examples for ergebnis/factory-bot.
PHP
4
star
32

phpunit-framework-constraint

👓 Provides additional constraints and assertions for phpunit/phpunit
PHP
4
star
33

laravel-application-template

:octocat: + 📒 Provides a GitHub repository template for a Laravel application, using GitHub Actions.
PHP
3
star
34

json-normalize

📃 Provides a composer package with a console command for normalizing JSON documents.
PHP
3
star
35

faker-provider

🐙 Provides additional providers for fzaninotto/faker.
PHP
3
star
36

twig-front-matter

🌱 + 👀 Provides a composer package with a Twig loader for files with YAML front-matter.
PHP
2
star
37

playground

🏀 A playground.
PHP
2
star
38

rector-config-template

👓 Provides a GitHub repository template for a composer package with a configuration factory and custom rule sets for rector/rector.
PHP
2
star
39

factory-muffin-definition

👧 Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.
PHP
2
star
40

version-constraint

🎚️ Provides a composer package with abstractions of version constraints.
PHP
1
star
41

data-generator

🗄 Provides a composer package with data generators.
PHP
1
star