diff --git a/.php_cs.fixture b/.php_cs.fixture index 492256b3..7c633d4c 100644 --- a/.php_cs.fixture +++ b/.php_cs.fixture @@ -6,6 +6,7 @@ use Localheinz\PhpCsFixer\Config; $config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71(''), [ 'lowercase_constants' => false, + 'lowercase_keywords' => false, 'magic_method_casing' => false, 'static_lambda' => false, ]); diff --git a/CHANGELOG.md b/CHANGELOG.md index 370e0ff5..9bb94784 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased -For a full diff see [`0.7.1...master`](https://github.com/localheinz/phpstan-rules/compare/0.7.1...master). +For a full diff see [`0.8.0...master`](https://github.com/localheinz/phpstan-rules/compare/0.8.0...master). + +## [`0.8.0`](https://github.com/localheinz/phpstan-rules/releases/tag/0.8.0) + +For a full diff see [`0.7.1...0.8.0`](https://github.com/localheinz/phpstan-rules/compare/0.7.1...0.8.0). + +### Added + +* Added `Expressions\NoIssetRule`, which reports an error when the language construct `isset()` is used ([#81](https://github.com/localheinz/phpstan-rules/pull/81)), by [@localheinz](https://github.com/localheinz) ## [`0.7.1`](https://github.com/localheinz/phpstan-rules/releases/tag/0.7.1) diff --git a/README.md b/README.md index 1dda1ed5..dfbc242a 100644 --- a/README.md +++ b/README.md @@ -39,9 +39,10 @@ This package provides the following rules for use with [`phpstan/phpstan`](https * [`Localheinz\PHPStan\Rules\Closures\NoNullableReturnTypeDeclarationRule`](https://github.com/localheinz/phpstan-rules#closuresnonullablereturntypedeclarationrule) * [`Localheinz\PHPStan\Rules\Closures\NoParameterWithNullableTypeDeclarationRule`](https://github.com/localheinz/phpstan-rules#closuresnoparameterwithnullabletypedeclarationrule) * [`Localheinz\PHPStan\Rules\Closures\NoParameterWithNullDefaultValueRule`](https://github.com/localheinz/phpstan-rules#closuresnoparameterwithnulldefaultvaluerule) +* [`Localheinz\PHPStan\Rules\Expressions\NoIssetRule`](https://github.com/localheinz/phpstan-rules#expressionsnoissetrule) * [`Localheinz\PHPStan\Rules\Functions\NoNullableReturnTypeDeclarationRule`](https://github.com/localheinz/phpstan-rules#functionsnonullablereturntypedeclarationrule) -* [`Localheinz\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule`](https://github.com/localheinz/phpstan-rules#functionsnoparameterwithnulldefaultvaluerule) * [`Localheinz\PHPStan\Rules\Functions\NoParameterWithNullableTypeDeclaration`](https://github.com/localheinz/phpstan-rules#functionsnoparameterwithnullabletypedeclarationrule) +* [`Localheinz\PHPStan\Rules\Functions\NoParameterWithNullDefaultValueRule`](https://github.com/localheinz/phpstan-rules#functionsnoparameterwithnulldefaultvaluerule) * [`Localheinz\PHPStan\Rules\Methods\NoConstructorParameterWithDefaultValueRule`](https://github.com/localheinz/phpstan-rules#methodsnoconstructorparameterwithdefaultvaluerule) * [`Localheinz\PHPStan\Rules\Methods\NoNullableReturnTypeDeclarationRule`](https://github.com/localheinz/phpstan-rules#methodsnonullablereturntypedeclarationrule) * [`Localheinz\PHPStan\Rules\Methods\NoParameterWithNullableTypeDeclarationRule`](https://github.com/localheinz/phpstan-rules#methodsnoparameterwithnullabletypedeclarationrule) @@ -108,6 +109,12 @@ This rule reports an error when a closure has a parameter with a nullable type d 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` diff --git a/src/Expressions/NoIssetRule.php b/src/Expressions/NoIssetRule.php new file mode 100644 index 00000000..4edcb185 --- /dev/null +++ b/src/Expressions/NoIssetRule.php @@ -0,0 +1,33 @@ + __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Success/isset-not-used.php', + ]; + + foreach ($paths as $description => $path) { + yield $description => [ + $path, + ]; + } + } + + public function providerAnalysisFails(): \Generator + { + $paths = [ + 'isset-used-with-correct-case' => [ + __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-correct-case.php', + [ + 'Language construct isset() should not be used.', + 7, + ], + ], + 'isset-used-with-incorrect-case' => [ + __DIR__ . '/../../Fixture/Expressions/NoIssetRule/Failure/isset-used-with-incorrect-case.php', + [ + 'Language construct isset() should not be used.', + 7, + ], + ], + ]; + + foreach ($paths as $description => [$path, $error]) { + yield $description => [ + $path, + $error, + ]; + } + } + + protected function getRule(): Rule + { + return new NoIssetRule(); + } +}