Completed
Pull Request — master (#64)
by Bill
02:04
created

MethodFlagParameterSniff::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 2
1
<?php
2
3
namespace Codor\Sniffs\Files;
4
5
use PHP_CodeSniffer_Sniff;
6
use PHP_CodeSniffer_File;
7
8
class MethodFlagParameterSniff implements PHP_CodeSniffer_Sniff
9
{
10
11
    protected $booleans = ['T_FALSE', 'T_TRUE'];
12
13
    /**
14
     * Returns the token types that this sniff is interested in.
15
     * @return array
16
     */
17
    public function register()
18
    {
19
        return [T_FUNCTION];
20
    }
21
22
    /**
23
     * Processes the tokens that this sniff is interested in.
24
     *
25
     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
26
     * @param integer              $stackPtr  The position in the stack where
27
     *                                    the token was found.
28
     * @return void
29
     */
30
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
31
    {
32
        $tokens           = $phpcsFile->getTokens();
33
34
        $token            = $tokens[$stackPtr];
35
        $openParenIndex   = $token['parenthesis_opener'];
36
        $closedParenIndex = $token['parenthesis_closer'];
37
38
        for ($index=$openParenIndex+1; $index <= $closedParenIndex; $index++) {
39
            if (in_array($tokens[$index]['type'], $this->booleans)) {
40
                $phpcsFile->addError("Function/method contains a flag parameter.", $stackPtr);
41
                continue;
42
            }
43
        }
44
    }
45
}
46