Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #238 from ddmler/config-descriptions
Browse files Browse the repository at this point in the history
Add analyzer descriptions
  • Loading branch information
ovr authored Oct 12, 2016
2 parents 705840f + 04fda38 commit 9dffcdc
Show file tree
Hide file tree
Showing 40 changed files with 100 additions and 6 deletions.
13 changes: 9 additions & 4 deletions docs/05_Analyzers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/ArrayIllegalOffsetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzer/Pass/Expression/ArrayShortDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/BacktickUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/Casts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/CompareWithArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/ErrorSuppression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/EvalUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class EvalUsage implements AnalyzerPassInterface
{
use DefaultMetadataPassTrait;

const DESCRIPTION = 'Discourages the use of `eval()`.';

/**
* @param Expr\Eval_ $expr
* @param Context $context
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/ExitUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/Analyzer/Pass/Expression/FinalStaticUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/FunctionCall/AliasCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/FunctionCall/DebugCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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','_'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/FunctionCall/UseCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/LogicInversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ['==', '!='],
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/MultipleUnaryOperators.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/StupidUnaryOperators.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Expression/VariableVariableUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/AssignmentInCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/ConstantNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ConstantNaming implements AnalyzerPassInterface
{
use DefaultMetadataPassTrait;

const DESCRIPTION = 'Checks that constants are all uppercase.';

/**
* @param ClassConst $stmt
* @param Context $context
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/GlobalUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class GlobalUsage implements Pass\AnalyzerPassInterface
{
use DefaultMetadataPassTrait;

const DESCRIPTION = 'Discourages the use of `global $var;`.';

/**
* @param $stmt
* @param Context $context
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/GotoUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/HasMoreThanOneProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/InlineHtmlUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MagicMethodParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MethodCannotReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MissingBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MissingBreakStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MissingDocblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/MissingVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/OldConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/OptionalParamBeforeRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Analyzer/Pass/Statement/StaticUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 9dffcdc

Please sign in to comment.