• 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

57.14
/src/Fixer/Casing/MagicConstantCasingFixer.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\CT;
22
use PhpCsFixer\Tokenizer\Token;
23
use PhpCsFixer\Tokenizer\Tokens;
24

25
/**
26
 * @author ntzm
27
 */
28
final class MagicConstantCasingFixer extends AbstractFixer
29
{
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getDefinition(): FixerDefinitionInterface
34
    {
35
        return new FixerDefinition(
3✔
36
            'Magic constants should be referred to using the correct casing.',
3✔
37
            [new CodeSample("<?php\necho __dir__;\n")]
3✔
38
        );
3✔
39
    }
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function isCandidate(Tokens $tokens): bool
45
    {
46
        return $tokens->isAnyTokenKindsFound($this->getMagicConstantTokens());
12✔
47
    }
48

49
    /**
50
     * {@inheritdoc}
51
     */
52
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
53
    {
54
        $magicConstants = $this->getMagicConstants();
12✔
55
        $magicConstantTokens = $this->getMagicConstantTokens();
12✔
56

57
        foreach ($tokens as $index => $token) {
12✔
58
            if ($token->isGivenKind($magicConstantTokens)) {
12✔
59
                $tokens[$index] = new Token([$token->getId(), $magicConstants[$token->getId()]]);
12✔
60
            }
61
        }
62
    }
63

64
    /**
65
     * @return array<int, string>
66
     */
67
    private function getMagicConstants(): array
68
    {
69
        static $magicConstants = null;
12✔
70

71
        if (null === $magicConstants) {
12✔
72
            $magicConstants = [
×
73
                T_LINE => '__LINE__',
×
74
                T_FILE => '__FILE__',
×
75
                T_DIR => '__DIR__',
×
76
                T_FUNC_C => '__FUNCTION__',
×
77
                T_CLASS_C => '__CLASS__',
×
78
                T_METHOD_C => '__METHOD__',
×
79
                T_NS_C => '__NAMESPACE__',
×
80
                CT::T_CLASS_CONSTANT => 'class',
×
81
                T_TRAIT_C => '__TRAIT__',
×
82
            ];
×
83
        }
84

85
        return $magicConstants;
12✔
86
    }
87

88
    /**
89
     * @return array<int>
90
     */
91
    private function getMagicConstantTokens(): array
92
    {
93
        static $magicConstantTokens = null;
12✔
94

95
        if (null === $magicConstantTokens) {
12✔
96
            $magicConstantTokens = array_keys($this->getMagicConstants());
×
97
        }
98

99
        return $magicConstantTokens;
12✔
100
    }
101
}
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