Failed Conditions
Push — master ( eab50b...c7ef78 )
by Alexander
03:03
created

CodingStandard_Sniffs_PHP_NoSilencedErrorsSniff   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 31 7
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 39 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
// @codeCoverageIgnoreStart
15
if (class_exists('Generic_Sniffs_PHP_NoSilencedErrorsSniff', true) === false) {
16
    $error = 'Class Generic_Sniffs_PHP_NoSilencedErrorsSniff not found';
17
    throw new PHP_CodeSniffer_Exception($error);
18
}
19
// @codeCoverageIgnoreEnd
20
21
/**
22
 * CodingStandard_Sniffs_PHP_NoSilencedErrorsSniffSniff.
23
 *
24
 * Throws an error or warning when any code prefixed with an asperand is encountered.
25
 *
26
 * <code>
27
 *  if (@in_array($array, $needle))
28
 *  {
29
 *      doSomething();
30
 *  }
31
 * </code>
32
 *
33
 * @category PHP
34
 * @package  PHP_CodeSniffer
35
 * @author   Alexander Obuhovich <[email protected]>
36
 * @license  https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause
37
 * @link     https://github.com/aik099/CodingStandard
38
 */
39
class CodingStandard_Sniffs_PHP_NoSilencedErrorsSniff extends Generic_Sniffs_PHP_NoSilencedErrorsSniff
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
40
{
41
42
    /**
43
     * Processes this test, when one of its tokens is encountered.
44
     *
45
     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
46
     * @param int                  $stackPtr  The position of the current token
47
     *                                        in the stack passed in $tokens.
48
     *
49
     * @return void
50
     */
51 1
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
52
    {
53 1
        $tokens = $phpcsFile->getTokens();
54 1
        $secondTokenData = $tokens[($stackPtr + 1)];
55 1
        $thirdTokenData = $tokens[($stackPtr + 2)];
56
57
        // This is a silenced "trigger_error" function call.
58 1
        if ($secondTokenData['code'] === T_STRING
59 1
            && $secondTokenData['content'] === 'trigger_error'
60 1
            && $thirdTokenData['code'] === T_OPEN_PARENTHESIS
61 1
            && isset($thirdTokenData['parenthesis_closer']) === true
62 1
        ) {
63 1
            $lastArgumentToken = $phpcsFile->findPrevious(
64 1
                PHP_CodeSniffer_Tokens::$emptyTokens,
65 1
                ($thirdTokenData['parenthesis_closer'] - 1),
66 1
                ($thirdTokenData['parenthesis_opener'] + 1),
67
                true
68 1
            );
69
70 1
            $lastArgumentTokenData = $tokens[$lastArgumentToken];
71
72 1
            if ($lastArgumentTokenData['code'] === T_STRING
73 1
                && $lastArgumentTokenData['content'] === 'E_USER_DEPRECATED'
74 1
            ) {
75 1
                return;
76
            }
77 1
        }
78
79 1
        parent::process($phpcsFile, $stackPtr);
80
81 1
    }//end process()
82
83
84
}//end class
85