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

keradus / PHP-CS-Fixer / 17319949156

29 Aug 2025 09:20AM UTC coverage: 94.696% (-0.05%) from 94.744%
17319949156

push

github

keradus
CS

28333 of 29920 relevant lines covered (94.7%)

45.63 hits per line

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

97.14
/src/Fixer/Basic/NoMultipleStatementsPerLineFixer.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\Basic;
16

17
use PhpCsFixer\AbstractFixer;
18
use PhpCsFixer\Fixer\IndentationTrait;
19
use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
20
use PhpCsFixer\FixerDefinition\CodeSample;
21
use PhpCsFixer\FixerDefinition\FixerDefinition;
22
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
23
use PhpCsFixer\Preg;
24
use PhpCsFixer\Tokenizer\CT;
25
use PhpCsFixer\Tokenizer\Tokens;
26

27
/**
28
 * Fixer for rules defined in PSR2 ¶2.3 Lines: There must not be more than one statement per line.
29
 *
30
 * @no-named-arguments Parameter names are not covered by the backward compatibility promise.
31
 */
32
final class NoMultipleStatementsPerLineFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
33
{
34
    use IndentationTrait;
35

36
    public function getDefinition(): FixerDefinitionInterface
37
    {
38
        return new FixerDefinition(
3✔
39
            'There must not be more than one statement per line.',
3✔
40
            [new CodeSample("<?php\nfoo(); bar();\n")]
3✔
41
        );
3✔
42
    }
43

44
    /**
45
     * {@inheritdoc}
46
     *
47
     * Must run before BracesPositionFixer, CurlyBracesPositionFixer.
48
     * Must run after ControlStructureBracesFixer, NoEmptyStatementFixer, YieldFromArrayToYieldsFixer.
49
     */
50
    public function getPriority(): int
51
    {
52
        return -1;
1✔
53
    }
54

55
    public function isCandidate(Tokens $tokens): bool
56
    {
57
        return $tokens->isTokenKindFound(';');
12✔
58
    }
59

60
    protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
61
    {
62
        for ($index = 1, $max = \count($tokens) - 1; $index < $max; ++$index) {
12✔
63
            if ($tokens[$index]->isGivenKind(\T_FOR)) {
12✔
64
                $index = $tokens->findBlockEnd(
2✔
65
                    Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
2✔
66
                    $tokens->getNextTokenOfKind($index, ['('])
2✔
67
                );
2✔
68

69
                continue;
2✔
70
            }
71

72
            if ($tokens[$index]->isGivenKind(CT::T_PROPERTY_HOOK_BRACE_OPEN)) {
12✔
73
                $index = $tokens->findBlockEnd(
1✔
74
                    Tokens::BLOCK_TYPE_PROPERTY_HOOK,
1✔
75
                    $index
1✔
76
                );
1✔
77

78
                continue;
1✔
79
            }
80

81
            if (!$tokens[$index]->equals(';')) {
12✔
82
                continue;
12✔
83
            }
84

85
            for ($nextIndex = $index + 1; $nextIndex < $max; ++$nextIndex) {
11✔
86
                $token = $tokens[$nextIndex];
11✔
87

88
                if ($token->isWhitespace() || $token->isComment()) {
11✔
89
                    if (Preg::match('/\R/', $token->getContent())) {
11✔
90
                        break;
3✔
91
                    }
92

93
                    continue;
10✔
94
                }
95

96
                if (!$token->equalsAny(['}', [\T_CLOSE_TAG], [\T_ENDIF], [\T_ENDFOR], [\T_ENDSWITCH], [\T_ENDWHILE], [\T_ENDFOREACH]])) {
8✔
97
                    $whitespaceIndex = $index;
3✔
98
                    do {
99
                        $token = $tokens[++$whitespaceIndex];
3✔
100
                    } while ($token->isComment());
3✔
101

102
                    $newline = $this->whitespacesConfig->getLineEnding().$this->getLineIndentation($tokens, $index);
3✔
103

104
                    if ($tokens->ensureWhitespaceAtIndex($whitespaceIndex, 0, $newline)) {
3✔
105
                        ++$max;
×
106
                    }
107
                }
108

109
                break;
8✔
110
            }
111
        }
112
    }
113
}
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