NoElseSniff::process()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php declare(strict_types = 1);
2
3
namespace Codor\Sniffs\ControlStructures;
4
5
use PHP_CodeSniffer\Sniffs\Sniff as PHP_CodeSniffer_Sniff;
6
use PHP_CodeSniffer\Files\File as PHP_CodeSniffer_File;
7
8
/**
9
 * Do not use "else" or "elseif".
10
 */
11
class NoElseSniff implements PHP_CodeSniffer_Sniff
12
{
13
14
    /**
15
     * Returns the token types that this sniff is interested in.
16
     * @return array
17
     */
18
    public function register(): array
19
    {
20
        return [T_ELSE, T_ELSEIF];
21
    }
22
23
    /**
24
     * Processes the tokens that this sniff is interested in.
25
     *
26
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
27
     * @param integer              $stackPtr  The position in the stack where
28
     *                                    the token was found.
29
     * @return void
30
     */
31
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
32
    {
33
        $phpcsFile->addError('Do not use "else" or "elseif"', $stackPtr, __CLASS__);
34
    }
35
}
36