Skip to content

Instantly share code, notes, and snippets.

@AlexNDRmac
Last active May 7, 2019 18:33
Show Gist options
  • Save AlexNDRmac/88214afd6343f36ba6cda58704d33679 to your computer and use it in GitHub Desktop.
Save AlexNDRmac/88214afd6343f36ba6cda58704d33679 to your computer and use it in GitHub Desktop.
Mess Detector Inspections

Suppress specific PHPMD warnings

Unused code:

  • UnusedPrivateField
  • UnusedLocalVariable
  • UnusedPrivateMethod
  • UnusedFormalParameter

Naming:

  • ShortVariable
  • LongVariable
  • ShortMethodName
  • ConstructorWithNameAsEnclosingClass
  • ConstantNamingConventions
  • BooleanGetMethodName
  • VariableNamingConventions
  • MethodNamingConventions
  • ClassNamingConventions
  • AbstractNaming
  • AvoidFieldNameMatchingTypeName
  • AvoidFieldNameMatchingMethodName
  • NoPackage
  • MisleadingVariableName

Design:

  • ExitExpression
  • EvalExpression
  • GotoStatement
  • NumberOfChildren
  • DepthOfInheritance
  • CouplingBetweenObjects
  • DevelopmentCodeFragment

Controversial:

  • Superglobals
  • CamelCaseClassName
  • CamelCasePropertyName
  • CamelCaseMethodName
  • CamelCaseParameterName
  • CamelCaseVariableName

Code size:

  • CyclomaticComplexity
  • NPathComplexity
  • ExcessiveMethodLength
  • ExcessiveClassLength
  • ExcessiveParameterList
  • ExcessivePublicCount
  • TooManyFields
  • NcssMethodCount
  • NcssTypeCount
  • NcssConstructorCount
  • TooManyMethods
  • TooManyPublicMethods
  • ExcessiveClassComplexity

Clean code:

  • BooleanArgumentFlag
  • ElseExpression
  • StaticAccess
  • BooleanGetMethodName
  • ConstantNamingConventions
  • ConstructorWithNameAsEnclosingClass
  • CouplingBetweenObjects
  • CyclomaticComplexity
  • DepthOfInheritance
  • EvalExpression
  • ExcessiveClassComplexity
  • ExcessiveClassLength
  • ExcessiveMethodLength
  • ExcessiveParameterList
  • ExcessivePublicCount
  • GotoStatement
  • LongVariable
  • NPathComplexity
  • NumberOfChildren
  • ShortMethodName
  • ShortVariable
  • TooManyFields
  • TooManyMethods
  • UnusedLocalVariable
  • UnusedPrivateMethod

Example:

<?php

namespace Tests;

/**
 * Suppress PHPMD Warnings for Camel Case Method Name for whole Class
 *
 * @SuppressWarnings(PHPMD.CamelCaseMethodName)
 */
Class UserTest
{

    public function it_can_use_snake_case(): bool
    {
        return true;
    }

    /**
     * Suppress Specific PHPMD Warnings for one Method in Class
     *
     * @SuppressWarnings(PHPMD.BooleanGetMethodName)
     * @SuppressWarnings(PHPMD.ShortMethodName)
     *
     * @return bool
     */
    public function on(): bool
    {
        return $this->active;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment