Failed Conditions
Push — phpcs-3-upgrade ( d91341 )
by Alexander
02:06
created

NoSilencedErrorsSniff::process()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 3
nop 2
dl 0
loc 30
rs 8.5066
c 0
b 0
f 0
1
<?php
2
/**
3
 * CodingStandard_Sniffs_PHP_NoSilencedErrorsSniffSniff
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  PHP_CodeSniffer
9
 * @author   Alexander Obuhovich <[email protected]>
10
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
11
 * @link     https://github.com/aik099/CodingStandard
12
 */
13
14
namespace CodingStandard\Sniffs\PHP;
15
16
use PHP_CodeSniffer\Files\File;
17
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\NoSilencedErrorsSniff as Generic_NoSilencedErrorsSniff;
18
use PHP_CodeSniffer\Util\Tokens;
19
20
/**
21
 * CodingStandard_Sniffs_PHP_NoSilencedErrorsSniffSniff.
22
 *
23
 * Throws an error or warning when any code prefixed with an asperand is encountered.
24
 *
25
 * <code>
26
 *  if (@in_array($array, $needle))
27
 *  {
28
 *      doSomething();
29
 *  }
30
 * </code>
31
 *
32
 * @category PHP
33
 * @package  PHP_CodeSniffer
34
 * @author   Alexander Obuhovich <[email protected]>
35
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
36
 * @link     https://github.com/aik099/CodingStandard
37
 */
38
class NoSilencedErrorsSniff extends Generic_NoSilencedErrorsSniff
39
{
40
41
    /**
42
     * Processes this test, when one of its tokens is encountered.
43
     *
44
     * @param File $phpcsFile The file being scanned.
45
     * @param int  $stackPtr  The position of the current token in the
46
     *                        stack passed in $tokens.
47
     *
48
     * @return void
49
     */
50
    public function process(File $phpcsFile, $stackPtr)
51
    {
52
        $tokens          = $phpcsFile->getTokens();
53
        $secondTokenData = $tokens[($stackPtr + 1)];
54
        $thirdTokenData  = $tokens[($stackPtr + 2)];
55
56
        // This is a silenced "trigger_error" function call.
57
        if ($secondTokenData['code'] === T_STRING
58
            && $secondTokenData['content'] === 'trigger_error'
59
            && $thirdTokenData['code'] === T_OPEN_PARENTHESIS
60
            && isset($thirdTokenData['parenthesis_closer']) === true
61
        ) {
62
            $lastArgumentToken = $phpcsFile->findPrevious(
63
                Tokens::$emptyTokens,
64
                ($thirdTokenData['parenthesis_closer'] - 1),
65
                ($thirdTokenData['parenthesis_opener'] + 1),
66
                true
67
            );
68
69
            $lastArgumentTokenData = $tokens[$lastArgumentToken];
70
71
            if ($lastArgumentTokenData['code'] === T_STRING
72
                && $lastArgumentTokenData['content'] === 'E_USER_DEPRECATED'
73
            ) {
74
                return;
75
            }
76
        }
77
78
        parent::process($phpcsFile, $stackPtr);
79
    }//end process()
80
}//end class
81