Přehled pravidel

Všechna vestavěná pravidla DressCode podle oblasti, u každého odkaz na stránku s příklady a volbami. Pravidlo, které porušení jen hlásí a neopravuje, je tak označeno, stejně jako pravidlo, jehož opravy mohou změnit chování kódu a čekají na svolení v klíči fixRisky; pravidlo pro syntaxi novějšího PHP nese verzi, od které se zapíná.

Pravidla se zapínají standardem, skupinou nebo jednotlivě v konfiguraci; jméno pravidla je to, co vidíte ve výpisu dresscode check, a dresscode explain <pravidlo> k němu vypíše volby i příklad.

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.
  • line-ending: Unifies line endings.
  • line-length Řádek širší než délka řádku z konfigurace se ohlásí; opravit ho pravidlo neumí. (jen hlásí)
  • no-bom: 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. (rizikové opravy)

Jmenné prostory a importy

Importy a zápis jmen tříd, funkcí a konstant.

  • class-reference-name-casing: Writes the names of internal classes, interfaces and enums in their declared case.
  • import-notation: Writes the imports of each kind one per use statement or all in one, and expands group use declarations.
  • name-fallback: Writes a global function or constant in a namespace qualified, or bare and reached by the fallback at run time. (rizikové opravy)
  • name-notation: Writes a referenced name imported or with the leading backslash.
  • 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.
  • no-unlisted-namespaced-declaration: Reports a function or a constant declared in a namespace that the configuration does not list. (jen hlásí)
  • ordered-imports: Sorts use statements alphabetically, classes before functions before constants.
  • 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-constant-fetch-for-constant-call: Fetches a class constant by its name instead of asking constant() for it. (PHP 8.3+)
  • class-definition-spacing: Puts single spaces in the head of a class declaration.
  • class-name-reference-for-string-literal: Writes a class name held in a string as ::class. (rizikové opravy)
  • final-internal-class: Makes classes annotated as internal final. (rizikové opravy)
  • kind-in-class-name: Decides whether the name of a class, interface or trait repeats its kind. (jen hlásí)
  • modern-class-name-reference: Uses ::class instead of get_class() and __CLASS__. (rizikové opravy)
  • name-casing: Reports declared names that do not follow the case convention configured for their kind. (jen hlásí)
  • no-deprecated-classes: Writes the class a deprecated class was replaced by.
  • no-deprecated-members: Replaces deprecated constants, methods and properties with the member their deprecation names, and reports the rest.
  • no-null-debug-info-return: Returns an empty array from __debugInfo() where it returns null.
  • no-sleep-and-wakeup: Reports the __sleep() and __wakeup() methods PHP 8.5 deprecated.
  • 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.
  • override-attribute-required: Marks a method overriding an inherited one with #\Override. (PHP 8.3+)
  • promoted-property-for-assigned-parameter: Promotes a constructor parameter that is only assigned to a property. (rizikové opravy, PHP 8.0+)
  • readonly-class-for-readonly-members: Marks a class whose every property is readonly as readonly. (PHP 8.2+)
  • readonly-for-annotation: Replaces the @readonly annotation with the readonly keyword. (rizikové opravy, PHP 8.1+)
  • readonly-for-unwritten-property: Marks a property written only in the constructor as readonly. (rizikové opravy, PHP 8.1+)
  • replaced-classes: Writes the class the project writes instead of another one.
  • self-for-current-class: Replaces the name of the current class with self. (rizikové opravy)
  • 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.
  • static-for-private-method-without-this: Marks a private method that does not use $this as static. (rizikové opravy)
  • static-set-state-required: Declares __set_state() static, which is how PHP calls it.
  • stringable-required: Declares a class with a __toString() method as Stringable. (PHP 8.0+)
  • useless-modifier: Removes a member modifier the class already implies.
  • useless-null-property-initialization: Removes the explicit null initialization of untyped properties.
  • useless-overriding-method: Removes a method that only calls the parent method with the same arguments. (rizikové opravy)
  • visibility-required: Requires visibility on class members and orders their modifiers.

Funkce

Deklarace i volání funkcí a metod, parametry a argumenty.

  • array-first-for-edge-element: Reads the first or the last element of an array with array_first() and array_last(). (rizikové opravy, PHP 8.5+)
  • arrow-function: Replaces a closure returning a single expression with an arrow function.
  • clamp-for-min-max: Replaces a max() around a min() holding a value between bounds with clamp(). (rizikové opravy, PHP 8.6+)
  • csv-escape-argument-required: Writes out the escape argument of the CSV functions, whose default PHP 8.4 deprecated.
  • first-class-callable-notation: Writes a callable in the first-class callable notation. (rizikové opravy, PHP 8.1+)
  • forbidden-functions: Reports calls of the configured functions. (jen hlásí)
  • function-name-spacing: Removes whitespace between a function name and its parentheses.
  • get-debug-type-for-type-ternary: Replaces a ternary asking whether a value is an object with get_debug_type(). (rizikové opravy, PHP 8.0+)
  • json-validate-for-decode-test: Replaces json_decode() called only to test the input with json_validate(). (rizikové opravy, PHP 8.3+)
  • mb-convert-encoding-for-utf8-function: Replaces the deprecated utf8_encode() and utf8_decode() with mb_convert_encoding(). (rizikové opravy)
  • 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. (rizikové opravy)
  • no-call-user-func: Calls a callable directly instead of through call_user_func(). (rizikové opravy, PHP 7.0+)
  • no-conversion-functions: Uses a cast instead of intval() and friends. (rizikové opravy)
  • no-deprecated-arguments: Removes the arguments the targeted version of PHP deprecated because nothing reads them.
  • no-deprecated-functions: Reports calls of internal functions deprecated in the targeted version of PHP. (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. (rizikové opravy)
  • no-inner-functions: Reports a function declared inside another function. (jen hlásí)
  • no-is-null: Replaces is_null() with a comparison with null. (rizikové opravy)
  • no-manual-empty-string-test: Tests whether a string is empty by comparing it with the empty string.
  • no-manual-substring-test: Replaces a hand-written test for a substring with str_contains(), str_starts_with() or str_ends_with(). (rizikové opravy, PHP 8.0+)
  • no-settype: Assigns a cast instead of calling settype(). (rizikové opravy)
  • optimized-call-notation: Writes the arguments of a call PHP optimizes positionally and reports unpacking in it. (rizikové opravy)
  • replaced-functions: Calls the function the project writes instead of another one. (rizikové opravy)
  • rounding-mode-notation: Writes the rounding mode of round() as a case of the RoundingMode enum. (PHP 8.4+)
  • sensitive-parameter-required: Marks the parameters the configuration names with #\SensitiveParameter. (PHP 8.2+)
  • static-closure: Declares a closure that does not use $this as static. (rizikové opravy)
  • strict-call: Calls in_array(), array_search(), array_keys(), base64_decode() and mb_detect_encoding() with $strict = true. (rizikové opravy)
  • useless-no-op-call: Removes calls of the functions that have freed nothing since PHP 8.0. (PHP 8.0+)
  • useless-parameter-default: Removes a default value that a required parameter makes unreachable.
  • useless-set-accessible: Removes setAccessible() calls, which do nothing since PHP 8.1. (PHP 8.1+)

Řízení toku

Řídicí struktury, příkazy, bloky a výjimky.

  • array-function-for-foreach: Replaces a foreach that only searches or tests its items with array_any(), array_all(), array_find() or array_find_key(). (PHP 8.4+)
  • 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.
  • match-for-simple-switch: Writes a switch whose every case assigns or returns one value as a match. (rizikové opravy, PHP 8.0+)
  • multi-line-condition: Writes a condition of if, elseif, while and do-while in the shape the configuration asks for.
  • 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. (PHP 8.0+)
  • 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 mezera; jestli smí zůstat i zarovnání do sloupců, říká volba.
  • 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. (rizikové opravy)
  • 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. (rizikové opravy)
  • 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.
  • not-equals-operator: Writes != instead of <>.
  • null-coalescing-operator: Replaces a ternary testing for null with the null coalescing operator. (rizikové opravy)
  • nullsafe-operator: Replaces a ternary guarding a member access against null with the nullsafe operator. (PHP 8.0+)
  • object-operator-spacing: Removes whitespace around the object operator.
  • offset-bracket-spacing: Removes whitespace around the brackets of an offset access.
  • pipe-operator: Writes nested calls passing one result into the next with the pipe operator. (PHP 8.5+)
  • 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. (rizikové opravy)
  • 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-attribute-parentheses: Removes the empty parentheses after the name of an attribute.
  • 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.
  • yoda: Decides which side of a comparison the constant stands on.

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. (rizikové opravy)
  • 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+)
  • string-quotes: Decides which quotes a string that needs neither kind is written with.
  • 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: Spreads a multi-line or too wide array over lines, an item on each or several filling a line, the opening bracket on the line before.
  • no-manual-list-test: Replaces a hand-written test for a list with array_is_list(). (rizikové opravy, PHP 8.1+)
  • no-null-array-key: Writes a null array key as the empty string it becomes.
  • short-array-syntax: Writes arrays and destructuring with the short syntax.
  • 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.

  • never-for-throwing-function: Declares a function that always throws or exits as returning never. (PHP 8.1+)
  • 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. (rizikové opravy)
  • 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.
  • deprecated-attribute-for-annotation: Replaces the @deprecated annotation with the #\Deprecated attribute. (rizikové opravy, PHP 8.4+)
  • explicit-assertion: Replaces an inline @var annotation with an assert() of the type. (rizikové opravy)
  • forbidden-annotations: Removes the configured annotations from doc comments.
  • forbidden-phpdoc-lines: Removes description lines matching the configured patterns from doc comments.
  • no-consecutive-phpdoc: Reports a doc comment followed by another one. (jen hlásí)
  • 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.
  • promoted-property-annotation-position: Moves the @param annotation of a promoted property to a doc comment at the property.
  • 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. (rizikové opravy)
  • 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í)

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.
  • blank-lines Prázdné řádky tam, kde je standard chce: v hlavičce souboru kolem declare, namespace a importů, ve třídě mezi metodami a členy, za otevírací a před zavírací závorkou bloku a kolem příkazů jako return.
  • 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, zavírací závorka má řádek pro sebe a else, catch či finally stojí na jejím řádku.
  • comma-spacing: Puts a single space after a comma and none before it.
  • construct-spacing: Puts a single space around language constructs.
  • 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í)