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

keradus / PHP-CS-Fixer / 17678835382

12 Sep 2025 03:24PM UTC coverage: 94.69% (-0.06%) from 94.75%
17678835382

push

github

keradus
fix typo

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

1042 existing lines in 177 files now uncovered.

28424 of 30018 relevant lines covered (94.69%)

45.5 hits per line

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

95.24
/src/Fixer/Operator/NoUselessNullsafeOperatorFixer.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\Operator;
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\Token;
23
use PhpCsFixer\Tokenizer\Tokens;
24

25
/**
26
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
27
 */
28
final class NoUselessNullsafeOperatorFixer extends AbstractFixer
29
{
30
    public function getDefinition(): FixerDefinitionInterface
31
    {
32
        return new FixerDefinition(
3✔
33
            'There should not be useless Null-safe operator `?->` used.',
3✔
34
            [
3✔
35
                new VersionSpecificCodeSample(
3✔
36
                    <<<'PHP'
3✔
37
                        <?php
38
                        class Foo extends Bar
39
                        {
40
                            public function test() {
41
                                echo $this?->parentMethod();
42
                            }
43
                        }
44

45
                        PHP,
3✔
46
                    new VersionSpecification(8_00_00)
3✔
47
                ),
3✔
48
            ]
3✔
49
        );
3✔
50
    }
51

52
    public function isCandidate(Tokens $tokens): bool
53
    {
54
        return \PHP_VERSION_ID >= 8_00_00 && $tokens->isAllTokenKindsFound([\T_VARIABLE, \T_NULLSAFE_OBJECT_OPERATOR]);
3✔
55
    }
56

57
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
58
    {
59
        for ($index = $tokens->count() - 1; $index >= 0; --$index) {
3✔
60
            if (!$tokens[$index]->isGivenKind(\T_NULLSAFE_OBJECT_OPERATOR)) {
3✔
61
                continue;
3✔
62
            }
63

64
            $nullsafeObjectOperatorIndex = $index;
3✔
65
            $index = $tokens->getPrevMeaningfulToken($index);
3✔
66

67
            if (!$tokens[$index]->isGivenKind(\T_VARIABLE)) {
3✔
68
                continue;
1✔
69
            }
70

71
            if ('$this' !== strtolower($tokens[$index]->getContent())) {
3✔
UNCOV
72
                continue;
×
73
            }
74

75
            $tokens[$nullsafeObjectOperatorIndex] = new Token([\T_OBJECT_OPERATOR, '->']);
3✔
76
        }
77
    }
78
}
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

© 2026 Coveralls, Inc