-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #6047 StringLengthToEmptyFixer - introduction (SpacePossum)
This PR was squashed before being merged into the master branch. Discussion ---------- StringLengthToEmptyFixer - introduction closes #5005 ``` [11:03 AM]-[possum@aquarium]-[~/work/PHP-CS-Fixer]-[git master_StringLengthToEmptyFixer] $ php php-cs-fixer describe string_length_to_empty Description of string_length_to_empty rule. String tests for empty must be done against `''`, not with `strlen`. Fixer applying this rule is risky. Risky when `strlen` is overridden, when called using a `stringable` object, also no longer triggers warning when called using non-string(able). Fixing examples: ``` ```diff --- Original +++ New @@ -1,1 +1,1 @@ -<?php $a = 0 === strlen($b) || \STRLEN($c) < 1; +<?php $a = '' === $b || $c === ''; ``` Commits ------- c1ede31 StringLengthToEmptyFixer - introduction
- Loading branch information
Showing
24 changed files
with
743 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=============================== | ||
Rule ``string_length_to_empty`` | ||
=============================== | ||
|
||
String tests for empty must be done against ``''``, not with ``strlen``. | ||
|
||
.. warning:: Using this rule is risky. | ||
|
||
Risky when ``strlen`` is overridden, when called using a ``stringable`` | ||
object, also no longer triggers warning when called using non-string(able). | ||
|
||
Examples | ||
-------- | ||
|
||
Example #1 | ||
~~~~~~~~~~ | ||
|
||
.. code-block:: diff | ||
--- Original | ||
+++ New | ||
-<?php $a = 0 === strlen($b) || \STRLEN($c) < 1; | ||
+<?php $a = '' === $b || $c === ''; | ||
Rule sets | ||
--------- | ||
|
||
The rule is part of the following rule sets: | ||
|
||
@PhpCsFixer:risky | ||
Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``string_length_to_empty`` rule. | ||
|
||
@Symfony:risky | ||
Using the `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_ rule set will enable the ``string_length_to_empty`` rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.