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

webimpress / coding-standard / 4086684577

pending completion
4086684577

Pull #178

github

GitHub
Merge 75aa3b533 into 18aa29088
Pull Request #178: Bump phpunit/phpunit from 9.5.20 to 9.6.0

6985 of 6999 relevant lines covered (99.8%)

1.13 hits per line

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

92.86
/src/WebimpressCodingStandard/Sniffs/ControlStructures/DefaultAsLastSniff.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace WebimpressCodingStandard\Sniffs\ControlStructures;
6

7
use PHP_CodeSniffer\Files\File;
8
use PHP_CodeSniffer\Sniffs\Sniff;
9

10
use function array_reverse;
11
use function key;
12

13
use const T_CASE;
14
use const T_DEFAULT;
15

16
class DefaultAsLastSniff implements Sniff
17
{
18
    /**
19
     * @return int[]
20
     */
21
    public function register() : array
22
    {
23
        return [T_DEFAULT];
1✔
24
    }
25

26
    /**
27
     * @param int $stackPtr
28
     */
29
    public function process(File $phpcsFile, $stackPtr) : void
30
    {
31
        $tokens = $phpcsFile->getTokens();
1✔
32
        $default = $tokens[$stackPtr];
1✔
33
        $switchPtr = key(array_reverse($default['conditions'], true));
1✔
34

35
        // skip in case of default statement in PHP 8 match expression
36
        if ($switchPtr === null) {
1✔
37
            return;
×
38
        }
39

40
        $closer = $tokens[$switchPtr]['scope_closer'];
1✔
41

42
        $from = $stackPtr;
1✔
43

44
        while ($casePtr = $phpcsFile->findNext(T_CASE, $from + 1, $closer)) {
1✔
45
            if ($switchPtr === key(array_reverse($tokens[$casePtr]['conditions'], true))) {
1✔
46
                $error = 'Default case in switch should be as last; another case found here';
1✔
47
                $phpcsFile->addError($error, $casePtr, 'CaseAfterDefault');
1✔
48
                break;
1✔
49
            }
50

51
            $from = $casePtr;
1✔
52
        }
53
    }
54
}
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