Fork me on GitHub
a Sensio Labs Product

Folding Bike (v3.91.3) edition

List of Available Rules

Alias

Array Notation

Attribute Notation

Basic

  • braces (deprecated, configurable)

    The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.

  • braces_position (configurable)

    Braces must be placed as configured.

  • curly_braces_position (deprecated, configurable)

    Curly braces must be placed as configured.

  • encoding

    PHP code MUST use only UTF-8 without BOM (remove BOM).

  • no_multiple_statements_per_line

    There must not be more than one statement per line.

  • no_trailing_comma_in_singleline (configurable)

    If a list of values separated by a comma is contained on a single line, then the last item MUST NOT have a trailing comma.

  • non_printable_character (risky, configurable)

    Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols.

  • numeric_literal_separator (configurable)

    Adds separators to numeric literals of any kind.

  • octal_notation

    Literal octal must be in 0o notation.

  • psr_autoloading (risky, configurable)

    Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.

  • single_line_empty_body

    Empty body of class, interface, trait, enum or function must be abbreviated as {} and placed on the same line as the previous symbol, separated by a single space.

Casing

Cast Notation

  • cast_spaces (configurable)

    A single space or none should be between cast and variable.

  • lowercase_cast

    Cast should be written in lower case.

  • modernize_types_casting (risky)

    Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator.

  • no_short_bool_cast

    Short cast bool using double exclamation mark should not be used.

  • no_unset_cast

    Variables must be set null instead of using (unset) casting.

  • short_scalar_cast

    Cast (boolean) and (integer) should be written as (bool) and (int), (double) and (real) as (float), (binary) as (string).

Class Notation

  • class_attributes_separation (configurable)

    Class, trait and interface elements must be separated with one or none blank line.

  • class_definition (configurable)

    Whitespace around the keywords of a class, trait, enum or interfaces definition should be one space.

  • final_class (risky)

    All classes must be final, except abstract ones and Doctrine entities.

  • final_internal_class (risky, configurable)

    Internal classes should be final.

  • final_public_method_for_abstract_class (risky)

    All public methods of abstract classes should be final.

  • modifier_keywords (configurable)

    Classes, constants, properties, and methods MUST have visibility declared, and keyword modifiers MUST be in the following order: inheritance modifier (abstract or final), visibility modifier (public, protected, or private), set-visibility modifier (public(set), protected(set), or private(set)), scope modifier (static), mutation modifier (readonly), type declaration, name.

  • no_blank_lines_after_class_opening

    There should be no empty lines after class opening brace.

  • no_null_property_initialization

    Properties MUST not be explicitly initialised with null except when they have a type declaration (PHP 7.4).

  • no_php4_constructor (risky)

    Convert PHP4-style constructors to __construct.

  • no_unneeded_final_method (risky, configurable)

    Removes final from methods where possible.

  • ordered_class_elements (configurable)

    Orders the elements of classes/interfaces/traits/enums.

  • ordered_interfaces (configurable)

    Orders the interfaces in an implements or interface extends clause.

  • ordered_traits (risky, configurable)

    Trait use statements must be sorted alphabetically.

  • ordered_types (configurable)

    Sort union types and intersection types using configured order.

  • phpdoc_readonly_class_comment_to_keyword (risky)

    Converts readonly comment on classes to the readonly keyword.

  • protected_to_private

    Converts protected variables and methods to private where possible.

  • self_accessor (risky)

    Inside class or interface element self should be preferred to the class name itself.

  • self_static_accessor

    Inside an enum or final/anonymous class, self should be preferred over static.

  • single_class_element_per_statement (configurable)

    There MUST NOT be more than one property or constant declared per statement.

  • single_trait_insert_per_statement

    Each trait use must be done as single statement.

  • static_private_method (risky)

    Converts private methods to static where possible.

  • stringable_for_to_string

    A class that implements the __toString() method must explicitly implement the Stringable interface.

  • visibility_required (deprecated, configurable)

    Classes, constants, properties, and methods MUST have visibility declared, and keyword modifiers MUST be in the following order: inheritance modifier (abstract or final), visibility modifier (public, protected, or private), set-visibility modifier (public(set), protected(set), or private(set)), scope modifier (static), mutation modifier (readonly), type declaration, name.

Class Usage

Comment

Constant Notation

  • native_constant_invocation (risky, configurable)

    Add leading \ before constant invocation of internal constant to speed up resolving. Constant name match is case-sensitive, except for null, false and true.

Control Structure

  • control_structure_braces

    The body of each control structure MUST be enclosed within braces.

  • control_structure_continuation_position (configurable)

    Control structure continuation keyword must be on the configured line.

  • elseif

    The keyword elseif should be used instead of else if so that all control keywords look like single words.

  • empty_loop_body (configurable)

    Empty loop-body must be in configured style.

  • empty_loop_condition (configurable)

    Empty loop-condition must be in configured style.

  • include

    Include/Require and file path should be divided with a single space. File path should not be placed within parentheses.

  • no_alternative_syntax (configurable)

    Replace control structure alternative syntax to use braces.

  • no_break_comment (configurable)

    There must be a comment when fall-through is intentional in a non-empty case body.

  • no_superfluous_elseif

    Replaces superfluous elseif with if.

  • no_trailing_comma_in_list_call (deprecated)

    Remove trailing commas in list function calls.

  • no_unneeded_braces (configurable)

    Removes unneeded braces that are superfluous and aren’t part of a control structure’s body.

  • no_unneeded_control_parentheses (configurable)

    Removes unneeded parentheses around control statements.

  • no_unneeded_curly_braces (deprecated, configurable)

    Removes unneeded curly braces that are superfluous and aren’t part of a control structure’s body.

  • no_useless_else

    There should not be useless else cases.

  • simplified_if_return

    Simplify if control structures that return the boolean result of their condition.

  • switch_case_semicolon_to_colon

    A case should be followed by a colon and not a semicolon.

  • switch_case_space

    Removes extra spaces between colon and case value.

  • switch_continue_to_break

    Switch case must not be ended with continue but with break.

  • trailing_comma_in_multiline (configurable)

    Arguments lists, array destructuring lists, arrays that are multi-line, match-lines and parameters lists must have a trailing comma.

  • yoda_style (configurable)

    Write conditions in Yoda style (true), non-Yoda style (['equal' => false, 'identical' => false, 'less_and_greater' => false]) or ignore those conditions (null) based on configuration.

Doctrine Annotation

Function Notation

  • combine_nested_dirname (risky)

    Replace multiple nested calls of dirname by only one call with second $level parameter.

  • date_time_create_from_format_call (risky)

    The first argument of DateTime::createFromFormat method must start with !.

  • fopen_flag_order (risky)

    Order the flags in fopen calls, b and t must be last.

  • fopen_flags (risky, configurable)

    The flags in fopen calls must omit t, and b must be omitted or included consistently.

  • function_declaration (configurable)

    Spaces should be properly placed in a function declaration.

  • function_typehint_space (deprecated)

    Ensure single space between function’s argument and its typehint.

  • implode_call (risky)

    Function implode must be called with 2 arguments in the documented order.

  • lambda_not_used_import

    Lambda must not import variables it doesn’t use.

  • method_argument_space (configurable)

    In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.

  • multiline_promoted_properties (experimental, configurable)

    Promoted properties must be on separate lines.

  • native_function_invocation (risky, configurable)

    Add leading \ before function invocation to speed up resolving.

  • no_spaces_after_function_name

    When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.

  • no_trailing_comma_in_singleline_function_call (deprecated)

    When making a method or function call on a single line there MUST NOT be a trailing comma after the last argument.

  • no_unreachable_default_argument_value (risky)

    In function arguments there must not be arguments with default values before non-default ones.

  • no_useless_printf (risky)

    There must be no printf calls with only the first argument.

  • no_useless_sprintf (risky)

    There must be no sprintf calls with only the first argument.

  • nullable_type_declaration_for_default_null_value (configurable)

    Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value.

  • phpdoc_to_param_type (experimental, risky, configurable)

    Takes @param annotations of non-mixed types and adjusts accordingly the function signature.

  • phpdoc_to_property_type (experimental, risky, configurable)

    Takes @var annotation of non-mixed types and adjusts accordingly the property signature..

  • phpdoc_to_return_type (experimental, risky, configurable)

    Takes @return annotation of non-mixed types and adjusts accordingly the function signature.

  • regular_callable_call (risky)

    Callables must be called without using call_user_func* when possible.

  • return_type_declaration (configurable)

    Adjust spacing around colon in return type declarations and backed enum types.

  • single_line_throw

    Throwing exception must be done in single line.

  • static_lambda (risky)

    Lambdas not (indirectly) referencing $this must be declared static.

  • use_arrow_functions (risky)

    Anonymous functions with return as the only statement must use arrow functions.

  • void_return (risky)

    Add void return type to functions with missing or empty return statements, but priority is given to @return annotations.

Import

Language Construct

List Notation

  • list_syntax (configurable)

    List (array destructuring) assignment should be declared using the configured syntax.

Namespace Notation

Naming

  • no_homoglyph_names (risky)

    Replace accidental usage of homoglyphs (non ascii characters) in names.

Operator

PHP Tag

  • blank_line_after_opening_tag

    Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.

  • echo_tag_syntax (configurable)

    Replaces short-echo <?= with long format <?php echo/<?php print syntax, or vice-versa.

  • full_opening_tag

    PHP code must use the long <?php tags or short-echo <?= tags and not other tag variations.

  • linebreak_after_opening_tag

    Ensure there is no code on the same line as the PHP open tag.

  • no_closing_tag

    The closing ?> tag MUST be omitted from files containing only PHP.

PHPUnit

  • php_unit_assert_new_names (risky)

    Rename deprecated PHPUnit assertions like assertFileNotExists to new methods like assertFileDoesNotExist.

  • php_unit_attributes (configurable)

    PHPUnit attributes must be used over their respective PHPDoc-based annotations.

  • php_unit_construct (risky, configurable)

    PHPUnit assertion method calls like ->assertSame(true, $foo) should be written with dedicated method like ->assertTrue($foo).

  • php_unit_data_provider_method_order (configurable)

    Data provider method must be placed after/before the last/first test where used.

  • php_unit_data_provider_name (risky, configurable)

    Data provider names must match the name of the test.

  • php_unit_data_provider_return_type (risky)

    The return type of PHPUnit data provider must be iterable.

  • php_unit_data_provider_static (risky, configurable)

    Data providers must be static.

  • php_unit_dedicate_assert (risky, configurable)

    PHPUnit assertions like assertInternalType, assertFileExists, should be used over assertTrue.

  • php_unit_dedicate_assert_internal_type (risky, configurable)

    PHPUnit assertions like assertIsArray should be used over assertInternalType.

  • php_unit_expectation (risky, configurable)

    Usages of ->setExpectedException* methods MUST be replaced by ->expectException* methods.

  • php_unit_fqcn_annotation

    PHPUnit annotations should be a FQCNs including a root namespace.

  • php_unit_internal_class (configurable)

    All PHPUnit test classes should be marked as internal.

  • php_unit_method_casing (configurable)

    Enforce camel (or snake) case for PHPUnit test methods, following configuration.

  • php_unit_mock (risky, configurable)

    Usages of ->getMock and ->getMockWithoutInvokingTheOriginalConstructor methods MUST be replaced by ->createMock or ->createPartialMock methods.

  • php_unit_mock_short_will_return (risky)

    Usage of PHPUnit’s mock e.g. ->will($this->returnValue(..)) must be replaced by its shorter equivalent such as ->willReturn(...).

  • php_unit_namespaced (risky, configurable)

    PHPUnit classes MUST be used in namespaced version, e.g. \PHPUnit\Framework\TestCase instead of \PHPUnit_Framework_TestCase.

  • php_unit_no_expectation_annotation (risky, configurable)

    Usages of @expectedException* annotations MUST be replaced by ->setExpectedException* methods.

  • php_unit_set_up_tear_down_visibility (risky)

    Changes the visibility of the setUp() and tearDown() functions of PHPUnit to protected, to match the PHPUnit TestCase.

  • php_unit_size_class (configurable)

    All PHPUnit test cases should have @small, @medium or @large annotation to enable run time limits.

  • php_unit_strict (risky, configurable)

    PHPUnit methods like assertSame should be used instead of assertEquals.

  • php_unit_test_annotation (risky, configurable)

    Adds or removes @test annotations from tests, following configuration.

  • php_unit_test_case_static_method_calls (risky, configurable)

    Calls to PHPUnit\Framework\TestCase static methods must all be of the same type, either $this->, self:: or static::.

  • php_unit_test_class_requires_covers

    Adds a default @coversNothing annotation to PHPUnit test classes that have no @covers* annotation.

PHPDoc

Return Notation

  • no_useless_return

    There should not be an empty return statement at the end of a function.

  • return_assignment

    Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.

  • simplified_null_return

    A return statement wishing to return void should not return null.

Semicolon

Strict

String Notation

  • escape_implicit_backslashes (deprecated, configurable)

    Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.

  • explicit_string_variable

    Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.

  • heredoc_closing_marker (configurable)

    Unify heredoc or nowdoc closing marker.

  • heredoc_to_nowdoc

    Convert heredoc to nowdoc where possible.

  • multiline_string_to_heredoc

    Convert multiline string to heredoc or nowdoc.

  • no_binary_string

    There should not be a binary flag before strings.

  • no_trailing_whitespace_in_string (risky)

    There must be no trailing whitespace at the end of lines in strings.

  • simple_to_complex_string_variable

    Converts explicit variables in double-quoted strings and heredoc syntax from simple to complex format (${ to {$).

  • single_quote (configurable)

    Convert double quotes to single quotes for simple strings.

  • string_implicit_backslashes (configurable)

    Handles implicit backslashes in strings and heredocs. Depending on the chosen strategy, it can escape implicit backslashes to ease the understanding of which are special chars interpreted by PHP and which not (escape), or it can remove these additional backslashes if you find them superfluous (unescape). You can also leave them as-is using ignore strategy.

  • string_length_to_empty (risky)

    String tests for empty must be done against '', not with strlen.

  • string_line_ending (risky)

    All multi-line strings must use correct line ending.

Whitespace