NativeFunctionInvocationFixer - add namespace scope and include sets

by @SpacePossum

Some issues have been detected in this pull request

Issues that can be fixed by applying a patch

Review the proposed patch then download it to apply it manually or execute the following command from the repository root directory:

$ curl https://fabbot.io/patch/FriendsOfPHP/PHP-CS-Fixer/3223/0967ce5c8feecddb736bef4bc88fe7a36d2c9f5e/cs.diff | patch -p0
diff -ru src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php
--- src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php	2018-04-16 08:07:43.277266455 +0000
+++ src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php	2018-04-16 08:07:44.165246429 +0000
@@ -55,7 +55,7 @@
     {
         return new FixerDefinition(
             'Add leading `\` before function invocation to speed up resolving.',
-            [
+            array(
                 new CodeSample(
 '<?php
 
@@ -81,11 +81,11 @@
     return json_encode($options);
 }
 ',
-                    [
-                        'exclude' => [
+                    array(
+                        'exclude' => array(
                             'json_encode',
-                        ],
-                    ]
+                        ),
+                    )
                 ),
                 new CodeSample(
                     '<?php
@@ -96,37 +96,37 @@
     echo count([1]);
 }
 ',
-                    ['scope' => 'namespaced']
+                    array('scope' => 'namespaced')
                 ),
                 new CodeSample(
                     '<?php
 myGlobalFunction();
 count();
 ',
-                    ['include' => ['myGlobalFunction']]
+                    array('include' => array('myGlobalFunction'))
                 ),
                 new CodeSample(
                     '<?php
 myGlobalFunction();
 count();
 ',
-                    ['include' => ['@all']]
+                    array('include' => array('@all'))
                 ),
                 new CodeSample(
                     '<?php
 myGlobalFunction();
 count();
 ',
-                    ['include' => ['@internal']]
+                    array('include' => array('@internal'))
                 ),
                 new CodeSample(
                     '<?php
 $a .= str_repeat($a, 4);
 $c = get_class($d);
 ',
-                    ['include' => ['@compiler_optimized']]
+                    array('include' => array('@compiler_optimized'))
                 ),
-            ],
+            ),
             null,
             'Risky when any of the functions are overridden.'
         );
@@ -172,10 +172,10 @@
      */
     protected function createConfigurationDefinition()
     {
-        return new FixerConfigurationResolver([
+        return new FixerConfigurationResolver(array(
             (new FixerOptionBuilder('exclude', 'List of functions to ignore.'))
-                ->setAllowedTypes(['array'])
-                ->setAllowedValues([static function (array $value) {
+                ->setAllowedTypes(array('array'))
+                ->setAllowedValues(array(static function (array $value) {
                     foreach ($value as $functionName) {
                         if (!\is_string($functionName) || '' === \trim($functionName) || \trim($functionName) !== $functionName) {
                             throw new InvalidOptionsException(\sprintf(
@@ -186,11 +186,11 @@
                     }
 
                     return true;
-                }])
-                ->setDefault([])
+                }))
+                ->setDefault(array())
                 ->getOption(),
             (new FixerOptionBuilder('include', 'List of function names or sets to fix. Defined sets are `@internal` (all native functions), `@all` (all global functions) and `@compiler_optimized` (functions that are specially optimized by Zend).'))
-                ->setAllowedValues([static function (array $value) {
+                ->setAllowedValues(array(static function (array $value) {
                     foreach ($value as $functionName) {
                         if (!\is_string($functionName) || '' === \trim($functionName) || \trim($functionName) !== $functionName) {
                             throw new InvalidOptionsException(\sprintf(
@@ -199,11 +199,11 @@
                             ));
                         }
 
-                        static $sets = [
+                        static $sets = array(
                             self::SET_ALL,
                             self::SET_INTERNAL,
                             self::SET_COMPILER_OPTIMIZED,
-                        ];
+                        );
 
                         if ('@' === $value[0] && !\in_array($value, $sets, true)) {
                             throw new InvalidOptionsException(\sprintf('Unknown set "%s", known sets are "%s".', $value, \implode('", "', $sets)));
@@ -211,14 +211,14 @@
                     }
 
                     return true;
-                }])
-                ->setDefault([self::SET_INTERNAL])
+                }))
+                ->setDefault(array(self::SET_INTERNAL))
                 ->getOption(),
             (new FixerOptionBuilder('scope', 'Only fix function calls that are made within a namespace or fix globally.'))
-                ->setAllowedValues(['global', 'namespaced'])
+                ->setAllowedValues(array('global', 'namespaced'))
                 ->setDefault('global')
                 ->getOption(),
-        ]);
+        ));
     }
 
     /**
@@ -229,7 +229,7 @@
      */
     private function fixFunctionCalls(Tokens $tokens, callable $functionFilter, $start, $end)
     {
-        $insertAtIndexes = [];
+        $insertAtIndexes = array();
         for ($index = $start; $index < $end; ++$index) {
             // test if we are at a function call
             if (!$tokens[$index]->isGivenKind(T_STRING)) {
@@ -241,13 +241,13 @@
             }
 
             $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
-            if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION])) {
+            if ($tokens[$functionNamePrefix]->isGivenKind(array(T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION))) {
                 continue;
             }
 
             if (
                 $tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)
-                && $tokens[$tokens->getPrevMeaningfulToken($functionNamePrefix)]->isGivenKind([T_STRING, T_NEW])
+                && $tokens[$tokens->getPrevMeaningfulToken($functionNamePrefix)]->isGivenKind(array(T_STRING, T_NEW))
             ) {
                 continue; // skip if the call is to a constructor or to a function in a namespace other than the default
             }
@@ -264,7 +264,7 @@
         }
 
         foreach (\array_reverse($insertAtIndexes) as $index) {
-            $tokens->insertAt($index, new Token([T_NS_SEPARATOR, '\\']));
+            $tokens->insertAt($index, new Token(array(T_NS_SEPARATOR, '\\')));
         }
     }
 
@@ -287,7 +287,7 @@
             };
         }
 
-        $include = [];
+        $include = array();
         if (\in_array(self::SET_INTERNAL, $this->configuration['include'], true)) {
             $include = $this->getAllInternalFunctionsNormalized();
         } elseif (\in_array(self::SET_COMPILER_OPTIMIZED, $this->configuration['include'], true)) {
@@ -319,7 +319,7 @@
         static $optimizedFunctions = null;
 
         if (null === $optimizedFunctions) {
-            $optimizedFunctions = $this->normalizeFunctionNames([
+            $optimizedFunctions = $this->normalizeFunctionNames(array(
                 'array_slice',
                 'assert',
                 'boolval',
@@ -352,7 +352,7 @@
                 'ord',
                 'strlen',
                 'strval',
-            ]);
+            ));
         }
 
         return $optimizedFunctions;
@@ -381,7 +381,7 @@
      */
     private function getUserDefinedNamespaces(Tokens $tokens)
     {
-        $namespaces = [];
+        $namespaces = array();
         for ($index = 1, $count = \count($tokens); $index < $count; ++$index) {
             if (!$tokens[$index]->isGivenKind(T_NAMESPACE)) {
                 continue;
@@ -394,26 +394,26 @@
                 continue;
             }
 
-            while (!$tokens[++$index]->equalsAny(['{', ';', [T_CLOSE_TAG]])) {
+            while (!$tokens[++$index]->equalsAny(array('{', ';', array(T_CLOSE_TAG)))) {
                 // no-op
             }
 
             if ($tokens[$index]->equals('{')) {
                 // namespace ends at block end of `{`
-                $namespaces[] = ['open' => $index, 'close' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index)];
+                $namespaces[] = array('open' => $index, 'close' => $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index));
 
                 continue;
             }
 
             // namespace ends at next T_NAMESPACE or EOF
-            $close = $tokens->getNextTokenOfKind($index, [[T_NAMESPACE]], false);
+            $close = $tokens->getNextTokenOfKind($index, array(array(T_NAMESPACE)), false);
             if (null === $close) {
-                $namespaces[] = ['open' => $index, 'close' => \count($tokens) - 1];
+                $namespaces[] = array('open' => $index, 'close' => \count($tokens) - 1);
 
                 break;
             }
 
-            $namespaces[] = ['open' => $index, 'close' => $close];
+            $namespaces[] = array('open' => $index, 'close' => $close);
         }
 
         return $namespaces;
diff -ru tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php
--- tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php	2018-04-16 08:07:43.440262779 +0000
+++ tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php	2018-04-16 08:07:43.794254796 +0000
@@ -34,9 +34,9 @@
             $key
         ));
 
-        $this->fixer->configure([
+        $this->fixer->configure(array(
             $key => 'bar',
-        ]);
+        ));
     }
 
     /**
@@ -52,11 +52,11 @@
             \is_object($element) ? \get_class($element) : \gettype($element)
         ));
 
-        $this->fixer->configure([
-            'exclude' => [
+        $this->fixer->configure(array(
+            'exclude' => array(
                 $element,
-            ],
-        ]);
+            ),
+        ));
     }
 
     /**
@@ -64,25 +64,25 @@
      */
     public function provideInvalidConfigurationElementCases()
     {
-        return [
-            'null' => [null],
-            'false' => [false],
-            'true' => [false],
-            'int' => [1],
-            'array' => [[]],
-            'float' => [0.1],
-            'object' => [new \stdClass()],
-            'not-trimmed' => ['  json_encode  '],
-        ];
+        return array(
+            'null' => array(null),
+            'false' => array(false),
+            'true' => array(false),
+            'int' => array(1),
+            'array' => array(array()),
+            'float' => array(0.1),
+            'object' => array(new \stdClass()),
+            'not-trimmed' => array('  json_encode  '),
+        );
     }
 
     public function testConfigureResetsExclude()
     {
-        $this->fixer->configure([
-            'exclude' => [
+        $this->fixer->configure(array(
+            'exclude' => array(
                 'json_encode',
-            ],
-        ]);
+            ),
+        ));
 
         $before = <<<'PHP'
 <?php
@@ -118,7 +118,7 @@
 
         $this->doTest($before);
 
-        $this->fixer->configure([]);
+        $this->fixer->configure(array());
 
         $this->doTest($after, $before);
     }
@@ -146,14 +146,14 @@
      */
     public function provideFixWithDefaultConfigurationCases()
     {
-        return [
-            [
+        return array(
+            array(
                 '<?php
 
 \json_encode($foo);
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 
 \json_encode($foo);
@@ -162,8 +162,8 @@
 
 json_encode($foo);
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 
 class Foo
@@ -174,8 +174,8 @@
     }
 }
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 
 class Foo
@@ -196,8 +196,8 @@
     }
 }
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 echo \/**/strlen($a);
 echo \ strlen($a);
@@ -214,8 +214,8 @@
 strlen($a);
 echo strlen($a);
 ',
-            ],
-        ];
+            ),
+        );
     }
 
     /**
@@ -226,11 +226,11 @@
      */
     public function testFixWithConfiguredExclude($expected, $input = null)
     {
-        $this->fixer->configure([
-            'exclude' => [
+        $this->fixer->configure(array(
+            'exclude' => array(
                 'json_encode',
-            ],
-        ]);
+            ),
+        ));
 
         $this->doTest($expected, $input);
     }
@@ -240,14 +240,14 @@
      */
     public function provideFixWithConfiguredExcludeCases()
     {
-        return [
-            [
+        return array(
+            array(
                 '<?php
 
 json_encode($foo);
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 
 class Foo
@@ -258,8 +258,8 @@
     }
 }
 ',
-            ],
-        ];
+            ),
+        );
     }
 
     /**
@@ -270,17 +270,17 @@
      */
     public function testFixWithNamespaceConfiguration($expected, $input = null)
     {
-        $this->fixer->configure(['scope' => 'namespaced']);
+        $this->fixer->configure(array('scope' => 'namespaced'));
         $this->doTest($expected, $input);
     }
 
     public function provideFixWithNamespaceConfigurationCases()
     {
-        return [
-            [
+        return array(
+            array(
                 '<?php echo count([1]);',
-            ],
-            [
+            ),
+            array(
                 '<?php
 namespace space1 { ?>
 <?php echo \count([2]) ?>
@@ -291,8 +291,8 @@
 <?php echo count([2]) ?>
 <?php }namespace {echo count([1]);}
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 namespace Bar {
     echo \strtoLOWER("in 1");
@@ -335,8 +335,8 @@
     echo strtolower("out 3");
 }
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php
 namespace space11 ?>
 
@@ -353,12 +353,12 @@
 namespace space2;
 echo strtolower(__NAMESPACE__);
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php namespace PhpCsFixer\Tests\Fixer\Casing;\count([1]);',
                 '<?php namespace PhpCsFixer\Tests\Fixer\Casing;count([1]);',
-            ],
-            [
+            ),
+            array(
                 '<?php
 namespace Space12;
 
@@ -379,11 +379,11 @@
 echo count([1]);
 ?>
 ',
-            ],
-            [
+            ),
+            array(
                 '<?php namespace {echo strtolower("out 2");}',
-            ],
-            [
+            ),
+            array(
                 '<?php
 namespace space13 {
     echo \strtolower("in 1");
@@ -410,8 +410,8 @@
     echo strtolower("global 1");
 }
 ',
-            ],
-        ];
+            ),
+        );
     }
 
     /**
@@ -421,7 +421,7 @@
      * @param null|string $input
      * @param array       $configuration
      */
-    public function testFixWithConfiguredInclude($expected, $input = null, array $configuration = [])
+    public function testFixWithConfiguredInclude($expected, $input = null, array $configuration = array())
     {
         $this->fixer->configure($configuration);
 
@@ -433,8 +433,8 @@
      */
     public function provideFixWithConfiguredIncludeCases()
     {
-        return [
-            'include set + 1, exclude 1' => [
+        return array(
+            'include set + 1, exclude 1' => array(
                 '<?php
                     echo \count([1]);
                     \some_other($a, 3);
@@ -447,12 +447,12 @@
                     echo strlen($a);
                     not_me();
                 ',
-                [
-                    'include' => ['@internal', 'some_other'],
-                    'exclude' => ['strlen'],
-                ],
-            ],
-            'include @all' => [
+                array(
+                    'include' => array('@internal', 'some_other'),
+                    'exclude' => array('strlen'),
+                ),
+            ),
+            'include @all' => array(
                 '<?php
                     echo \count([1]);
                     \some_other($a, 3);
@@ -465,11 +465,11 @@
                     echo strlen($a);
                     me_as_well();
                 ',
-                [
-                    'include' => ['@all'],
-                ],
-            ],
-            'include @compiler_optimized' => [
+                array(
+                    'include' => array('@all'),
+                ),
+            ),
+            'include @compiler_optimized' => array(
                 '<?php
                     // do not fix
                     $a = strrev($a);
@@ -486,10 +486,10 @@
                     $c = get_class($d);
                     $e = intval($f);
                 ',
-                [
-                    'include' => ['@compiler_optimized'],
-                ],
-            ],
-        ];
+                array(
+                    'include' => array('@compiler_optimized'),
+                ),
+            ),
+        );
     }
 }

0
Common Typos

0
File Permissions