Skip to content

Commit 089fa31

Browse files
committed
4.0 | (Abstract) Sniff classes: add parameter types
1 parent 30b85c1 commit 089fa31

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

src/Sniffs/AbstractArraySniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final public function register()
4040
*
4141
* @return void
4242
*/
43-
public function process(File $phpcsFile, $stackPtr)
43+
public function process(File $phpcsFile, int $stackPtr)
4444
{
4545
$tokens = $phpcsFile->getTokens();
4646

@@ -110,7 +110,7 @@ public function process(File $phpcsFile, $stackPtr)
110110
*
111111
* @return int
112112
*/
113-
private function getNext(File $phpcsFile, $ptr, $arrayEnd)
113+
private function getNext(File $phpcsFile, int $ptr, int $arrayEnd)
114114
{
115115
$tokens = $phpcsFile->getTokens();
116116

@@ -150,7 +150,7 @@ private function getNext(File $phpcsFile, $ptr, $arrayEnd)
150150
*
151151
* @return void
152152
*/
153-
abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
153+
abstract protected function processSingleLineArray(File $phpcsFile, int $stackPtr, int $arrayStart, int $arrayEnd, array $indices);
154154

155155

156156
/**
@@ -166,7 +166,7 @@ abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $array
166166
*
167167
* @return void
168168
*/
169-
abstract protected function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
169+
abstract protected function processMultiLineArray(File $phpcsFile, int $stackPtr, int $arrayStart, int $arrayEnd, array $indices);
170170

171171

172172
}//end class

src/Sniffs/AbstractPatternSniff.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ final public function register()
123123
*
124124
* @return array<int, int>
125125
*/
126-
private function getPatternTokenTypes($pattern)
126+
private function getPatternTokenTypes(array $pattern)
127127
{
128128
$tokenTypes = [];
129129
foreach ($pattern as $pos => $patternInfo) {
@@ -149,7 +149,7 @@ private function getPatternTokenTypes($pattern)
149149
* as the listener.
150150
* @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
151151
*/
152-
private function getListenerTokenPos($pattern)
152+
private function getListenerTokenPos(array $pattern)
153153
{
154154
$tokenTypes = $this->getPatternTokenTypes($pattern);
155155
$tokenCodes = array_keys($tokenTypes);
@@ -178,7 +178,7 @@ private function getListenerTokenPos($pattern)
178178
* @return void
179179
* @see register()
180180
*/
181-
final public function process(File $phpcsFile, $stackPtr)
181+
final public function process(File $phpcsFile, int $stackPtr)
182182
{
183183
$file = $phpcsFile->getFilename();
184184
if ($this->currFile !== $file) {
@@ -246,7 +246,7 @@ final public function process(File $phpcsFile, $stackPtr)
246246
*
247247
* @return array|false
248248
*/
249-
protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
249+
protected function processPattern(array $patternInfo, File $phpcsFile, int $stackPtr)
250250
{
251251
$tokens = $phpcsFile->getTokens();
252252
$pattern = $patternInfo['pattern'];
@@ -697,7 +697,7 @@ protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
697697
*
698698
* @return string The error message.
699699
*/
700-
protected function prepareError($found, $patternCode)
700+
protected function prepareError(string $found, string $patternCode)
701701
{
702702
$found = str_replace("\r\n", '\n', $found);
703703
$found = str_replace("\n", '\n', $found);
@@ -749,7 +749,7 @@ protected function registerSupplementary()
749749
* @return void
750750
* @see registerSupplementary()
751751
*/
752-
protected function processSupplementary(File $phpcsFile, $stackPtr)
752+
protected function processSupplementary(File $phpcsFile, int $stackPtr)
753753
{
754754

755755
}//end processSupplementary()
@@ -764,7 +764,7 @@ protected function processSupplementary(File $phpcsFile, $stackPtr)
764764
* @see createSkipPattern()
765765
* @see createTokenPattern()
766766
*/
767-
private function parse($pattern)
767+
private function parse(string $pattern)
768768
{
769769
$patterns = [];
770770
$length = strlen($pattern);
@@ -855,7 +855,7 @@ private function parse($pattern)
855855
* @see createTokenPattern()
856856
* @see parse()
857857
*/
858-
private function createSkipPattern($pattern, $from)
858+
private function createSkipPattern(string $pattern, int $from)
859859
{
860860
$skip = ['type' => 'skip'];
861861

@@ -908,7 +908,7 @@ private function createSkipPattern($pattern, $from)
908908
* @see createSkipPattern()
909909
* @see parse()
910910
*/
911-
private function createTokenPattern($str)
911+
private function createTokenPattern(string $str)
912912
{
913913
// Pause the StatusWriter to silence Tokenizer debug info about the patterns being parsed (which only confuses things).
914914
StatusWriter::pause();

src/Sniffs/AbstractScopeSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* parent::__construct(array(T_CLASS), array(T_FUNCTION));
1212
* }
1313
*
14-
* protected function processTokenWithinScope(\PHP_CodeSniffer\Files\File $phpcsFile, $stackPtr, $currScope)
14+
* protected function processTokenWithinScope(\PHP_CodeSniffer\Files\File $phpcsFile, int $stackPtr, int $currScope)
1515
* {
1616
* $className = $phpcsFile->getDeclarationName($currScope);
1717
* $phpcsFile->addWarning('encountered a method within class '.$className, $stackPtr, 'MethodFound');
@@ -71,7 +71,7 @@ abstract class AbstractScopeSniff implements Sniff
7171
public function __construct(
7272
array $scopeTokens,
7373
array $tokens,
74-
$listenOutside=false
74+
bool $listenOutside=false
7575
) {
7676
if (empty($scopeTokens) === true) {
7777
$error = 'The scope tokens list cannot be empty';
@@ -127,7 +127,7 @@ final public function register()
127127
* the rest of the file.
128128
* @see processTokenWithinScope()
129129
*/
130-
final public function process(File $phpcsFile, $stackPtr)
130+
final public function process(File $phpcsFile, int $stackPtr)
131131
{
132132
$tokens = $phpcsFile->getTokens();
133133

@@ -167,7 +167,7 @@ final public function process(File $phpcsFile, $stackPtr)
167167
* pointer is reached. Return `$phpcsFile->numTokens` to skip
168168
* the rest of the file.
169169
*/
170-
abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope);
170+
abstract protected function processTokenWithinScope(File $phpcsFile, int $stackPtr, int $currScope);
171171

172172

173173
/**
@@ -183,7 +183,7 @@ abstract protected function processTokenWithinScope(File $phpcsFile, $stackPtr,
183183
* pointer is reached. Return `$phpcsFile->numTokens` to skip
184184
* the rest of the file.
185185
*/
186-
abstract protected function processTokenOutsideScope(File $phpcsFile, $stackPtr);
186+
abstract protected function processTokenOutsideScope(File $phpcsFile, int $stackPtr);
187187

188188

189189
}//end class

src/Sniffs/AbstractVariableSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function __construct()
8484
* pointer is reached. Return `$phpcsFile->numTokens` to skip
8585
* the rest of the file.
8686
*/
87-
final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
87+
final protected function processTokenWithinScope(File $phpcsFile, int $stackPtr, int $currScope)
8888
{
8989
$tokens = $phpcsFile->getTokens();
9090

@@ -162,7 +162,7 @@ final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $cu
162162
* pointer is reached. Return `$phpcsFile->numTokens` to skip
163163
* the rest of the file.
164164
*/
165-
final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
165+
final protected function processTokenOutsideScope(File $phpcsFile, int $stackPtr)
166166
{
167167
$tokens = $phpcsFile->getTokens();
168168
// These variables are not member vars.
@@ -193,7 +193,7 @@ final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
193193
* pointer is reached. Return `$phpcsFile->numTokens` to skip
194194
* the rest of the file.
195195
*/
196-
abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
196+
abstract protected function processMemberVar(File $phpcsFile, int $stackPtr);
197197

198198

199199
/**
@@ -208,7 +208,7 @@ abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
208208
* pointer is reached. Return `$phpcsFile->numTokens` to skip
209209
* the rest of the file.
210210
*/
211-
abstract protected function processVariable(File $phpcsFile, $stackPtr);
211+
abstract protected function processVariable(File $phpcsFile, int $stackPtr);
212212

213213

214214
/**
@@ -227,7 +227,7 @@ abstract protected function processVariable(File $phpcsFile, $stackPtr);
227227
* pointer is reached. Return `$phpcsFile->numTokens` to skip
228228
* the rest of the file.
229229
*/
230-
abstract protected function processVariableInString(File $phpcsFile, $stackPtr);
230+
abstract protected function processVariableInString(File $phpcsFile, int $stackPtr);
231231

232232

233233
}//end class

src/Sniffs/Sniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function register();
7474
* pointer is reached. Return `$phpcsFile->numTokens` to skip
7575
* the rest of the file.
7676
*/
77-
public function process(File $phpcsFile, $stackPtr);
77+
public function process(File $phpcsFile, int $stackPtr);
7878

7979

8080
}//end interface

tests/Core/Sniffs/AbstractArraySniffTestable.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Sniffs;
1111

12+
use PHP_CodeSniffer\Files\File;
1213
use PHP_CodeSniffer\Sniffs\AbstractArraySniff;
1314

1415
class AbstractArraySniffTestable extends AbstractArraySniff
@@ -35,7 +36,7 @@ class AbstractArraySniffTestable extends AbstractArraySniff
3536
*
3637
* @return void
3738
*/
38-
public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices)
39+
public function processSingleLineArray(File $phpcsFile, int $stackPtr, int $arrayStart, int $arrayEnd, array $indices)
3940
{
4041
$this->indicies = $indices;
4142

@@ -55,7 +56,7 @@ public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arra
5556
*
5657
* @return void
5758
*/
58-
public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices)
59+
public function processMultiLineArray(File $phpcsFile, int $stackPtr, int $arrayStart, int $arrayEnd, array $indices)
5960
{
6061
$this->indicies = $indices;
6162

0 commit comments

Comments
 (0)