Browse Source

Update RuleSet

SpacePossum 5 years ago
parent
commit
79d6ccde9f

+ 14 - 14
README.rst

@@ -401,7 +401,7 @@ Choose from the list of available rules:
 
   Calling ``unset`` on multiple items should be done in one call.
 
-* **combine_nested_dirname** [@Symfony:risky, @PhpCsFixer:risky, @PHP70Migration:risky, @PHP71Migration:risky]
+* **combine_nested_dirname** [@Symfony:risky, @PhpCsFixer:risky, @PHP70Migration:risky, @PHP71Migration:risky, @PHP74Migration:risky]
 
   Replace multiple nested calls of ``dirname`` by only one call with second
   ``$level`` parameter. Requires PHP >= 7.0.
@@ -458,7 +458,7 @@ Choose from the list of available rules:
   - ``space`` (``'none'``, ``'single'``): spacing to apply around the equal sign;
     defaults to ``'none'``
 
-* **declare_strict_types** [@PHP70Migration:risky, @PHP71Migration:risky]
+* **declare_strict_types** [@PHP70Migration:risky, @PHP71Migration:risky, @PHP74Migration:risky]
 
   Force strict types declaration in all files. Requires PHP >= 7.0.
 
@@ -810,7 +810,7 @@ Choose from the list of available rules:
   - ``separate`` (``'both'``, ``'bottom'``, ``'none'``, ``'top'``): whether the header should be
     separated from the file content with a new line; defaults to ``'both'``
 
-* **heredoc_indentation** [@PHP73Migration]
+* **heredoc_indentation** [@PHP73Migration, @PHP74Migration]
 
   Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
 
@@ -818,7 +818,7 @@ Choose from the list of available rules:
 
   Convert ``heredoc`` to ``nowdoc`` where possible.
 
-* **implode_call** [@Symfony:risky, @PhpCsFixer:risky]
+* **implode_call** [@Symfony:risky, @PhpCsFixer:risky, @PHP74Migration:risky]
 
   Function ``implode`` must be called with 2 arguments in the documented
   order.
@@ -1021,7 +1021,7 @@ Choose from the list of available rules:
 
   All instances created with new keyword must be followed by braces.
 
-* **no_alias_functions** [@Symfony:risky, @PhpCsFixer:risky]
+* **no_alias_functions** [@Symfony:risky, @PhpCsFixer:risky, @PHP74Migration:risky]
 
   Master functions shall be used instead of aliases.
 
@@ -1293,7 +1293,7 @@ Choose from the list of available rules:
 
   Remove trailing whitespace at the end of blank lines.
 
-* **non_printable_character** [@Symfony:risky, @PhpCsFixer:risky, @PHP70Migration:risky, @PHP71Migration:risky]
+* **non_printable_character** [@Symfony:risky, @PhpCsFixer:risky, @PHP70Migration:risky, @PHP71Migration:risky, @PHP74Migration:risky]
 
   Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other
   invisible unicode symbols.
@@ -1305,7 +1305,7 @@ Choose from the list of available rules:
   - ``use_escape_sequences_in_strings`` (``bool``): whether characters should be
     replaced with escape sequences in strings; defaults to ``false``
 
-* **normalize_index_brace** [@Symfony, @PhpCsFixer]
+* **normalize_index_brace** [@Symfony, @PhpCsFixer, @PHP74Migration]
 
   Array index should always be written by using square braces.
 
@@ -1775,7 +1775,7 @@ Choose from the list of available rules:
   ``@var`` and ``@type`` annotations of classy properties should not contain
   the name.
 
-* **pow_to_exponentiation** [@Symfony:risky, @PhpCsFixer:risky, @PHP56Migration:risky, @PHP70Migration:risky, @PHP71Migration:risky]
+* **pow_to_exponentiation** [@Symfony:risky, @PhpCsFixer:risky, @PHP56Migration:risky, @PHP70Migration:risky, @PHP71Migration:risky, @PHP74Migration:risky]
 
   Converts ``pow`` to the ``**`` operator.
 
@@ -1808,7 +1808,7 @@ Choose from the list of available rules:
 
   *Risky rule: this fixer may change your class name, which will break the code that depends on the old name.*
 
-* **random_api_migration** [@PHP70Migration:risky, @PHP71Migration:risky]
+* **random_api_migration** [@PHP70Migration:risky, @PHP71Migration:risky, @PHP74Migration:risky]
 
   Replaces ``rand``, ``srand``, ``getrandmax`` functions calls with their ``mt_*``
   analogs.
@@ -1864,7 +1864,7 @@ Choose from the list of available rules:
 
   *Risky rule: risky when the ``settype`` function is overridden or when used as the 2nd or 3rd expression in a ``for`` loop .*
 
-* **short_scalar_cast** [@Symfony, @PhpCsFixer]
+* **short_scalar_cast** [@Symfony, @PhpCsFixer, @PHP74Migration]
 
   Cast ``(boolean)`` and ``(integer)`` should be written as ``(bool)`` and
   ``(int)``, ``(double)`` and ``(real)`` as ``(float)``, ``(binary)`` as
@@ -1995,7 +1995,7 @@ Choose from the list of available rules:
 
   Removes extra spaces between colon and case value.
 
-* **switch_continue_to_break** [@Symfony, @PhpCsFixer, @PHP73Migration]
+* **switch_continue_to_break** [@Symfony, @PhpCsFixer, @PHP73Migration, @PHP74Migration]
 
   Switch case must not be ended with ``continue`` but with ``break``.
 
@@ -2009,7 +2009,7 @@ Choose from the list of available rules:
 
   *Risky rule: risky when relying on functions called on both sides of the ``?`` operator.*
 
-* **ternary_to_null_coalescing** [@PHP70Migration, @PHP71Migration, @PHP73Migration]
+* **ternary_to_null_coalescing** [@PHP70Migration, @PHP71Migration, @PHP73Migration, @PHP74Migration]
 
   Use ``null`` coalescing operator ``??`` where possible. Requires PHP >= 7.0.
 
@@ -2031,7 +2031,7 @@ Choose from the list of available rules:
 
   Unary operators should be placed adjacent to their operands.
 
-* **visibility_required** [@PSR2, @Symfony, @PhpCsFixer, @PHP71Migration, @PHP73Migration]
+* **visibility_required** [@PSR2, @Symfony, @PhpCsFixer, @PHP71Migration, @PHP73Migration, @PHP74Migration]
 
   Visibility MUST be declared on all properties and methods; ``abstract``
   and ``final`` MUST be declared before the visibility; ``static`` MUST be
@@ -2043,7 +2043,7 @@ Choose from the list of available rules:
     elements to fix (PHP >= 7.1 required for ``const``); defaults to
     ``['property', 'method']``
 
-* **void_return** [@PHP71Migration:risky]
+* **void_return** [@PHP71Migration:risky, @PHP74Migration:risky]
 
   Add ``void`` return type to functions with missing or empty return
   statements, but priority is given to ``@return`` annotations. Requires

+ 19 - 0
src/RuleSet.php

@@ -98,12 +98,17 @@ final class RuleSet implements RuleSetInterface
             'no_empty_phpdoc' => true,
             'no_empty_statement' => true,
             'no_extra_blank_lines' => ['tokens' => [
+                'case',
+                'continue',
                 'curly_brace_block',
+                'default',
                 'extra',
                 'parenthesis_brace_block',
                 'square_brace_block',
+                'switch',
                 'throw',
                 'use',
+                'use_trait',
             ]],
             'no_leading_import_slash' => true,
             'no_leading_namespace_whitespace' => true,
@@ -282,14 +287,18 @@ final class RuleSet implements RuleSetInterface
             'multiline_whitespace_before_semicolons' => ['strategy' => 'new_line_for_chained_calls'],
             'no_extra_blank_lines' => ['tokens' => [
                 'break',
+                'case',
                 'continue',
                 'curly_brace_block',
+                'default',
                 'extra',
                 'parenthesis_brace_block',
                 'return',
                 'square_brace_block',
+                'switch',
                 'throw',
                 'use',
+                'use_trait',
             ]],
             'no_null_property_initialization' => true,
             'no_superfluous_elseif' => true,
@@ -367,6 +376,16 @@ final class RuleSet implements RuleSetInterface
             'heredoc_indentation' => true,
             'switch_continue_to_break' => true,
         ],
+        '@PHP74Migration' => [
+            '@PHP73Migration' => true,
+            'normalize_index_brace' => true,
+            'short_scalar_cast' => true,
+        ],
+        '@PHP74Migration:risky' => [
+            '@PHP71Migration:risky' => true,
+            'implode_call' => true,
+            'no_alias_functions' => true,
+        ],
         '@PHPUnit30Migration:risky' => [
             'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_3_0],
         ],

+ 6 - 0
tests/Fixtures/Integration/set/@PHP74Migration-risky.test

@@ -0,0 +1,6 @@
+--TEST--
+Integration of @PHP74Migration:risky.
+--RULESET--
+{"@PHP74Migration:risky": true}
+--REQUIREMENTS--
+{"php": 70400}

+ 11 - 0
tests/Fixtures/Integration/set/@PHP74Migration-risky.test-in.php

@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.implode-reverse-parameters
+// 'implode_call'
+$x = implode($foo, '');
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.real
+// 'no_alias_functions'
+$z2 = is_real($v);

+ 11 - 0
tests/Fixtures/Integration/set/@PHP74Migration-risky.test-out.php

@@ -0,0 +1,11 @@
+<?php
+
+declare(strict_types=1);
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.implode-reverse-parameters
+// 'implode_call'
+$x = implode('', $foo);
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.real
+// 'no_alias_functions'
+$z2 = is_float($v);

+ 6 - 0
tests/Fixtures/Integration/set/@PHP74Migration.test

@@ -0,0 +1,6 @@
+--TEST--
+Integration of @PHP74Migration.
+--RULESET--
+{"@PHP74Migration": true}
+--REQUIREMENTS--
+{"php": 70400}

+ 10 - 0
tests/Fixtures/Integration/set/@PHP74Migration.test-in.php

@@ -0,0 +1,10 @@
+<?php
+
+declare(strict_types=1);
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.array-string-access-curly-brace
+// 'normalize_index_brace'
+$y = $f{1};
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.real
+// $a = (real) $a; fails on PHP7.4 tokenizing deprecation error triggered

+ 10 - 0
tests/Fixtures/Integration/set/@PHP74Migration.test-out.php

@@ -0,0 +1,10 @@
+<?php
+
+declare(strict_types=1);
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.array-string-access-curly-brace
+// 'normalize_index_brace'
+$y = $f[1];
+
+// https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.real
+// $a = (real) $a; fails on PHP7.4 tokenizing deprecation error triggered

+ 15 - 6
tests/RuleSetTest.php

@@ -672,18 +672,27 @@ final class RuleSetTest extends TestCase
         $file = sprintf('%s/%s.test', $dir, $setDefinitionFileNamePrefix);
 
         static::assertFileExists($file);
-        static::assertFileExists(sprintf('%s/%s.test-in.php', $dir, $setDefinitionFileNamePrefix));
-        static::assertFileExists(sprintf('%s/%s.test-out.php', $dir, $setDefinitionFileNamePrefix));
+
+        $fileIn = sprintf('%s/%s.test-in.php', $dir, $setDefinitionFileNamePrefix);
+        static::assertFileExists($fileIn);
+
+        $fileOut = sprintf('%s/%s.test-out.php', $dir, $setDefinitionFileNamePrefix);
+        static::assertFileExists($fileOut);
 
         $template = '--TEST--
 Integration of %s.
 --RULESET--
 {"%s": true}
 ';
-        static::assertSame(
-            sprintf($template, $setDefinitionName, $setDefinitionName),
-            file_get_contents($file)
-        );
+        $integrationTestFile = file_get_contents($file);
+        static::assertStringStartsWith(sprintf($template, $setDefinitionName, $setDefinitionName), $integrationTestFile, $setDefinitionName.':'.$integrationTestFile);
+        static::assertStringEndsWith("\n", $integrationTestFile, $setDefinitionName.':'.$integrationTestFile);
+
+        static::assertStringEndsWith("\n", file_get_contents($fileOut), $setDefinitionName.':'.$fileOut);
+
+        if ('@Symfony' !== $setDefinitionName) {
+            static::assertStringEndsWith("\n", file_get_contents($fileIn), $setDefinitionName.':'.$fileIn);
+        }
     }
 
     private function findInSets(array $sets, $ruleName, $config)