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

PHP-CS-Fixer / PHP-CS-Fixer / 12831369634

17 Jan 2025 02:50PM UTC coverage: 94.964%. Remained the same
12831369634

push

github

web-flow
refactor: Use native `Yaml::parseFile()` instead of custom method (#8380)

27892 of 29371 relevant lines covered (94.96%)

43.09 hits per line

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

0.0
/src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.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\ArrayNotation;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\FixerDefinition\FixerDefinition;
19
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
20
use PhpCsFixer\FixerDefinition\VersionSpecification;
21
use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
22
use PhpCsFixer\Tokenizer\CT;
23
use PhpCsFixer\Tokenizer\Token;
24
use PhpCsFixer\Tokenizer\Tokens;
25

26
/**
27
 * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
28
 */
29
final class NormalizeIndexBraceFixer extends AbstractFixer
30
{
31
    public function getDefinition(): FixerDefinitionInterface
32
    {
33
        return new FixerDefinition(
×
34
            'Array index should always be written by using square braces.',
×
35
            [new VersionSpecificCodeSample(
×
36
                "<?php\necho \$sample{\$index};\n",
×
37
                new VersionSpecification(null, 8_04_00 - 1)
×
38
            )]
×
39
        );
×
40
    }
41

42
    public function isCandidate(Tokens $tokens): bool
43
    {
44
        return $tokens->isTokenKindFound(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN);
×
45
    }
46

47
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
48
    {
49
        foreach ($tokens as $index => $token) {
×
50
            if ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) {
×
51
                $tokens[$index] = new Token('[');
×
52
            } elseif ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE)) {
×
53
                $tokens[$index] = new Token(']');
×
54
            }
55
        }
56
    }
57
}
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