NoElseSniff   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 3
c 1
b 0
f 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A process() 0 3 1
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