Pravidla
Všechna vestavěná pravidla podle oblasti, každé s odkazem na stránku s příklady a volbami. Pravidlo, které porušení jen hlásí a neopravuje, je tak označeno; pravidlo pro syntaxi novějšího PHP nese verzi, od které se zapíná.
Soubor
Co platí pro celý soubor nebo pro každý jeho řádek: tagy, kódování, konce řádků, hlavička.
- declare-spacing: Removes whitespace inside a declare statement.
- eof-newline: Ends the file with exactly one line ending.
- full-opening-tag: Requires the <?php opening tag.
- header-blank-lines: Puts a fixed number of blank lines around the blocks of the file header.
- line-ending: Unifies line endings.
- line-length Řádek delší než limit se ohlásí; opravit ho pravidlo neumí. (jen hlásí)
- no-byte-order-mark: Removes the UTF-8 byte order mark.
- no-closing-tag: Removes the closing tag at the end of the file.
- no-invisible-characters: Removes or escapes invisible characters in comments and strings, reports them in names.
- no-trailing-whitespace: Removes whitespace at the end of lines.
- strict-types-required: Requires declare(strict_types=1) as the first statement of a file.
Jmenné prostory a importy
Importy a zápis jmen tříd, funkcí a konstant.
- class-reference-name-casing: Writes the names of internal classes and interfaces in their declared case.
- global-imports: Imports the global functions and constants a namespaced file uses.
- import-notation: Writes the imports of each kind one per use statement or all in one, and expands group use declarations.
- no-leading-backslash-in-global-namespace: Removes the leading backslash of names referenced in the global namespace.
- no-leading-backslash-in-import: Removes the leading backslash from imported names.
- ordered-imports: Sorts use statements alphabetically, classes before functions before constants.
- reference-used-names-only: Imports fully qualified names instead of referencing them in place.
- unused-imports Import, který kód nikde nepoužije, se odstraní.
- use-from-same-namespace: Removes imports of names from the current namespace.
- useless-alias: Removes an import alias equal to the imported name.
Třídy
Deklarace třídy a jejích členů.
- class-definition-spacing: Puts single spaces in the head of a class declaration.
- final-internal-class: Makes classes annotated as internal final.
- modern-class-name-reference: Uses ::class instead of get_class() and __CLASS__.
- name-casing: Reports declared names that do not follow the case convention configured for their kind. (jen hlásí)
- no-kind-in-class-name: Reports a class, interface or trait name repeating its kind. (jen hlásí)
- no-this-in-static-context: Reports $this used where no object is available. (jen hlásí)
- ordered-members: Orders class members by kind and visibility.
- self-for-current-class: Replaces the name of the current class with self.
- single-member-per-declaration: Splits a declaration of several constants, properties or traits into one per member.
- single-member-per-line: Puts every member of a class on its own line.
- useless-modifier: Removes a member modifier the class already implies.
- useless-null-property-initialization: Removes the explicit null initialization of untyped properties.
- visibility-required: Requires visibility on class members and orders their modifiers.
Funkce
Deklarace i volání funkcí a metod, parametry a argumenty.
- arrow-function: Replaces a closure returning a single expression with an arrow function.
- forbidden-functions: Reports calls of the configured functions. (jen hlásí)
- function-name-spacing: Removes whitespace between a function name and its parentheses.
- multi-line-call: Puts every argument of a multi-line call on its own line.
- multi-line-signature: Splits long signatures and constructors with promoted properties into one parameter per line.
- named-argument-spacing: Normalizes whitespace around the colon of a named argument.
- native-function-casing: Calls native functions in lowercase.
- no-alias-functions: Calls a function by its canonical name instead of an alias.
- no-conversion-functions: Uses a cast instead of intval() and friends.
- no-deprecated-functions: Reports calls of deprecated internal functions. (jen hlásí)
- no-direct-invoke-call: Calls an invokable object directly instead of its __invoke() method.
- no-dirname-of-file: Replaces dirname(__FILE__) with __DIR__ and nested dirname() calls with the levels argument.
- no-inner-functions: Reports a function declared inside another function. (jen hlásí)
- no-is-null: Replaces is_null() with a comparison with null.
- no-settype: Assigns a cast instead of calling settype().
- no-unpacking-in-optimized-call: Reports argument unpacking in a call of a function the compiler optimizes. (jen hlásí)
- static-closure: Declares a closure that does not use $this as static.
- strict-call: Calls in_array(), array_search(), array_keys(), base64_decode() and mb_detect_encoding() with $strict = true.
- useless-parameter-default: Removes a default value that a required parameter makes unreachable.
Řízení toku
Řídicí struktury, příkazy, bloky a výjimky.
- continuation-position: Puts else, elseif, catch, finally and the while of do on the line of the closing brace, or on the next one.
- control-structure-braces: Encloses the body of every control structure in braces.
- early-exit: Turns a trailing if into a guard that leaves early, and an else that leaves into the first branch.
- elseif-keyword: Replaces else if with elseif.
- fall-through-comment: Requires a comment on an intentional case fall-through.
- multi-line-condition: Splits a long condition of if, elseif, while and do-while into one part per line.
- no-alternative-syntax: Replaces the alternative syntax with braces.
- no-continue-in-switch: Leaves a switch with break, never with continue.
- no-empty-statement: Removes empty statements.
- no-unreachable-catch: Reports a catch block following one that catches Throwable. (jen hlásí)
- reference-throwable-only: Reports references to the general Exception where Throwable belongs. (jen hlásí)
- single-statement-per-line: Puts every statement on its own line.
- switch-case-colon: Ends case and default with a colon.
- switch-case-spacing: Removes whitespace before the colon of a case.
- ternary-for-simple-branch: Uses the ternary operator where an if-else only picks one of two values.
- useless-braces: Removes braces around a bare statement group.
- useless-catch-variable: Removes the variable of a catch clause that is never used.
- useless-construct-parentheses: Removes parentheses around the operand of a language construct.
- useless-else: Removes an else after branches which always leave, and may turn an elseif there into an if.
- useless-if-condition-with-return: Replaces an if returning true or false with a return of the condition.
- useless-return: Removes a bare return at the end of a function body.
Výrazy
Operátory, přetypování, ternár, instanciace a přístup ke členům.
- binary-operator-spacing Kolem binárního operátoru, přiřazení, instanceof, ⇒ a = výchozí hodnoty je z každé strany aspoň jedna mezera, nebo přesně jedna.
- cast-canonical-type: Writes a cast with the short type name in lowercase.
- cast-spacing: Puts a single space between a cast and its operand.
- combined-assignment-operator: Uses += and friends where an assignment repeats its target.
- concat-spacing: Puts a single space around the concatenation operator.
- double-colon-spacing: Removes whitespace around the double colon.
- explicit-operator-precedence: Parenthesizes an operand where the precedence of logical or bitwise operators is easy to misread.
- increment-operator: Uses ++ and – instead of += 1 and -= 1.
- multi-line-chain: Puts every link of a multi-line chain of calls on its own line, the first one included.
- multi-line-ternary: Puts the two operators of a multi-line ternary on lines of their own.
- new-argument-parentheses: Requires or forbids the empty parentheses of an instantiation.
- no-short-bool-cast: Replaces !! with a (bool) cast.
- no-yoda-comparison: Puts the variable side of a comparison on the left.
- not-equals-operator: Writes != instead of <>.
- null-coalescing-operator: Replaces a ternary testing for null with the null coalescing operator.
- object-operator-spacing: Removes whitespace around the object operator.
- offset-bracket-spacing: Removes whitespace around the brackets of an offset access.
- reference-spacing: Removes whitespace between & and its operand.
- short-ternary-operator Ternár, který ve své prostřední části opakuje podmínku, se píše zkráceně jako ?:.
- spread-operator-spacing: Removes whitespace between … and its operand.
- strict-comparison: Replaces loose comparisons with strict ones.
- symbolic-logical-operators: Uses && and || instead of and and or.
- ternary-operator-spacing: Puts whitespace around the ternary operators.
- unary-operator-spacing: Removes whitespace between a unary operator and its operand.
- useless-parentheses-around-new: Removes the parentheses around new when a member of the new object is accessed. (PHP 8.4+)
- useless-ternary-operator: Replaces a ternary operator choosing between true and false with the condition.
Literály
Zápis řetězců, čísel, konstant a klíčových slov.
- complex-string-variable: Replaces the deprecated ${name} interpolation with {$name}.
- constant-casing: Lowercases true, false and null.
- heredoc-indentation: Indents the body and the closing marker of a heredoc relative to its starting line.
- keyword-casing: Writes keywords in lowercase.
- magic-constant-casing: Writes magic constants in uppercase.
- no-backtick-operator: Runs a command through shell_exec() instead of backticks.
- no-implicit-backslash: Writes every backslash of a string escaped.
- no-trailing-whitespace-in-string: Removes trailing whitespace from string lines.
- nowdoc-without-interpolation: Uses nowdoc where a heredoc interpolates nothing.
- numeric-literal-separator: Groups the digits of long numbers with underscores.
- octal-notation Osmičkové číslo se píše s prefixem 0o, ne s pouhou nulou na začátku. (PHP 8.1+)
- single-quoted-strings: Uses single quotes where double quotes give nothing.
- useless-string-concat: Joins two string literals concatenated on one line and drops concatenation with an empty string.
Pole
Pole a destrukturace jako syntaktická konstrukce.
- array-spacing: Removes whitespace inside the brackets of an array.
- multi-line-array: Puts every item of a multi-line array on its own line and the opening bracket on the line before.
- short-array-syntax: Writes arrays with the short syntax.
- short-list-syntax: Uses the short syntax for destructuring instead of list().
- trailing-comma Víceřádkový seznam končí čárkou za poslední položkou, jednořádkový ji nemá.
Typy
Typové deklarace v kódu, ne v anotacích.
- nullable-type-for-default-null: Marks the type of a parameter defaulting to null as nullable.
- type-hint-required: Adds native types from annotations and reports declarations without any type.
- type-hint-spacing: Normalizes whitespace in type declarations.
- union-type-format: Writes a nullable type as ?T, puts null last in a union type and may sort the rest.
PhpDoc
Dokumentační komentáře a anotace v nich.
- annotation-name: Writes known annotations in their canonical case.
- attribute-after-phpdoc: Moves a doc comment written after the attributes above them.
- explicit-assertion: Replaces an inline @var annotation with an assert() of the type.
- forbidden-annotations: Removes the configured annotations from doc comments.
- forbidden-phpdoc-lines: Removes description lines matching the configured patterns from doc comments.
- no-duplicate-return-annotation: Reports more than one @return in a function doc comment. (jen hlásí)
- no-empty-phpdoc: Removes empty doc comments.
- no-empty-var-annotation: Reports a @var or @see without content in a property doc comment. (jen hlásí)
- no-unknown-param-annotation: Reports a @param of a parameter the function does not declare. (jen hlásí)
- phpdoc-alignment: Aligns the stars of a doc comment with its opening.
- phpdoc-canonical-types: Writes the types in doc comments in their canonical form: short lowercase built-ins, one array notation, no repeated type in a union.
- phpdoc-null-last: Moves null to the end of union types in doc comments.
- phpdoc-trim: Removes extra blank lines in a doc comment.
- property-phpdoc-required: Reports a plain comment in place of a property doc comment. (jen hlásí)
- property-phpdoc-single-line: Writes a property doc comment with a single line of content on one line.
- property-var-annotation: Reports a repeated or misplaced @var in a property doc comment. (jen hlásí)
- useless-constant-var-annotation: Removes a useless @var from a class constant.
- useless-function-phpdoc: Removes a function doc comment that only repeats the native types.
- useless-inheritdoc: Removes a doc comment consisting of @inheritDoc only.
Komentáře
Obyčejné komentáře.
- comment-spacing: Puts a space after the marker of a comment and before a comment following code.
- commented-out-function: Comments out statements calling the configured debugging functions.
- no-empty-comment: Removes empty comments.
- no-hash-comment: Writes single-line comments with //, not #.
Proměnné
Proměnné, jejich rozsah a životnost.
- combined-issets: Asks about several variables in one isset() instead of a chain joined by &&.
- combined-unsets: Drops several variables in one unset instead of consecutive statements.
- no-duplicate-assignment: Reports an assignment repeated to the same variable in one expression. (jen hlásí)
- no-global-keyword: Forbids the global statement. (jen hlásí)
- no-unset-on-property: Assigns null to a property instead of unsetting it.
Bílé znaky
Bílé znaky, které nepatří žádné jedné konstrukci: odsazení, závorky, čárky, prázdné řádky.
- attribute-position: Puts the attributes of a declaration on lines of their own above it.
- attribute-spacing: Removes whitespace inside the brackets of an attribute group and the empty parentheses of an attribute.
- body-blank-lines: Removes the blank line after the opening brace of a block.
- braces-position Otevírací složená závorka stojí u tříd a funkcí na vlastním řádku a u řídicích struktur, closures a anonymních tříd na řádku hlavičky; tělo začíná na novém řádku a zavírací závorka má řádek pro sebe.
- comma-spacing: Puts a single space after a comma and none before it.
- construct-spacing: Puts a single space around language constructs.
- declaration-blank-lines Mezi metodami jsou dva prázdné řádky, mezi vlastnostmi a konstantami nejvýš jeden, za otevírací závorkou třídy a před zavírací žádný a dokumentační komentář se drží své deklarace.
- indentation: Indents every line by the construct it continues, one level per nesting.
- parentheses-spacing: Removes whitespace inside parentheses.
- semicolon-spacing: Removes whitespace before a semicolon and puts a single space after it.
- single-level-indentation: Reports indentation that deepens by more than a level or returns to a level nothing opened. (jen hlásí)
- statement-blank-lines: Puts blank lines before and after statements of the configured kinds.