Style
All insights about style are regrouped in one Metric:
NunoMaduro\PhpInsights\Domain\Metrics\Style\Style
Style
^1.0 Style
Closing tagThis sniff checks that the file does not end with a closing tag.
Insight Class: PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff
^1.0 Style
End file newlineThis sniff ensures the file ends with a newline character.
Insight Class: PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff
^1.0 Style
Side effectsThis sniff ensures a file declares new symbols and causes no other side effects, or executes logic with side effects, but not both.
Insight Class: PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff
^1.0 Style
Git merge conflictThis sniff checks for merge conflict artifacts.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\VersionControl\GitMergeConflictSniff
^1.0 Style
Byte order markThis sniff detects BOMs that may corrupt application work.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Files\ByteOrderMarkSniff
^1.0 Style configurable
Line endingsThis sniff checks that end of line characters are correct.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff
Configuration
\PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineEndingsSniff::class => [
'eolChar' => '\n',
]
^1.0 Style
Function closing braceThis sniff checks that the closing brace of a function goes directly after the body.
Insight Class: PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionClosingBraceSniff
^1.0 Style configurable
Object operator indentThis sniff checks that object operators are indented correctly.
Insight Class: PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ObjectOperatorIndentSniff
Configuration
\PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ObjectOperatorIndentSniff::class => [
'indent' => 4,
]
^1.0 Style configurable
Scope closing braceThis sniff checks that the closing braces of scopes are aligned correctly.
Insight Class: PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff
Configuration
\PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff::class => [
'indent' => 4,
]
^1.0 Style
Disallow long array syntaxThis sniff bans the use of the PHP long array syntax (array()
).
Use []
instead.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays\DisallowLongArraySyntaxSniff
^1.0 Style configurable
Line lengthThis sniff checks the length of all lines in a file.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff
Configuration
\PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff::class => [
'lineLimit' => 80,
'absoluteLineLimit' => 100,
'ignoreComments' => false,
]
^1.0 Style
Space after castThis sniff ensures there is a single space after cast tokens.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterCastSniff
^1.0 Style
Space after notThis sniff ensures there is a single space after a NOT operator.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterNotSniff
^1.0 Style
Function call argument spacingThis sniff checks that calls to methods and functions are spaced correctly.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\Functions\FunctionCallArgumentSpacingSniff
^1.0 Style
Character before PHP opening tagThis sniff checks that the opening PHP tag is the first content in a file.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\CharacterBeforePHPOpeningTagSniff
^1.0 Style
Backtick OperatorThis sniff disallows the use of the backtick execution operator.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\BacktickOperatorSniff
^1.0 Style
Disallow alternative PHP tagsThis sniff verifies that no alternative PHP tags are used.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowAlternativePHPTagsSniff
^1.0 Style
Disallow short open tagThis sniff makes sure that shorthand PHP open tags are not used.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\DisallowShortOpenTagSniff
^1.0 Style
Lower case constantThis sniff checks that all uses of true
, false
and null
are lowercase.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseConstantSniff
^1.0 Style
Lower case keywordThis sniff checks that all PHP keywords are lowercase.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseKeywordSniff
^1.0 Style
Lower case typeThis sniff checks that all PHP types are lowercase.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\LowerCaseTypeSniff
^1.0 Style
SAPI UsageThis sniff ensures the PHP_SAPI
constant is used instead of php_sapi_name()
.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\SAPIUsageSniff
^1.0 Style Deprecated since 2.0
SyntaxThis sniff ensures PHP believes the syntax is clean.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\SyntaxSniff
Note: This sniff is deprecated, use insight below
^2.0 Style
Syntax CheckThis Insight process lint on all PHP files via php -l
using PHP-Parallel-Lint.
Insight Class: NunoMaduro\PhpInsights\Domain\Insights\SyntaxCheck
^1.0 Style
Trailing array commaThis sniff enforces trailing commas in multi-line arrays and requires short array syntax []
.
Commas after the last element in an array make adding a new element easier and result in a cleaner versioning diff.
Insight Class: SlevomatCodingStandard\Sniffs\Arrays\TrailingArrayCommaSniff
^1.0 Style
Arbitrary parentheses spacingThis sniff checks whitespace on the inside of arbitrary parentheses.
Arbitrary parentheses are those which are not owned by a function (call), array or control structure. Spacing on the outside is not checked on purpose as this would too easily conflict with other spacing rules.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ArbitraryParenthesesSpacingSniff
^1.0 Style
Disallow tab indentThis sniff throws errors if tabs are used for indentation.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff
^1.0 Style
Increment decrement spacingThis sniff verifies spacing between variables and increment/decrement operators.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\IncrementDecrementSpacingSniff
^1.0 Style
Language construct spacingThis sniff ensures all language constructs contain a single space between themselves and their content.
Insight Class: PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff
^1.0 Style
Camel caps method nameThis sniff ensures method names are defined using camel case.
Insight Class: PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff
^1.0 Style
Else If declarationThis sniff verifies that there are no else if
statements (elseif
should be used instead).
Insight Class: PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\ElseIfDeclarationSniff
^1.0 Style configurable
Switch declarationThis sniff ensures all switch statements are defined correctly.
Insight Class: PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\SwitchDeclarationSniff
Configuration
\PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\SwitchDeclarationSniff::class => [
'indent' => 4,
]
^1.0 Style
Upper case constant nameThis sniff ensures that constant names are all uppercase.
Insight Class: PHP_CodeSniffer\Standards\Generic\Sniffs\NamingConventions\UpperCaseConstantNameSniff
^1.0 Style
Alphabetically sorted usesThis sniff checks whether uses at the top of a file are alphabetically sorted. Follows natural sorting and takes edge cases with special symbols into consideration.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff
^1.0 Style configurable
Namespace SpacingThis sniff enforces configurable number of lines before and after namespace
.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff
Configuration
\SlevomatCodingStandard\Sniffs\Namespaces\NamespaceSpacingSniff::class => [
'linesCountBeforeNamespace' => 1,
'linesCountAfterNamespace' => 1,
]
^1.0 Style
Require one namespace in fileThis sniff checks there is only one namespace in a file.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\RequireOneNamespaceInFileSniff
^1.0 Style configurable
Unused usesThis sniff detects unused use
in a file.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff
Configuration
\SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff::class => [
'searchAnnotations' => false,
'ignoredAnnotationNames' => [], // case sensitive list of annotation names that the sniff should ignore (only the name is ignored, annotation content is still searched). Useful for name collisions like @testCase annotation and TestCase class.
'ignoredAnnotations' => [], // case sensitive list of annotation names that the sniff ignore completely (both name and content are ignored). Useful for name collisions like @group Cache annotation and Cache class
]
^1.0 Style
Use does not start with BackslashThis sniff disallows leading backslash in use statement.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\UseDoesNotStartWithBackslashSniff
^1.0 Style configurable
Use spacing sniffThis sniff enforces a configurable number of lines before first use, after last use and between two use statements.
Insight Class: SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff
Configuration
\SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff::class => [
'linesCountBeforeFirstUse' => 1,
'linesCountBetweenUseTypes' => 0,
'linesCountAfterLastUse' => 1,
]
^1.0 Style configurable
Spread operator spacingThis sniff enforces a configurable number of spaces after the ...
operator.
Insight Class: SlevomatCodingStandard\Sniffs\Operators\SpreadOperatorSpacingSniff
Configuration
\SlevomatCodingStandard\Sniffs\Operators\SpreadOperatorSpacingSniff::class => [
'spacesCountAfterOperator' => 0,
]
^1.0 Style
Short listThis sniff enforces using short form of list syntax, [...]
instead of list(...)
.
Insight Class: SlevomatCodingStandard\Sniffs\PHP\ShortListSniff
^1.0 Style
Parameter type hint spacingThis sniff
- checks that there's a single space between a type hint and a parameter name:
Foo $foo
- checks that there's no whitespace between a nullability symbol and a type hint:
?Foo
Insight Class: SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSpacingSniff
^1.0 Style configurable
Return type hint spacingThis sniff enforces consistent formatting of return type hints.
Insight Class: SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff
Configuration
\SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSpacingSniff::class => [
'spacesCountBeforeColon' => 0,
]
^1.0 Style configurable
Superfluous WhitespaceThis sniff checks for unneeded whitespace.
Insight Class: PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff
Configuration
\PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff::class => [
'ignoreBlankLines' => false,
]
^1.0 Style configurable
Doc comment spacingThis sniff enforces a configurable number of lines before first content (description or annotation), after last content (description or annotation), between description and annotations and between two different annotations types (eg. between @param
and @return
).
Insight Class: SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff
Configuration
\SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class => [
'linesCountBeforeFirstContent' => 0,
'linesCountBetweenDescriptionAndAnnotations' => 1,
'linesCountBetweenDifferentAnnotationsTypes' => 0,
'linesCountBetweenAnnotationsGroups' => 1,
'linesCountAfterLastContent' => 0,
'annotationsGroups' => [],
]
^1.0 Style
Class instantiationThis sniff verifies that classes are instantiated with parentheses.
Insight Class: PHP_CodeSniffer\Standards\PSR12\Sniffs\Classes\ClassInstantiationSniff
^1.10 Style
No trailing comma in single line arrayThis fixer removes trailing commas in list function calls.
Insight Class: PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer
^1.10 Style configurable
No whitespace before comma in arrayIn array declarations, there MUST NOT be a whitespace before each comma.
Insight Class: PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer
Configuration
\PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer::class => [
'after_heredoc' => false, // Whether the whitespace between heredoc end and comma should be removed.
]
^1.10 Style configurable
BracesThe body of each structure must be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
Insight Class: PhpCsFixer\Fixer\Basic\BracesFixer
Configuration
\PhpCsFixer\Fixer\Basic\BracesFixer::class => [
'allow_single_line_closure' => false,
'position_after_anonymous_constructs' => 'same', // possible values ['same', 'next']
'position_after_control_structures' => 'same', // possible values ['same', 'next']
'position_after_functions_and_oop_constructs' => 'same', // possible values ['same', 'next']
]
^1.10 Style
EncodingPHP code must use only UTF-8 without BOM (remove BOM).
Insight Class: PhpCsFixer\Fixer\Basic\EncodingFixer
^1.10 Style
Lowercase static referenceClass static references self
, static
and parent
must be in lower case.
Insight Class: PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer
^1.10 Style
Magic constant casingMagic constants should be referred to using the correct casing.
Insight Class: PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer
^1.10 Style
Magic method casingMagic method definitions and calls must be using the correct casing.
Insight Class: PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer
^1.10 Style
Native function casingFunction defined by PHP should be called using the correct casing.
Insight Class: PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer
^1.10 Style
Native function type declaration casingNative type hints for functions should use the correct case.
Insight Class: PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer
^1.10 Style configurable
Cast spacesA single space or none should be between cast and variable.
Insight Class: PhpCsFixer\Fixer\CastNotation\CastSpacesFixer
Configuration
\PhpCsFixer\Fixer\CastNotation\CastSpacesFixer::class => [
'space' => 'single' // possible values ['single', 'none']
]
^1.10 Style configurable
Class definition fixerWhitespace around the keywords of a class, trait or interfaces definition should be one space.
Insight Class: PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer
Configuration
\PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer::class => [
'multi_line_extends_each_single_line' => false,
'single_item_single_line' => false,
'single_line' => false,
]
^1.10 Style
No blank lines after class openingEnsure there is no code on the same line as the PHP open tag and it is followed by a blank line.
Insight Class: PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer
^1.10 Style
No trailing whitespace in commentThere must be no trailing spaces inside comment or PHPDoc.
Insight Class: PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer
^1.10 Style
Switch case semicolon to colonA case should be followed by a colon and not a semicolon.
Insight Class: PhpCsFixer\Fixer\ControlStructure\SwitchCaseSemicolonToColonFixer
^1.10 Style
Switch case spaceThis fixer removes extra spaces between colon and case value.
Insight Class: PhpCsFixer\Fixer\ControlStructure\SwitchCaseSpaceFixer
^1.10 Style configurable
Function declarationSpaces should be properly placed in a function declaration.
Insight Class: PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer
Configuration
\PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer::class => [
'closure_function_spacing' => 'one' // possible values ['one', 'none']
]
^1.10 Style
Function type hint spaceThis fixer adds missing spaces between function's argument and its type hint.
Insight Class: PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer
^1.10 Style configurable
Binary operator spaceBinary operators should be surrounded by spaces as configured.
Insight Class: PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer
Configuration
\PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer::class => [
'align_double_arrow' => false, // Whether to apply, remove or ignore double arrows alignment: possibles values [true, false, null]
'align_equals' => false, // Whether to apply, remove or ignore equals alignment: possibles values [true, false, null]
'default' => 'single_space', // default fix strategy: possibles values ['align', 'align_single_space', 'align_single_space_minimal', 'single_space', 'no_space', null]
]
^1.10 Style
Standardize not equalsThis fixer replaces all <>
with !=
.
Insight Class: PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer
^1.10 Style configurable
Align multiline commentEach line of multi-line DocComments must have an asterisk and must be aligned with the first one.
Insight Class: PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer
Configuration
\PhpCsFixer\Fixer\Phpdoc\AlignMultilineCommentFixer::class => [
'comment_type' => 'phpdocs_only' // possible values ['phpdocs_only', 'phpdocs_like', 'all_multiline']
]
^1.10 Style
Full opening tagPHP code must use the long <?php
tags or short-echo <?=
tags and not other tag variations.
Insight Class: PhpCsFixer\Fixer\PhpTag\FullOpeningTagFixer
^1.10 Style
No single line whitespace before semicolonsSingle-line whitespace before closing semicolon are prohibited.
Insight Class: PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer
^1.10 Style configurable
Single quoteThis fixer converts double quotes to single quotes for simple strings.
Insight Class: PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer
Configuration
\PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer::class => [
'strings_containing_single_quote_chars' => false,
]
^1.10 Style
Method chaining indentationMethod chaining must be properly indented. Method chaining with different levels of indentation is not supported.
Insight Class: PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer
^1.10 Style configurable
No extra blank linesThis fixer removes extra blank lines and/or blank lines following configuration.
Insight Class: PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer
Configuration
\PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer::class => [
'tokens' => ['extra'], // possibles values ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']
]
^1.10 Style configurable
No spaces around offsetThere must not be spaces around offset braces.
Insight Class: PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer
Configuration
\PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer::class => [
'positions' => ['inside', 'outside'],
]
^1.10 Style
No spaces inside parenthesisThere must not be a space after the opening parenthesis. There must not be a space before the closing parenthesis.
Insight Class: PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer
^1.10 Style
No trailing whitespaceThis fixer removes trailing whitespace at the end of non-blank lines.
Insight Class: PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer
^1.10 Style
No whitespace in blank lineThis fixer removes trailing whitespace at the end of blank lines.
Insight Class: PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer
^1.10 Style
Single blank line at eofA PHP file without end tag must always end with a single empty line feed.
Insight Class: PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer
^1.10 Style configurable
Ordered class elementsThis sniff orders the elements of classes/interfaces/traits.
Insight Class: PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer
Configuration
\PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer::class => [
'order' => [ // List of strings defining order of elements.
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private',
],
'sort_algorithm' => 'none' // possible values ['none', 'alpha']
]
^1.10 Style configurable
Single class element per statementThere must not be more than one property or constant declared per statement.
Insight Class: PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer
Configuration
\PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer::class => [
'elements' => [
'const',
'property',
],
]
^1.10 Style configurable
Ordered importsThis sniff orders use
statements (import of classes).
Insight Class: PhpCsFixer\Fixer\Import\OrderedImportsFixer
Configuration
\PhpCsFixer\Fixer\Import\OrderedImportsFixer::class => [
'imports_order' => ['class', 'const', 'function'],
'sort_algorithm' => 'alpha', // possible values ['alpha', 'length', 'none']
]
^1.10 Style
Single import pert statementThere must be one use
keyword per declaration.
Insight Class: PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer
^1.10 Style
Phpdoc trimPHPDoc should start and end with content, excluding the very first and last line of the DocBlocks.
Insight Class: PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer
^1.10 Style
Phpdoc var annotation correct order@var
and @type
annotations must have type and name in the correct order.
Insight Class: PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer
^1.10 Style
Phpdoc indentDocBlocks should have the same indentation as the documented subject.
Insight Class: PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer
^1.10 Style
Phpdoc inline tagThis fixer fixes PHPDoc inline tags, make @inheritdoc
always inline.
Insight Class: PhpCsFixer\Fixer\Phpdoc\PhpdocInlineTagFixer