Skip to content

Commit bf42618

Browse files
authored
Fix up PHP8.1 (#33)
* Fix up PHP 8.1
1 parent 34ff6ed commit bf42618

27 files changed

+188
-168
lines changed

PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) {
4242
*
4343
* @return void
4444
*/
45-
protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex) {
45+
protected function assertNonEmptyDocBlock(File $phpcsFile, int $stackPtr, int $endIndex): void {
4646
$nextIndex = $phpcsFile->findNext([T_WHITESPACE, T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $stackPtr + 1, $endIndex - 1, true);
4747
if ($nextIndex) {
4848
return;
@@ -63,7 +63,7 @@ protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex)
6363
*
6464
* @return void
6565
*/
66-
protected function assertNoEmptyTag(File $phpcsFile, $stackPtr, $endIndex) {
66+
protected function assertNoEmptyTag(File $phpcsFile, int $stackPtr, int $endIndex): void {
6767
$tokens = $phpcsFile->getTokens();
6868

6969
$index = $stackPtr;

PSR2R/Sniffs/Commenting/DocBlockParamSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function process(File $phpCsFile, $stackPointer): void {
134134
*
135135
* @return array
136136
*/
137-
private function getMethodSignature(File $phpCsFile, $stackPtr) {
137+
private function getMethodSignature(File $phpCsFile, int $stackPtr): array {
138138
$tokens = $phpCsFile->getTokens();
139139

140140
$startIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1);

PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function isNonChainable(array $tokens, int $stackPointer): bool {
115115
*
116116
* @return void
117117
*/
118-
protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) {
118+
protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void {
119119
$result = [];
120120
foreach ($parts as $key => $part) {
121121
if ($part !== 'self') {

PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function process(File $phpCsFile, $stackPointer): void {
8282
*
8383
* @return void
8484
*/
85-
protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) {
85+
protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void {
8686
$mapping = [
8787
'boolean' => 'bool',
8888
'integer' => 'int',

PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
1616
/**
1717
* @var array
1818
*/
19-
protected static $whitelistedTags = [
19+
protected static array $whitelistedTags = [
2020
'@api',
2121
'@author',
2222
'@copyright',
@@ -92,7 +92,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
9292
/**
9393
* @var array
9494
*/
95-
protected static $blacklistedTags = [
95+
protected static array $blacklistedTags = [
9696
'@package',
9797
'@subpackage',
9898
'@global',
@@ -105,7 +105,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
105105
/**
106106
* @var array
107107
*/
108-
protected static $mapping = [
108+
protected static array $mapping = [
109109
'@type' => '@var',
110110
'@overwrite' => '@override',
111111
'@inheritdoc' => '@inheritDoc',
@@ -121,7 +121,7 @@ class DocBlockTagTypesSniff extends AbstractSniff {
121121
*
122122
* @var string
123123
*/
124-
public $whitelist = '';
124+
public string $whitelist = '';
125125

126126
/**
127127
* @inheritDoc
@@ -196,7 +196,7 @@ public function process(File $phpcsFile, $stackPtr) {
196196
/**
197197
* @return void
198198
*/
199-
protected function prepareWhitelist() {
199+
protected function prepareWhitelist(): void {
200200
if (!empty($this->whitelist)) {
201201
$whitelist = explode(',', $this->whitelist);
202202
foreach ($whitelist as $tag) {

PSR2R/Sniffs/Commenting/DocCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DocCommentSniff extends AbstractSniff {
3030
*
3131
* @var array
3232
*/
33-
public $supportedTokenizers = [
33+
public array $supportedTokenizers = [
3434
'PHP',
3535
'JS',
3636
];

PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public function process(File $phpCsFile, $stackPointer): void {
105105
/**
106106
* @param \PHP_CodeSniffer\Files\File $phpCsFile
107107
* @param int $index
108-
* @param int $limit
108+
* @param int|null $limit
109109
*
110110
* @return int|null
111111
*/
112-
protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) {
112+
protected function detectRightEnd(File $phpCsFile, int $index, ?int $limit = 0): ?int {
113113
$tokens = $phpCsFile->getTokens();
114114

115115
$rightEndIndex = $index;
@@ -163,12 +163,12 @@ protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) {
163163
* @return void
164164
*/
165165
protected function applyFix(File $phpCsFile,
166-
$index,
167-
$leftIndexStart,
168-
$leftIndexEnd,
169-
$rightIndexStart,
170-
$rightIndexEnd,
171-
) {
166+
int $index,
167+
int $leftIndexStart,
168+
int $leftIndexEnd,
169+
int $rightIndexStart,
170+
int $rightIndexEnd,
171+
): void {
172172
$tokens = $phpCsFile->getTokens();
173173

174174
$token = $tokens[$index];
@@ -200,7 +200,7 @@ protected function applyFix(File $phpCsFile,
200200
*
201201
* @return string
202202
*/
203-
protected function getComparisonValue(array $token) {
203+
protected function getComparisonValue(array $token): string {
204204
$comparisonIndexValue = $token['content'];
205205
$operatorsToMap = [T_GREATER_THAN, T_LESS_THAN, T_IS_GREATER_OR_EQUAL, T_IS_SMALLER_OR_EQUAL];
206206
if (in_array($token['code'], $operatorsToMap, true)) {

PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class ControlStructureSpacingSniff implements Sniff {
3232
/**
3333
* How many spaces should follow the opening bracket.
3434
*
35-
* @var int
3635
*/
37-
public $requiredSpacesAfterOpen = 0;
36+
public int $requiredSpacesAfterOpen = 0;
3837

3938
/**
4039
* @inheritDoc
@@ -57,9 +56,8 @@ public function register(): array {
5756
/**
5857
* How many spaces should precede the closing bracket.
5958
*
60-
* @var int
6159
*/
62-
public $requiredSpacesBeforeClose = 0;
60+
public int $requiredSpacesBeforeClose = 0;
6361

6462
/**
6563
* @inheritDoc

PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function process(File $phpcsFile, $stackPtr) {
3636
/**
3737
* @param \PHP_CodeSniffer\Files\File $phpcsFile
3838
* @param int $stackPtr
39-
*
39+
*
4040
* @return void
4141
*/
42-
protected function checkMethodCalls(File $phpcsFile, $stackPtr) {
42+
protected function checkMethodCalls(File $phpcsFile, int $stackPtr): void {
4343
$tokens = $phpcsFile->getTokens();
4444

4545
$openingBraceIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, $stackPtr + 4);
@@ -63,10 +63,10 @@ protected function checkMethodCalls(File $phpcsFile, $stackPtr) {
6363
/**
6464
* @param \PHP_CodeSniffer\Files\File $phpcsFile
6565
* @param int $stackPtr
66-
*
66+
*
6767
* @return void
6868
*/
69-
protected function checkConditions($phpcsFile, $stackPtr) {
69+
protected function checkConditions(File $phpcsFile, int $stackPtr): void {
7070
$tokens = $phpcsFile->getTokens();
7171

7272
$openingBraceIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
@@ -99,7 +99,7 @@ protected function checkConditions($phpcsFile, $stackPtr) {
9999
*
100100
* @return bool
101101
*/
102-
protected function isFixableInlineAssignment(File $phpcsFile, $startIndex, $endIndex, &$indexEqualSign) {
102+
protected function isFixableInlineAssignment(File $phpcsFile, int $startIndex, int $endIndex, int &$indexEqualSign): bool {
103103
$tokens = $phpcsFile->getTokens();
104104

105105
$hasInlineAssignment = false;

PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public function process(File $phpcsFile, $stackPtr) {
3434
/**
3535
* @param \PHP_CodeSniffer\Files\File $phpcsFile
3636
* @param int $stackPtr
37-
*
37+
*
3838
* @return void
3939
*/
40-
protected function assertSpaceBefore(File $phpcsFile, $stackPtr) {
40+
protected function assertSpaceBefore(File $phpcsFile, int $stackPtr): void {
4141
$previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
4242
if ($stackPtr - $previous > 1) {
4343
$this->assertSingleSpaceBeforeIfNotMultiline($phpcsFile, $stackPtr, $previous);
@@ -58,10 +58,10 @@ protected function assertSpaceBefore(File $phpcsFile, $stackPtr) {
5858
* @param \PHP_CodeSniffer\Files\File $phpcsFile
5959
* @param int $stackPtr
6060
* @param int $previous
61-
*
61+
*
6262
* @return void
6363
*/
64-
protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stackPtr, $previous) {
64+
protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, int $stackPtr, int $previous): void {
6565
$tokens = $phpcsFile->getTokens();
6666

6767
if ($tokens[$stackPtr]['line'] !== $tokens[$previous]['line']) {
@@ -81,10 +81,10 @@ protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stack
8181
/**
8282
* @param \PHP_CodeSniffer\Files\File $phpcsFile
8383
* @param int $thenIndex
84-
*
84+
*
8585
* @return void
8686
*/
87-
protected function checkAfter(File $phpcsFile, $thenIndex) {
87+
protected function checkAfter(File $phpcsFile, int $thenIndex): void {
8888
$elseIndex = $phpcsFile->findNext(T_INLINE_ELSE, $thenIndex + 1);
8989
if (!$elseIndex) {
9090
return;
@@ -106,10 +106,10 @@ protected function checkAfter(File $phpcsFile, $thenIndex) {
106106
* @param \PHP_CodeSniffer\Files\File $phpcsFile
107107
* @param int $thenIndex
108108
* @param int $elseIndex
109-
*
109+
*
110110
* @return void
111111
*/
112-
protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex) {
112+
protected function assertNoSpaceBetween(File $phpcsFile, int $thenIndex, int $elseIndex): void {
113113
if ($elseIndex - $thenIndex === 1) {
114114
return;
115115
}
@@ -128,10 +128,10 @@ protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex)
128128
/**
129129
* @param \PHP_CodeSniffer\Files\File $phpcsFile
130130
* @param int $stackPtr
131-
*
131+
*
132132
* @return void
133133
*/
134-
protected function assertSpaceAfter(File $phpcsFile, $stackPtr) {
134+
protected function assertSpaceAfter(File $phpcsFile, int $stackPtr): void {
135135
$nextIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
136136
if ($nextIndex - $stackPtr > 1) {
137137
$this->assertSingleSpaceAfterIfNotMultiline($phpcsFile, $stackPtr, $nextIndex);
@@ -152,10 +152,10 @@ protected function assertSpaceAfter(File $phpcsFile, $stackPtr) {
152152
* @param \PHP_CodeSniffer\Files\File $phpcsFile
153153
* @param int $stackPtr
154154
* @param int $next
155-
*
155+
*
156156
* @return void
157157
*/
158-
protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, $stackPtr, $next) {
158+
protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, int $stackPtr, int $next): void {
159159
$tokens = $phpcsFile->getTokens();
160160

161161
if ($tokens[$stackPtr]['line'] !== $tokens[$next]['line']) {

0 commit comments

Comments
 (0)