• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHP-CS-Fixer / PHP-CS-Fixer / 3825623956

pending completion
3825623956

Pull #6734

github

GitHub
Merge f402171a0 into f5726f543
Pull Request #6734: bug: Fix type error when using paths intersection mode

1 of 1 new or added line in 1 file covered. (100.0%)

22556 of 24273 relevant lines covered (92.93%)

39.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.73
/src/Fixer/Casing/NativeFunctionCasingFixer.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz RumiƄski <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Fixer\Casing;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\FixerDefinition\CodeSample;
19
use PhpCsFixer\FixerDefinition\FixerDefinition;
20
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
21
use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer;
22
use PhpCsFixer\Tokenizer\Token;
23
use PhpCsFixer\Tokenizer\Tokens;
24

25
final class NativeFunctionCasingFixer extends AbstractFixer
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getDefinition(): FixerDefinitionInterface
31
    {
32
        return new FixerDefinition(
3✔
33
            'Function defined by PHP should be called using the correct casing.',
3✔
34
            [new CodeSample("<?php\nSTRLEN(\$str);\n")]
3✔
35
        );
3✔
36
    }
37

38
    /**
39
     * {@inheritdoc}
40
     *
41
     * Must run after FunctionToConstantFixer, NoUselessSprintfFixer, PowToExponentiationFixer.
42
     */
43
    public function getPriority(): int
44
    {
45
        return 0;
1✔
46
    }
47

48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function isCandidate(Tokens $tokens): bool
52
    {
53
        return $tokens->isTokenKindFound(T_STRING);
21✔
54
    }
55

56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
60
    {
61
        $functionsAnalyzer = new FunctionsAnalyzer();
21✔
62

63
        static $nativeFunctionNames = null;
21✔
64

65
        if (null === $nativeFunctionNames) {
21✔
66
            $nativeFunctionNames = $this->getNativeFunctionNames();
×
67
        }
68

69
        for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
21✔
70
            // test if we are at a function all
71
            if (!$functionsAnalyzer->isGlobalFunctionCall($tokens, $index)) {
21✔
72
                continue;
21✔
73
            }
74

75
            // test if the function call is to a native PHP function
76
            $lower = strtolower($tokens[$index]->getContent());
11✔
77
            if (!\array_key_exists($lower, $nativeFunctionNames)) {
11✔
78
                continue;
1✔
79
            }
80

81
            $tokens[$index] = new Token([T_STRING, $nativeFunctionNames[$lower]]);
10✔
82
        }
83
    }
84

85
    /**
86
     * @return array<string, string>
87
     */
88
    private function getNativeFunctionNames(): array
89
    {
90
        $allFunctions = get_defined_functions();
×
91
        $functions = [];
×
92
        foreach ($allFunctions['internal'] as $function) {
×
93
            $functions[strtolower($function)] = $function;
×
94
        }
95

96
        return $functions;
×
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc