|
@@ -6,7 +6,7 @@ whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2,
|
|
|
or other community driven ones like the Symfony one.
|
|
|
You can **also** define your (teams) style through configuration.
|
|
|
|
|
|
-It can modernize your code (like converting the `pow` function to the `**` operator on PHP 5.6)
|
|
|
+It can modernize your code (like converting the ``pow`` function to the ``**`` operator on PHP 5.6)
|
|
|
and (micro) optimize it.
|
|
|
|
|
|
If you are already using a linter to identify coding standards problems in your
|
|
@@ -46,7 +46,7 @@ or with specified version:
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
- $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.7.4/php-cs-fixer.phar -O php-cs-fixer
|
|
|
+ $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.9.1/php-cs-fixer.phar -O php-cs-fixer
|
|
|
|
|
|
or with curl:
|
|
|
|
|
@@ -147,9 +147,13 @@ to merge paths from the config file and from the argument:
|
|
|
|
|
|
$ php php-cs-fixer.phar fix --path-mode=intersection /path/to/dir
|
|
|
|
|
|
-The ``--format`` option for the output format. Supported formats are ``txt`` (default one), ``json``, ``xml`` and ``junit``.
|
|
|
+The ``--format`` option for the output format. Supported formats are ``txt`` (default one), ``json``, ``xml``, ``checkstyle`` and ``junit``.
|
|
|
+
|
|
|
+NOTE: the output for the following formats are generated in accordance with XML schemas
|
|
|
+
|
|
|
+* ``junit`` follows the `JUnit xml schema from Jenkins </doc/junit-10.xsd>`_
|
|
|
+* ``checkstyle`` follows the common `"checkstyle" xml schema </doc/checkstyle.xsd>`_
|
|
|
|
|
|
-NOTE: When using ``junit`` format report generates in accordance with JUnit xml schema from Jenkins (see docs/junit-10.xsd).
|
|
|
|
|
|
The ``--verbose`` option will show the applied rules. When using the ``txt`` format it will also displays progress notifications.
|
|
|
|
|
@@ -188,13 +192,19 @@ Complete configuration for rules can be supplied using a ``json`` formatted stri
|
|
|
|
|
|
$ php php-cs-fixer.phar fix /path/to/project --rules='{"concat_space": {"spacing": "none"}}'
|
|
|
|
|
|
-A combination of ``--dry-run`` and ``--diff`` will
|
|
|
-display a summary of proposed fixes, leaving your files unchanged.
|
|
|
+The ``--dry-run`` flag will run the fixer without making changes to your files.
|
|
|
+
|
|
|
+The ``--diff`` flag can be used to let the fixer output all the changes it makes.
|
|
|
+
|
|
|
+The ``--diff-format`` option allows to specify in which format the fixer should output the changes it makes:
|
|
|
+
|
|
|
+* ``udiff``: unified diff format;
|
|
|
+* ``sbd``: Sebastianbergmann/diff format (default when using `--diff` without specifying `diff-format`).
|
|
|
|
|
|
The ``--allow-risky`` option (pass ``yes`` or ``no``) allows you to set whether risky rules may run. Default value is taken from config file.
|
|
|
Risky rule is a rule, which could change code behaviour. By default no risky rules are run.
|
|
|
|
|
|
-The ``--stop-on-violation`` flag stops execution upon first file that needs to be fixed.
|
|
|
+The ``--stop-on-violation`` flag stops the execution upon first file that needs to be fixed.
|
|
|
|
|
|
The ``--show-progress`` option allows you to choose the way process progress is rendered:
|
|
|
|
|
@@ -216,6 +226,13 @@ automatically fix anything:
|
|
|
|
|
|
$ cat foo.php | php php-cs-fixer.phar fix --diff -
|
|
|
|
|
|
+Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
|
|
|
+would be default in next MAJOR release (unified differ, estimating, full-width progress indicator):
|
|
|
+
|
|
|
+.. code-block:: bash
|
|
|
+
|
|
|
+ $ PHP_CS_FIXER_FUTURE_MODE=1 php php-cs-fixer.phar fix -v --diff
|
|
|
+
|
|
|
Choose from the list of available rules:
|
|
|
|
|
|
* **align_multiline_comment**
|
|
@@ -307,6 +324,16 @@ Choose from the list of available rules:
|
|
|
- ``space`` (``'none'``, ``'single'``): spacing to apply between cast and variable;
|
|
|
defaults to ``'single'``
|
|
|
|
|
|
+* **class_attributes_separation** [@Symfony]
|
|
|
+
|
|
|
+ Class, trait and interface elements must be separated with one blank
|
|
|
+ line.
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``elements`` (``array``): list of classy elements; 'const', 'method',
|
|
|
+ 'property'; defaults to ``['const', 'method', 'property']``
|
|
|
+
|
|
|
* **class_definition** [@PSR2, @Symfony]
|
|
|
|
|
|
Whitespace around the keywords of a class, trait or interfaces
|
|
@@ -327,12 +354,16 @@ Choose from the list of available rules:
|
|
|
|
|
|
* **combine_consecutive_issets**
|
|
|
|
|
|
- Using ``isset(X) &&`` multiple times should be done in one call.
|
|
|
+ Using ``isset($var) &&`` multiple times should be done in one call.
|
|
|
|
|
|
* **combine_consecutive_unsets**
|
|
|
|
|
|
Calling ``unset`` on multiple items should be done in one call.
|
|
|
|
|
|
+* **compact_nullable_typehint**
|
|
|
+
|
|
|
+ Remove extra spaces in a nullable typehint.
|
|
|
+
|
|
|
* **concat_space** [@Symfony]
|
|
|
|
|
|
Concatenation should be spaced according configuration.
|
|
@@ -363,7 +394,7 @@ Choose from the list of available rules:
|
|
|
Replaces ``dirname(__FILE__)`` expression with equivalent ``__DIR__``
|
|
|
constant.
|
|
|
|
|
|
- *Risky rule: risky when the function ``dirname()`` is overridden.*
|
|
|
+ *Risky rule: risky when the function ``dirname`` is overridden.*
|
|
|
|
|
|
* **doctrine_annotation_array_assignment** [@DoctrineAnnotation]
|
|
|
|
|
@@ -517,6 +548,45 @@ Choose from the list of available rules:
|
|
|
|
|
|
*Risky rule: risky if the ``ereg`` function is overridden.*
|
|
|
|
|
|
+* **escape_implicit_backslashes**
|
|
|
+
|
|
|
+ Escape implicit backslashes in strings and heredocs to ease the
|
|
|
+ understanding of which are special chars interpreted by PHP and which
|
|
|
+ not.
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``double_quoted`` (``bool``): whether to fix double-quoted strings; defaults to
|
|
|
+ ``true``
|
|
|
+ - ``heredoc_syntax`` (``bool``): whether to fix heredoc syntax; defaults to ``true``
|
|
|
+ - ``single_quoted`` (``bool``): whether to fix single-quoted strings; defaults to
|
|
|
+ ``false``
|
|
|
+
|
|
|
+* **explicit_indirect_variable**
|
|
|
+
|
|
|
+ Add curly braces to indirect variables to make them clear to understand.
|
|
|
+ Requires PHP >= 7.0.
|
|
|
+
|
|
|
+* **explicit_string_variable**
|
|
|
+
|
|
|
+ Converts implicit variables into explicit ones in double-quoted strings
|
|
|
+ or heredoc syntax.
|
|
|
+
|
|
|
+* **final_internal_class**
|
|
|
+
|
|
|
+ Internal classes should be ``final``.
|
|
|
+
|
|
|
+ *Risky rule: changing classes to ``final`` might cause code execution to break.*
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``annotation-black-list`` (``array``): class level annotations tags that must be
|
|
|
+ omitted to fix the class, even if all of the white list ones are used
|
|
|
+ as well. (case insensitive); defaults to ``['@final', '@Entity', '@ORM']``
|
|
|
+ - ``annotation-white-list`` (``array``): class level annotations tags that must be
|
|
|
+ set in order to fix the class. (case insensitive); defaults to
|
|
|
+ ``['@internal']``
|
|
|
+
|
|
|
* **full_opening_tag** [@PSR1, @PSR2, @Symfony]
|
|
|
|
|
|
PHP code must use the long ``<?php`` tags or short-echo ``<?=`` tags and not
|
|
@@ -555,7 +625,7 @@ Choose from the list of available rules:
|
|
|
- ``annotations`` (``array``): list of annotations to remove, e.g. ``["author"]``;
|
|
|
defaults to ``[]``
|
|
|
|
|
|
-* **hash_to_slash_comment** [@Symfony]
|
|
|
+* **hash_to_slash_comment**
|
|
|
|
|
|
Single line comments should use double slashes ``//`` and not hash ``#``.
|
|
|
DEPRECATED: use ``single_line_comment_style`` instead.
|
|
@@ -583,15 +653,25 @@ Choose from the list of available rules:
|
|
|
Include/Require and file path should be divided with a single space.
|
|
|
File path should not be placed under brackets.
|
|
|
|
|
|
+* **increment_style** [@Symfony]
|
|
|
+
|
|
|
+ Pre- or post-increment and decrement operators should be used if
|
|
|
+ possible.
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``style`` (``'post'``, ``'pre'``): whether to use pre- or post-increment and
|
|
|
+ decrement operators; defaults to ``'pre'``
|
|
|
+
|
|
|
* **indentation_type** [@PSR2, @Symfony]
|
|
|
|
|
|
Code MUST use configured indentation type.
|
|
|
|
|
|
* **is_null** [@Symfony:risky]
|
|
|
|
|
|
- Replaces is_null(parameter) expression with ``null === parameter``.
|
|
|
+ Replaces ``is_null($var)`` expression with ``null === $var``.
|
|
|
|
|
|
- *Risky rule: risky when the function ``is_null()`` is overridden.*
|
|
|
+ *Risky rule: risky when the function ``is_null`` is overridden.*
|
|
|
|
|
|
Configuration options:
|
|
|
|
|
@@ -653,9 +733,15 @@ Choose from the list of available rules:
|
|
|
- ``keep_multiple_spaces_after_comma`` (``bool``): whether keep multiple spaces
|
|
|
after comma; defaults to ``false``
|
|
|
|
|
|
-* **method_separation** [@Symfony]
|
|
|
+* **method_chaining_indentation**
|
|
|
+
|
|
|
+ Method chaining MUST be properly indented. Method chaining with
|
|
|
+ different levels of indentation is not supported.
|
|
|
|
|
|
- Methods must be separated with one blank line.
|
|
|
+* **method_separation**
|
|
|
+
|
|
|
+ Methods must be separated with one blank line. DEPRECATED: use
|
|
|
+ ``class_attributes_separation`` instead.
|
|
|
|
|
|
* **modernize_types_casting** [@Symfony:risky]
|
|
|
|
|
@@ -939,7 +1025,7 @@ Choose from the list of available rules:
|
|
|
- ``assertions`` (``array``): list of assertion methods to fix; defaults to
|
|
|
``['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']``
|
|
|
|
|
|
-* **php_unit_dedicate_assert** [@Symfony:risky]
|
|
|
+* **php_unit_dedicate_assert** [@Symfony:risky, @PHPUnit30Migration:risky, @PHPUnit32Migration:risky, @PHPUnit35Migration:risky, @PHPUnit43Migration:risky, @PHPUnit48Migration:risky, @PHPUnit50Migration:risky, @PHPUnit52Migration:risky, @PHPUnit54Migration:risky, @PHPUnit56Migration:risky, @PHPUnit57Migration:risky, @PHPUnit60Migration:risky]
|
|
|
|
|
|
PHPUnit assertions like "assertInternalType", "assertFileExists", should
|
|
|
be used over "assertTrue".
|
|
@@ -948,16 +1034,60 @@ Choose from the list of available rules:
|
|
|
|
|
|
Configuration options:
|
|
|
|
|
|
- - ``functions`` (``array``): list of assertions to fix; defaults to
|
|
|
- ``['array_key_exists', 'empty', 'file_exists', 'is_array', 'is_bool',
|
|
|
- 'is_boolean', 'is_callable', 'is_double', 'is_float', 'is_infinite',
|
|
|
- 'is_int', 'is_integer', 'is_long', 'is_nan', 'is_null', 'is_numeric',
|
|
|
- 'is_object', 'is_real', 'is_resource', 'is_scalar', 'is_string']``
|
|
|
+ - ``functions`` (``null``): (deprecated, use ``target`` instead) List of assertions
|
|
|
+ to fix (overrides ``target``); defaults to ``null``
|
|
|
+ - ``target`` (``'3.0'``, ``'3.5'``, ``'5.0'``, ``'5.6'``, ``'newest'``): target version of
|
|
|
+ PHPUnit; defaults to ``'5.0'``
|
|
|
+
|
|
|
+* **php_unit_expectation** [@PHPUnit52Migration:risky, @PHPUnit54Migration:risky, @PHPUnit56Migration:risky, @PHPUnit57Migration:risky, @PHPUnit60Migration:risky]
|
|
|
+
|
|
|
+ Usages of ``->setExpectedException*`` methods MUST be replaced by
|
|
|
+ ``->expectException*`` methods.
|
|
|
+
|
|
|
+ *Risky rule: risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.*
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``target`` (``'5.2'``, ``'5.6'``, ``'newest'``): target version of PHPUnit; defaults to
|
|
|
+ ``'newest'``
|
|
|
|
|
|
* **php_unit_fqcn_annotation** [@Symfony]
|
|
|
|
|
|
PHPUnit annotations should be a FQCNs including a root namespace.
|
|
|
|
|
|
+* **php_unit_mock** [@PHPUnit54Migration:risky, @PHPUnit56Migration:risky, @PHPUnit57Migration:risky, @PHPUnit60Migration:risky]
|
|
|
+
|
|
|
+ Usages of ``->getMock`` and
|
|
|
+ ``->getMockWithoutInvokingTheOriginalConstructor`` methods MUST be
|
|
|
+ replaced by ``->createMock`` method.
|
|
|
+
|
|
|
+ *Risky rule: risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.*
|
|
|
+
|
|
|
+* **php_unit_namespaced** [@PHPUnit48Migration:risky, @PHPUnit50Migration:risky, @PHPUnit52Migration:risky, @PHPUnit54Migration:risky, @PHPUnit56Migration:risky, @PHPUnit57Migration:risky, @PHPUnit60Migration:risky]
|
|
|
+
|
|
|
+ PHPUnit classes MUST be used in namespaced version, eg
|
|
|
+ ``\PHPUnit\Framework\TestCase`` instead of ``\PHPUnit_Framework_TestCase``.
|
|
|
+
|
|
|
+ *Risky rule: risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.*
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``target`` (``'4.8'``, ``'5.7'``, ``'6.0'``, ``'newest'``): target version of PHPUnit;
|
|
|
+ defaults to ``'newest'``
|
|
|
+
|
|
|
+* **php_unit_no_expectation_annotation** [@PHPUnit32Migration:risky, @PHPUnit35Migration:risky, @PHPUnit43Migration:risky, @PHPUnit48Migration:risky, @PHPUnit50Migration:risky, @PHPUnit52Migration:risky, @PHPUnit54Migration:risky, @PHPUnit56Migration:risky, @PHPUnit57Migration:risky, @PHPUnit60Migration:risky]
|
|
|
+
|
|
|
+ Usages of ``@expectedException*`` annotations MUST be replaced by
|
|
|
+ ``->setExpectedException*`` methods.
|
|
|
+
|
|
|
+ *Risky rule: risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.*
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``target`` (``'3.2'``, ``'4.3'``, ``'newest'``): target version of PHPUnit; defaults to
|
|
|
+ ``'newest'``
|
|
|
+ - ``use_class_const`` (``bool``): use ::class notation; defaults to ``true``
|
|
|
+
|
|
|
* **php_unit_strict**
|
|
|
|
|
|
PHPUnit methods like ``assertSame`` should be used instead of
|
|
@@ -971,6 +1101,19 @@ Choose from the list of available rules:
|
|
|
``['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals',
|
|
|
'assertNotEquals']``
|
|
|
|
|
|
+* **php_unit_test_annotation**
|
|
|
+
|
|
|
+ Adds or removes @test annotations from tests, following configuration.
|
|
|
+
|
|
|
+ *Risky rule: this fixer may change the name of your tests, and could cause incompatibility with abstract classes or interfaces.*
|
|
|
+
|
|
|
+ Configuration options:
|
|
|
+
|
|
|
+ - ``case`` (``'camel'``, ``'snake'``): whether to camel or snake case when adding the
|
|
|
+ test prefix; defaults to ``'camel'``
|
|
|
+ - ``style`` (``'annotation'``, ``'prefix'``): whether to use the @test annotation or
|
|
|
+ not; defaults to ``'prefix'``
|
|
|
+
|
|
|
* **php_unit_test_class_requires_covers**
|
|
|
|
|
|
Adds a default ``@coversNothing`` annotation to PHPUnit test classes that
|
|
@@ -1101,13 +1244,14 @@ Choose from the list of available rules:
|
|
|
|
|
|
* **pow_to_exponentiation** [@PHP56Migration:risky, @PHP70Migration:risky, @PHP71Migration:risky]
|
|
|
|
|
|
- Converts ``pow()`` to the ``**`` operator.
|
|
|
+ Converts ``pow`` to the ``**`` operator.
|
|
|
|
|
|
- *Risky rule: risky when the function ``pow()`` is overridden.*
|
|
|
+ *Risky rule: risky when the function ``pow`` is overridden.*
|
|
|
|
|
|
-* **pre_increment** [@Symfony]
|
|
|
+* **pre_increment**
|
|
|
|
|
|
Pre incrementation/decrementation should be used if possible.
|
|
|
+ DEPRECATED: use ``increment_style`` instead.
|
|
|
|
|
|
* **protected_to_private** [@Symfony]
|
|
|
|
|
@@ -1156,8 +1300,8 @@ Choose from the list of available rules:
|
|
|
|
|
|
* **self_accessor** [@Symfony]
|
|
|
|
|
|
- Inside a classy element "self" should be preferred to the class name
|
|
|
- itself.
|
|
|
+ Inside class or interface element "self" should be preferred to the
|
|
|
+ class name itself.
|
|
|
|
|
|
* **semicolon_after_instruction** [@Symfony]
|
|
|
|
|
@@ -1178,8 +1322,6 @@ Choose from the list of available rules:
|
|
|
|
|
|
A return statement wishing to return ``void`` should not return ``null``.
|
|
|
|
|
|
- *Risky rule: risky since PHP 7.1 as ``null`` and ``void`` can be hinted as return type and have different meaning.*
|
|
|
-
|
|
|
* **single_blank_line_at_eof** [@PSR2, @Symfony]
|
|
|
|
|
|
A PHP file without end tag must always end with a single empty line
|
|
@@ -1208,7 +1350,7 @@ Choose from the list of available rules:
|
|
|
Each namespace use MUST go on its own line and there MUST be one blank
|
|
|
line after the use statements block.
|
|
|
|
|
|
-* **single_line_comment_style**
|
|
|
+* **single_line_comment_style** [@Symfony]
|
|
|
|
|
|
Single-line comments and multi-line comments with only one line of
|
|
|
actual content should use the ``//`` syntax.
|
|
@@ -1235,6 +1377,12 @@ Choose from the list of available rules:
|
|
|
|
|
|
Replace all ``<>`` with ``!=``.
|
|
|
|
|
|
+* **static_lambda**
|
|
|
+
|
|
|
+ Lambdas not (indirect) referencing ``$this`` must be declared ``static``.
|
|
|
+
|
|
|
+ *Risky rule: risky when using "->bindTo" on lambdas without referencing to ``$this``.*
|
|
|
+
|
|
|
* **strict_comparison**
|
|
|
|
|
|
Comparisons should be strict.
|
|
@@ -1326,7 +1474,7 @@ Config file
|
|
|
|
|
|
Instead of using command line options to customize the rule, you can save the
|
|
|
project configuration in a ``.php_cs.dist`` file in the root directory of your project.
|
|
|
-The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.7.4/src/ConfigInterface.php>`_
|
|
|
+The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.9.1/src/ConfigInterface.php>`_
|
|
|
which lets you configure the rules, the files and directories that
|
|
|
need to be analyzed. You may also create ``.php_cs`` file, which is
|
|
|
the local configuration that will be used instead of the project configuration. It
|