Skip to content

Latest commit

 

History

History
869 lines (563 loc) · 39 KB

index.rst

File metadata and controls

869 lines (563 loc) · 39 KB

List of Available Rules

Alias

Array Notation

Basic

  • braces

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

  • curly_braces_position

    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

    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)

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

  • octal_notation

    Literal octal must be in 0o notation.

  • psr_autoloading (risky)

    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.

Casing

Cast Notation

  • cast_spaces

    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 Usage

Comment

Constant Notation

  • native_constant_invocation (risky)

    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

Doctrine Annotation

Function Notation

  • combine_nested_dirname (risky)

    Replace multiple nested calls of dirname by only one call with second $level parameter. Requires PHP >= 7.0.

  • 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)

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

  • function_declaration

    Spaces should be properly placed in a function declaration.

  • function_typehint_space

    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

    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.

  • native_function_invocation (risky)

    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_sprintf (risky)

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

  • nullable_type_declaration_for_default_null_value

    Adds or removes ? before type declarations for parameters with a default null value.

  • phpdoc_to_param_type (risky)

    EXPERIMENTAL: Takes @param annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.

  • phpdoc_to_property_type (risky)

    EXPERIMENTAL: Takes @var annotation of non-mixed types and adjusts accordingly the property signature. Requires PHP >= 7.4.

  • phpdoc_to_return_type (risky)

    EXPERIMENTAL: Takes @return annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.

  • regular_callable_call (risky)

    Callables must be called without using call_user_func* when possible.

  • return_type_declaration

    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 (indirect) referencing $this must be declared static.

  • use_arrow_functions (risky)

    Anonymous functions with one-liner return 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. Requires PHP >= 7.1.

Import

Language Construct

List Notation

  • list_syntax

    List (array destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.

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

    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_construct (risky)

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

  • php_unit_dedicate_assert (risky)

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

  • php_unit_dedicate_assert_internal_type (risky)

    PHPUnit assertions like assertIsArray should be used over assertInternalType.

  • php_unit_expectation (risky)

    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

    All PHPUnit test classes should be marked as internal.

  • php_unit_method_casing

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

  • php_unit_mock (risky)

    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)

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

  • php_unit_no_expectation_annotation (risky)

    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

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

  • php_unit_strict (risky)

    PHPUnit methods like assertSame should be used instead of assertEquals.

  • php_unit_test_annotation (risky)

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

  • php_unit_test_case_static_method_calls (risky)

    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

Whitespace