1 | <?php |
||
17 | class PHPCompatibility_Sniffs_PHP_NewFunctionParametersSniff extends PHPCompatibility_Sniff |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * If true, forbidden functions will be considered regular expressions. |
||
22 | * |
||
23 | * @var bool |
||
24 | */ |
||
25 | protected $patternMatch = false; |
||
26 | |||
27 | /** |
||
28 | * A list of new functions, not present in older versions. |
||
29 | * |
||
30 | * The array lists : version number with false (not present) or true (present). |
||
31 | * The index is the location of the parameter in the parameter list, starting at 0 ! |
||
32 | * If's sufficient to list the first version where the function appears. |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | public $newFunctionParameters = array( |
||
37 | 'dirname' => array( |
||
38 | 1 => array( |
||
39 | 'name' => 'depth', |
||
40 | '5.6' => false, |
||
41 | '7.0' => true |
||
42 | ), |
||
43 | ), |
||
44 | ); |
||
45 | |||
46 | |||
47 | /** |
||
48 | * If true, an error will be thrown; otherwise a warning. |
||
49 | * |
||
50 | * @var bool |
||
51 | */ |
||
52 | public $error = false; |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | private $newFunctionParametersNames; |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Returns an array of tokens this test wants to listen for. |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | public function register() |
||
80 | |||
81 | /** |
||
82 | * Processes this test, when one of its tokens is encountered. |
||
83 | * |
||
84 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
85 | * @param int $stackPtr The position of the current token in |
||
86 | * the stack passed in $tokens. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
127 | |||
128 | |||
129 | /** |
||
130 | * Generates the error or wanrning for this sniff. |
||
131 | * |
||
132 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
133 | * @param int $stackPtr The position of the function |
||
134 | * in the token array. |
||
135 | * @param string $function The name of the function. |
||
136 | * @param string $pattern The pattern used for the match. |
||
|
|||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | protected function addError($phpcsFile, $stackPtr, $function, $parameterLocation) |
||
165 | |||
166 | }//end class |
||
167 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.