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

PHP-CS-Fixer / PHP-CS-Fixer / 3721300657

pending completion
3721300657

push

github

GitHub
minor: Follow PSR12 ordered imports in Symfony ruleset (#6712)

9 of 9 new or added lines in 2 files covered. (100.0%)

22674 of 24281 relevant lines covered (93.38%)

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

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function isCandidate(Tokens $tokens): bool
45
    {
46
        return $tokens->isTokenKindFound(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN);
×
47
    }
48

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