1 | <?php |
||
28 | class NegativeStringOffsetSniff extends AbstractFunctionCallParameterSniff |
||
29 | { |
||
30 | |||
31 | /** |
||
32 | * Functions to check for. |
||
33 | * |
||
34 | * @var array Function name => 1-based parameter offset of the affected parameters => parameter name. |
||
35 | */ |
||
36 | protected $targetFunctions = array( |
||
37 | 'file_get_contents' => array( |
||
38 | 4 => 'offset', |
||
39 | ), |
||
40 | 'grapheme_extract' => array( |
||
41 | 4 => 'start', |
||
42 | ), |
||
43 | 'grapheme_stripos' => array( |
||
44 | 3 => 'offset', |
||
45 | ), |
||
46 | 'grapheme_strpos' => array( |
||
47 | 3 => 'offset', |
||
48 | ), |
||
49 | 'iconv_strpos' => array( |
||
50 | 3 => 'offset', |
||
51 | ), |
||
52 | 'mb_ereg_search_setpos' => array( |
||
53 | 1 => 'position', |
||
54 | ), |
||
55 | 'mb_strimwidth' => array( |
||
56 | 2 => 'start', |
||
57 | 3 => 'width', |
||
58 | ), |
||
59 | 'mb_stripos' => array( |
||
60 | 3 => 'offset', |
||
61 | ), |
||
62 | 'mb_strpos' => array( |
||
63 | 3 => 'offset', |
||
64 | ), |
||
65 | 'stripos' => array( |
||
66 | 3 => 'offset', |
||
67 | ), |
||
68 | 'strpos' => array( |
||
69 | 3 => 'offset', |
||
70 | ), |
||
71 | 'substr_count' => array( |
||
72 | 3 => 'offset', |
||
73 | 4 => 'length', |
||
74 | ), |
||
75 | ); |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Do a version check to determine if this sniff needs to run at all. |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | protected function bowOutEarly() |
||
87 | |||
88 | /** |
||
89 | * Process the parameters of a matched function. |
||
90 | * |
||
91 | * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
92 | * @param int $stackPtr The position of the current token in the stack. |
||
93 | * @param string $functionName The token content (function name) which was matched. |
||
94 | * @param array $parameters Array with information about the parameters. |
||
95 | * |
||
96 | * @return int|void Integer stack pointer to skip forward or void to continue |
||
97 | * normal file processing. |
||
98 | */ |
||
99 | public function processParameters(\PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionName, $parameters) |
||
125 | }//end class |
||
126 |