Completed
Push — in-portal ( 542489...3b6de0 )
by Alexander
04:02
created

NoSilencedErrorsSniff   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 30 7
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 1
    public function process(File $phpcsFile, $stackPtr)
51
    {
52 1
        $tokens          = $phpcsFile->getTokens();
53 1
        $secondTokenData = $tokens[($stackPtr + 1)];
54 1
        $thirdTokenData  = $tokens[($stackPtr + 2)];
55
56
        // This is a silenced "trigger_error" function call.
57 1
        if ($secondTokenData['code'] === T_STRING
58 1
            && $secondTokenData['content'] === 'trigger_error'
59 1
            && $thirdTokenData['code'] === T_OPEN_PARENTHESIS
60 1
            && isset($thirdTokenData['parenthesis_closer']) === true
61 1
        ) {
62 1
            $lastArgumentToken = $phpcsFile->findPrevious(
63 1
                Tokens::$emptyTokens,
64 1
                ($thirdTokenData['parenthesis_closer'] - 1),
65 1
                ($thirdTokenData['parenthesis_opener'] + 1),
66
                true
67 1
            );
68
69 1
            $lastArgumentTokenData = $tokens[$lastArgumentToken];
70
71 1
            if ($lastArgumentTokenData['code'] === T_STRING
72 1
                && $lastArgumentTokenData['content'] === 'E_USER_DEPRECATED'
73 1
            ) {
74 1
                return;
75
            }
76 1
        }
77
78 1
        parent::process($phpcsFile, $stackPtr);
79 1
    }//end process()
80
}//end class
81