From 04fda3833cba821d352e520d1a2844a2604cdd96 Mon Sep 17 00:00:00 2001 From: Enrico Date: Wed, 12 Oct 2016 13:10:10 +0200 Subject: [PATCH] Add analyzer descriptions --- docs/05_Analyzers.md | 13 +++++++++---- .../Pass/Expression/ArrayIllegalOffsetType.php | 2 ++ .../Pass/Expression/ArrayShortDefinition.php | 2 +- src/Analyzer/Pass/Expression/BacktickUsage.php | 2 ++ src/Analyzer/Pass/Expression/Casts.php | 2 ++ .../Pass/Expression/CompareWithArray.php | 2 ++ .../Pass/Expression/ErrorSuppression.php | 2 ++ src/Analyzer/Pass/Expression/EvalUsage.php | 2 ++ src/Analyzer/Pass/Expression/ExitUsage.php | 2 ++ .../Pass/Expression/FinalStaticUsage.php | 17 ++++++++++++++++- .../Pass/Expression/FunctionCall/AliasCheck.php | 2 ++ .../FunctionCall/ArgumentUnpacking.php | 2 ++ .../Pass/Expression/FunctionCall/DebugCode.php | 2 ++ .../FunctionCall/DeprecatedFunctions.php | 2 ++ .../FunctionCall/DeprecatedIniOptions.php | 2 ++ .../FunctionCall/RandomApiMigration.php | 2 ++ .../FunctionCall/RegularExpressions.php | 2 ++ .../Pass/Expression/FunctionCall/UseCast.php | 2 ++ src/Analyzer/Pass/Expression/LogicInversion.php | 2 ++ .../Pass/Expression/MultipleUnaryOperators.php | 2 ++ .../Pass/Expression/StupidUnaryOperators.php | 2 ++ .../Pass/Expression/VariableVariableUsage.php | 2 ++ .../Pass/Statement/AssignmentInCondition.php | 2 ++ src/Analyzer/Pass/Statement/ConstantNaming.php | 2 ++ src/Analyzer/Pass/Statement/GlobalUsage.php | 2 ++ src/Analyzer/Pass/Statement/GotoUsage.php | 2 ++ .../Pass/Statement/HasMoreThanOneProperty.php | 2 ++ src/Analyzer/Pass/Statement/InlineHtmlUsage.php | 2 ++ .../Pass/Statement/MagicMethodParameters.php | 2 ++ .../Pass/Statement/MethodCannotReturn.php | 2 ++ src/Analyzer/Pass/Statement/MissingBody.php | 2 ++ .../Pass/Statement/MissingBreakStatement.php | 2 ++ src/Analyzer/Pass/Statement/MissingDocblock.php | 2 ++ .../Pass/Statement/MissingVisibility.php | 2 ++ src/Analyzer/Pass/Statement/OldConstructor.php | 2 ++ .../Statement/OptionalParamBeforeRequired.php | 2 ++ src/Analyzer/Pass/Statement/StaticUsage.php | 2 ++ src/Analyzer/Pass/Statement/TestAnnotation.php | 2 ++ .../Pass/Statement/UnexpectedUseOfThis.php | 2 ++ src/Analyzer/Pass/Statement/YodaCondition.php | 2 ++ 40 files changed, 100 insertions(+), 6 deletions(-) diff --git a/docs/05_Analyzers.md b/docs/05_Analyzers.md index b4cbce9d..55105611 100644 --- a/docs/05_Analyzers.md +++ b/docs/05_Analyzers.md @@ -12,7 +12,8 @@ Checks for use of `func_get_args()` and suggests the use of argument unpacking. #### ArrayDuplicateKeys -Checks for duplicate array keys on definition. Can handle variable keys. +This inspection reports any duplicated keys on array creation expression. +If multiple elements in the array declaration use the same key, only the last one will be used as all others are overwritten. #### ArrayIllegalOffsetType @@ -36,7 +37,7 @@ Checks for casts that try to cast a type to itself. #### CompareWithArray -Checks for `{type array} > 1` and similar and suggests use of `count()`. +Checks for `{type array} > 1` and similar and suggests use of `count()`. #### ConstantNaming @@ -56,7 +57,7 @@ Checks for use of deprecated php.ini options and gives alternatives if available #### ErrorSuppression -Discourages the use of @ operator to silence errors. +Discourages the use of the `@` operator to silence errors. #### EvalUsage @@ -68,7 +69,7 @@ Discourages the use of `exit()` and `die()`. #### FinalStaticUsage -Checks for use of static:: inside a final class. +Checks for use of `static::` inside a final class. #### GlobalUsage @@ -86,6 +87,10 @@ Checks for multiple property definitions in one line. For example public $a, $b; Discourages the use of inline html. +#### LogicInversion + +Checks for Logic inversion like `if (!($a == $b))` and suggests the correct operator. + #### MagicMethodParameters Checks that magic methods have the right amount of parameters. diff --git a/src/Analyzer/Pass/Expression/ArrayIllegalOffsetType.php b/src/Analyzer/Pass/Expression/ArrayIllegalOffsetType.php index e85dd596..9c21e9bd 100644 --- a/src/Analyzer/Pass/Expression/ArrayIllegalOffsetType.php +++ b/src/Analyzer/Pass/Expression/ArrayIllegalOffsetType.php @@ -14,6 +14,8 @@ class ArrayIllegalOffsetType implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for illegal array key types (for example objects).'; + /** * @param Expr\Array_|Expr\Assign $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/ArrayShortDefinition.php b/src/Analyzer/Pass/Expression/ArrayShortDefinition.php index 89f604c7..c4b635da 100644 --- a/src/Analyzer/Pass/Expression/ArrayShortDefinition.php +++ b/src/Analyzer/Pass/Expression/ArrayShortDefinition.php @@ -16,7 +16,7 @@ class ArrayShortDefinition implements AnalyzerPassInterface DefaultMetadataPassTrait::getMetadata as defaultMetadata; } - const DESCRIPTION = 'Short syntax can be used in array literals.'; + const DESCRIPTION = 'Recommends the use of [] short syntax for arrays.'; /** * @param Expr\Array_ $expr diff --git a/src/Analyzer/Pass/Expression/BacktickUsage.php b/src/Analyzer/Pass/Expression/BacktickUsage.php index baa37ad4..f7fe3848 100644 --- a/src/Analyzer/Pass/Expression/BacktickUsage.php +++ b/src/Analyzer/Pass/Expression/BacktickUsage.php @@ -11,6 +11,8 @@ class BacktickUsage implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of backtick operator for shell execution.'; + /** * @param Expr\ShellExec $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/Casts.php b/src/Analyzer/Pass/Expression/Casts.php index f9c65187..4a88d714 100644 --- a/src/Analyzer/Pass/Expression/Casts.php +++ b/src/Analyzer/Pass/Expression/Casts.php @@ -12,6 +12,8 @@ class Casts implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for casts that try to cast a type to itself.'; + /** * @param Expr $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/CompareWithArray.php b/src/Analyzer/Pass/Expression/CompareWithArray.php index 76b09f93..6414c0b9 100644 --- a/src/Analyzer/Pass/Expression/CompareWithArray.php +++ b/src/Analyzer/Pass/Expression/CompareWithArray.php @@ -11,6 +11,8 @@ class CompareWithArray implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for `{type array} > 1` and similar and suggests use of `count()`.'; + /** * @param Expr $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/ErrorSuppression.php b/src/Analyzer/Pass/Expression/ErrorSuppression.php index 16dfd859..79c194fd 100644 --- a/src/Analyzer/Pass/Expression/ErrorSuppression.php +++ b/src/Analyzer/Pass/Expression/ErrorSuppression.php @@ -11,6 +11,8 @@ class ErrorSuppression implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of the `@` operator to silence errors.'; + /** * @param Expr\ErrorSuppress $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/EvalUsage.php b/src/Analyzer/Pass/Expression/EvalUsage.php index b19234ab..670a64c0 100644 --- a/src/Analyzer/Pass/Expression/EvalUsage.php +++ b/src/Analyzer/Pass/Expression/EvalUsage.php @@ -14,6 +14,8 @@ class EvalUsage implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of `eval()`.'; + /** * @param Expr\Eval_ $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/ExitUsage.php b/src/Analyzer/Pass/Expression/ExitUsage.php index 30bb07c7..00bb8f99 100644 --- a/src/Analyzer/Pass/Expression/ExitUsage.php +++ b/src/Analyzer/Pass/Expression/ExitUsage.php @@ -14,6 +14,8 @@ class ExitUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of `exit()` and `die()`.'; + /** * @param Expr\Exit_ $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/FinalStaticUsage.php b/src/Analyzer/Pass/Expression/FinalStaticUsage.php index 5e347f68..6e84d8e8 100644 --- a/src/Analyzer/Pass/Expression/FinalStaticUsage.php +++ b/src/Analyzer/Pass/Expression/FinalStaticUsage.php @@ -10,7 +10,11 @@ class FinalStaticUsage implements AnalyzerPassInterface { - use DefaultMetadataPassTrait; + use DefaultMetadataPassTrait { + DefaultMetadataPassTrait::getMetadata as defaultMetadata; + } + + const DESCRIPTION = 'Checks for use of `static::` inside a final class.'; /** * @param Expr\StaticCall $expr @@ -46,4 +50,15 @@ public function getRegister() Expr\StaticCall::class, ]; } + + /** + * {@inheritdoc} + */ + public static function getMetadata() + { + $metadata = self::defaultMetadata(); + $metadata->setRequiredPhpVersion('5.3'); //static:: since PHP 5.3 + + return $metadata; + } } diff --git a/src/Analyzer/Pass/Expression/FunctionCall/AliasCheck.php b/src/Analyzer/Pass/Expression/FunctionCall/AliasCheck.php index d19b4355..d5cb051e 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/AliasCheck.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/AliasCheck.php @@ -10,6 +10,8 @@ class AliasCheck extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of alias functions and suggests the use of the originals.'; + protected $map = [ 'join' => 'implode', 'sizeof' => 'count', diff --git a/src/Analyzer/Pass/Expression/FunctionCall/ArgumentUnpacking.php b/src/Analyzer/Pass/Expression/FunctionCall/ArgumentUnpacking.php index 6d7903c8..d3ca90b9 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/ArgumentUnpacking.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/ArgumentUnpacking.php @@ -9,6 +9,8 @@ class ArgumentUnpacking extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of `func_get_args()` and suggests the use of argument unpacking. (... operator)'; + public function pass(FuncCall $funcCall, Context $context) { $functionName = $this->resolveFunctionName($funcCall, $context); diff --git a/src/Analyzer/Pass/Expression/FunctionCall/DebugCode.php b/src/Analyzer/Pass/Expression/FunctionCall/DebugCode.php index 843d0fdb..3bc9fb19 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/DebugCode.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/DebugCode.php @@ -11,6 +11,8 @@ class DebugCode extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of debug code and suggests to remove it.'; + protected $map = [ 'var_dump' => 'var_dump', 'var_export' => 'var_export', diff --git a/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedFunctions.php b/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedFunctions.php index e579fd2b..fc653f8e 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedFunctions.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedFunctions.php @@ -7,6 +7,8 @@ class DeprecatedFunctions extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of deprecated functions and gives alternatives if available.'; + protected $map = [ 'datefmt_set_timezone_id' => ['5.5','IntlDateFormatter::setTimeZone()'], 'define_syslog_variables' => ['5.3','_'], diff --git a/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedIniOptions.php b/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedIniOptions.php index 8cb3ea90..258d11d7 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedIniOptions.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/DeprecatedIniOptions.php @@ -10,6 +10,8 @@ class DeprecatedIniOptions extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of deprecated php.ini options and gives alternatives if available.'; + static protected $functions = [ 'ini_set' => 'ini_set', 'ini_get' => 'ini_get', diff --git a/src/Analyzer/Pass/Expression/FunctionCall/RandomApiMigration.php b/src/Analyzer/Pass/Expression/FunctionCall/RandomApiMigration.php index 2c00522a..6a5bc43a 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/RandomApiMigration.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/RandomApiMigration.php @@ -10,6 +10,8 @@ class RandomApiMigration extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of old rand, srand, getrandmax functions and suggests alternatives.'; + protected $map = [ 'rand' => 'mt_rand', 'srand' => 'mt_srand', diff --git a/src/Analyzer/Pass/Expression/FunctionCall/RegularExpressions.php b/src/Analyzer/Pass/Expression/FunctionCall/RegularExpressions.php index 62b7c681..928e659f 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/RegularExpressions.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/RegularExpressions.php @@ -12,6 +12,8 @@ class RegularExpressions extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks that regular expressions are syntactically correct.'; + static public $map = [ 'preg_filter' => 0, 'preg_grep' => 0, diff --git a/src/Analyzer/Pass/Expression/FunctionCall/UseCast.php b/src/Analyzer/Pass/Expression/FunctionCall/UseCast.php index 53d47f34..014cb8e5 100644 --- a/src/Analyzer/Pass/Expression/FunctionCall/UseCast.php +++ b/src/Analyzer/Pass/Expression/FunctionCall/UseCast.php @@ -10,6 +10,8 @@ class UseCast extends AbstractFunctionCallAnalyzer { + const DESCRIPTION = 'Checks for use of functions like boolval, strval and others and suggests the use of casts.'; + protected $map = [ 'boolval' => 'bool', 'intval' => 'int', diff --git a/src/Analyzer/Pass/Expression/LogicInversion.php b/src/Analyzer/Pass/Expression/LogicInversion.php index 9245a152..d5980344 100644 --- a/src/Analyzer/Pass/Expression/LogicInversion.php +++ b/src/Analyzer/Pass/Expression/LogicInversion.php @@ -14,6 +14,8 @@ class LogicInversion implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for Logic inversion like `if (!($a == $b))` and suggests the correct operator.'; + protected $map = [ 'Expr_BinaryOp_Equal' => ['!=', '=='], 'Expr_BinaryOp_NotEqual' => ['==', '!='], diff --git a/src/Analyzer/Pass/Expression/MultipleUnaryOperators.php b/src/Analyzer/Pass/Expression/MultipleUnaryOperators.php index e060d0d1..b0b67629 100644 --- a/src/Analyzer/Pass/Expression/MultipleUnaryOperators.php +++ b/src/Analyzer/Pass/Expression/MultipleUnaryOperators.php @@ -11,6 +11,8 @@ class MultipleUnaryOperators implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for use of multiple unary operators that cancel each other out. For example `!!boolean` or `- -int`. (there is a space between the two minus)'; + /** * @param Expr $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/StupidUnaryOperators.php b/src/Analyzer/Pass/Expression/StupidUnaryOperators.php index 8fbb9851..7f798db1 100644 --- a/src/Analyzer/Pass/Expression/StupidUnaryOperators.php +++ b/src/Analyzer/Pass/Expression/StupidUnaryOperators.php @@ -11,6 +11,8 @@ class StupidUnaryOperators implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for use of UnaryPlus `+$a` and suggests to use an int or float cast instead.'; + /** * @param Expr $expr * @param Context $context diff --git a/src/Analyzer/Pass/Expression/VariableVariableUsage.php b/src/Analyzer/Pass/Expression/VariableVariableUsage.php index c91f0a5b..b9c4f17a 100644 --- a/src/Analyzer/Pass/Expression/VariableVariableUsage.php +++ b/src/Analyzer/Pass/Expression/VariableVariableUsage.php @@ -14,6 +14,8 @@ class VariableVariableUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of variable variables.'; + /** * @param Expr\Assign $expr * @param Context $context diff --git a/src/Analyzer/Pass/Statement/AssignmentInCondition.php b/src/Analyzer/Pass/Statement/AssignmentInCondition.php index da502e10..0a6f7b82 100644 --- a/src/Analyzer/Pass/Statement/AssignmentInCondition.php +++ b/src/Analyzer/Pass/Statement/AssignmentInCondition.php @@ -22,6 +22,8 @@ class AssignmentInCondition implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for assignments in conditions. (= instead of ==)'; + /** * @param $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/ConstantNaming.php b/src/Analyzer/Pass/Statement/ConstantNaming.php index 093a22eb..86124176 100644 --- a/src/Analyzer/Pass/Statement/ConstantNaming.php +++ b/src/Analyzer/Pass/Statement/ConstantNaming.php @@ -12,6 +12,8 @@ class ConstantNaming implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks that constants are all uppercase.'; + /** * @param ClassConst $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/GlobalUsage.php b/src/Analyzer/Pass/Statement/GlobalUsage.php index 9f9ea09c..12bc8423 100644 --- a/src/Analyzer/Pass/Statement/GlobalUsage.php +++ b/src/Analyzer/Pass/Statement/GlobalUsage.php @@ -13,6 +13,8 @@ class GlobalUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of `global $var;`.'; + /** * @param $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/GotoUsage.php b/src/Analyzer/Pass/Statement/GotoUsage.php index 890c8a1b..4a0830c7 100644 --- a/src/Analyzer/Pass/Statement/GotoUsage.php +++ b/src/Analyzer/Pass/Statement/GotoUsage.php @@ -14,6 +14,8 @@ class GotoUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of goto and goto labels.'; + /** * @param $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/HasMoreThanOneProperty.php b/src/Analyzer/Pass/Statement/HasMoreThanOneProperty.php index 5b74afdb..b67aa12f 100644 --- a/src/Analyzer/Pass/Statement/HasMoreThanOneProperty.php +++ b/src/Analyzer/Pass/Statement/HasMoreThanOneProperty.php @@ -13,6 +13,8 @@ class HasMoreThanOneProperty implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for multiple property definitions in one line. For example public $a, $b; and discourages it.'; + /** * @param Property $prop * @param Context $context diff --git a/src/Analyzer/Pass/Statement/InlineHtmlUsage.php b/src/Analyzer/Pass/Statement/InlineHtmlUsage.php index c7e22bf4..740360fb 100644 --- a/src/Analyzer/Pass/Statement/InlineHtmlUsage.php +++ b/src/Analyzer/Pass/Statement/InlineHtmlUsage.php @@ -12,6 +12,8 @@ class InlineHtmlUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of inline html.'; + /** * @param Stmt\InlineHTML $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/MagicMethodParameters.php b/src/Analyzer/Pass/Statement/MagicMethodParameters.php index 61c87e6f..3083e2f0 100644 --- a/src/Analyzer/Pass/Statement/MagicMethodParameters.php +++ b/src/Analyzer/Pass/Statement/MagicMethodParameters.php @@ -15,6 +15,8 @@ class MagicMethodParameters implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks that magic methods have the right amount of parameters.'; + /** * @param ClassMethod $methodStmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/MethodCannotReturn.php b/src/Analyzer/Pass/Statement/MethodCannotReturn.php index 04634067..35f7aaa8 100644 --- a/src/Analyzer/Pass/Statement/MethodCannotReturn.php +++ b/src/Analyzer/Pass/Statement/MethodCannotReturn.php @@ -16,6 +16,8 @@ class MethodCannotReturn implements Pass\AnalyzerPassInterface use DefaultMetadataPassTrait; use ResolveExpressionTrait; + const DESCRIPTION = 'Checks for return statements in `__construct` and `__destruct` since they can\'t return anything.'; + /** * @param ClassMethod $methodStmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/MissingBody.php b/src/Analyzer/Pass/Statement/MissingBody.php index 4a8771ed..847c5d18 100644 --- a/src/Analyzer/Pass/Statement/MissingBody.php +++ b/src/Analyzer/Pass/Statement/MissingBody.php @@ -10,6 +10,8 @@ class MissingBody implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + + const DESCRIPTION = 'Checks that statements that define a block of statements are not empty.'; /** * @param Stmt $stmt diff --git a/src/Analyzer/Pass/Statement/MissingBreakStatement.php b/src/Analyzer/Pass/Statement/MissingBreakStatement.php index 98d93e98..1ad2f8f4 100644 --- a/src/Analyzer/Pass/Statement/MissingBreakStatement.php +++ b/src/Analyzer/Pass/Statement/MissingBreakStatement.php @@ -14,6 +14,8 @@ class MissingBreakStatement implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for a missing break or return statement in switch cases. Can ignore empty cases and the last case.'; + /** * @param Stmt\Switch_ $switchStmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/MissingDocblock.php b/src/Analyzer/Pass/Statement/MissingDocblock.php index 19749592..45ef39a0 100644 --- a/src/Analyzer/Pass/Statement/MissingDocblock.php +++ b/src/Analyzer/Pass/Statement/MissingDocblock.php @@ -11,6 +11,8 @@ class MissingDocblock implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for a missing docblock for: class, property, class constant, trait, interface, class method, function.'; + /** * @param Stmt $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/MissingVisibility.php b/src/Analyzer/Pass/Statement/MissingVisibility.php index 0831ade8..abf931d9 100644 --- a/src/Analyzer/Pass/Statement/MissingVisibility.php +++ b/src/Analyzer/Pass/Statement/MissingVisibility.php @@ -14,6 +14,8 @@ class MissingVisibility implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for missing visibility modifiers for properties and methods.'; + /** * @param Stmt $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/OldConstructor.php b/src/Analyzer/Pass/Statement/OldConstructor.php index ebc9275e..28aeee0b 100644 --- a/src/Analyzer/Pass/Statement/OldConstructor.php +++ b/src/Analyzer/Pass/Statement/OldConstructor.php @@ -11,6 +11,8 @@ class OldConstructor implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for use of PHP 4 constructors and discourages it.'; + /** * @param Stmt\Class_ $classStmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/OptionalParamBeforeRequired.php b/src/Analyzer/Pass/Statement/OptionalParamBeforeRequired.php index 3b55abd9..f2d9a66e 100644 --- a/src/Analyzer/Pass/Statement/OptionalParamBeforeRequired.php +++ b/src/Analyzer/Pass/Statement/OptionalParamBeforeRequired.php @@ -14,6 +14,8 @@ class OptionalParamBeforeRequired implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks if any optional parameters are before a required one. For example: `function ($a = 1, $b)`'; + /** * @param Stmt $func * @param Context $context diff --git a/src/Analyzer/Pass/Statement/StaticUsage.php b/src/Analyzer/Pass/Statement/StaticUsage.php index 685afaaa..0409e788 100644 --- a/src/Analyzer/Pass/Statement/StaticUsage.php +++ b/src/Analyzer/Pass/Statement/StaticUsage.php @@ -11,6 +11,8 @@ class StaticUsage implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Discourages the use of static variables (not properties).'; + /** * @param Static_ $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/TestAnnotation.php b/src/Analyzer/Pass/Statement/TestAnnotation.php index ac068764..19913d54 100644 --- a/src/Analyzer/Pass/Statement/TestAnnotation.php +++ b/src/Analyzer/Pass/Statement/TestAnnotation.php @@ -12,6 +12,8 @@ class TestAnnotation implements AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for use of `@test` when methods name begins with test, since it is unnecessary.'; + /** @var DocBlockFactory */ protected $docBlockFactory; diff --git a/src/Analyzer/Pass/Statement/UnexpectedUseOfThis.php b/src/Analyzer/Pass/Statement/UnexpectedUseOfThis.php index 8e00e0f1..77c08b17 100644 --- a/src/Analyzer/Pass/Statement/UnexpectedUseOfThis.php +++ b/src/Analyzer/Pass/Statement/UnexpectedUseOfThis.php @@ -15,6 +15,8 @@ class UnexpectedUseOfThis implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for behavior that would result in overwriting $this variable.'; + /** * @param Node\Stmt $stmt * @param Context $context diff --git a/src/Analyzer/Pass/Statement/YodaCondition.php b/src/Analyzer/Pass/Statement/YodaCondition.php index b0052abc..af846b9d 100644 --- a/src/Analyzer/Pass/Statement/YodaCondition.php +++ b/src/Analyzer/Pass/Statement/YodaCondition.php @@ -21,6 +21,8 @@ class YodaCondition implements Pass\AnalyzerPassInterface { use DefaultMetadataPassTrait; + const DESCRIPTION = 'Checks for Yoda conditions, where a constant is placed before the variable. For example: `if (3 == $a)`'; + /** * @param $stmt * @param Context $context