Skip to content

Commit 10c0968

Browse files
Apply the new rules to the current code
There will be a lot of fun.
1 parent 45b6888 commit 10c0968

25 files changed

+159
-154
lines changed

Inpsyde/Helpers/Boundaries.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function functionBoundaries(File $file, int $position): array
4646
$tokens = $file->getTokens();
4747

4848
if (
49-
!in_array(
49+
! in_array(
5050
$tokens[$position]['code'] ?? null,
5151
array_keys(Collections::functionDeclarationTokens()),
5252
true
@@ -68,7 +68,7 @@ public static function objectBoundaries(File $file, int $position): array
6868
/** @var array<int, array<string, mixed>> $tokens */
6969
$tokens = $file->getTokens();
7070

71-
if (!in_array(($tokens[$position]['code'] ?? null), Tokens::$ooScopeTokens, true)) {
71+
if (! in_array(($tokens[$position]['code'] ?? null), Tokens::$ooScopeTokens, true)) {
7272
return [-1, -1];
7373
}
7474

@@ -84,14 +84,14 @@ public static function arrayBoundaries(File $file, int $position): array
8484
{
8585
$openClose = Arrays::getOpenClose($file, $position);
8686
if (
87-
!is_array($openClose)
88-
|| !is_int($openClose['opener'] ?? null)
89-
|| !is_int($openClose['closer'] ?? null)
87+
! is_array($openClose)
88+
|| ! is_int($openClose['opener'] ?? null)
89+
|| ! is_int($openClose['closer'] ?? null)
9090
) {
9191
return [-1, -1];
9292
}
9393

94-
return [(int)$openClose['opener'], (int)$openClose['closer']];
94+
return [(int) $openClose['opener'], (int) $openClose['closer']];
9595
}
9696

9797
/**
@@ -105,15 +105,15 @@ private static function startEnd(File $file, int $position): array
105105
$token = $file->getTokens()[$position] ?? [];
106106
if (($token['code'] ?? '') === T_FN) {
107107
$start = $file->findNext(T_FN_ARROW, $position + 1, null, false, null, true);
108-
if (!$start) {
108+
if (! $start) {
109109
return [-1, -1];
110110
}
111111

112112
return [$start + 1, $file->findEndOfStatement($start)];
113113
}
114114

115-
$start = (int)($token['scope_opener'] ?? 0);
116-
$end = (int)($token['scope_closer'] ?? 0);
115+
$start = (int) ($token['scope_opener'] ?? 0);
116+
$end = (int) ($token['scope_closer'] ?? 0);
117117
if (($start <= 0) || ($end <= 0) || ($start >= ($end - 1))) {
118118
return [-1, -1];
119119
}

Inpsyde/Helpers/FunctionDocBlock.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,28 @@ public static function allTags(
5353
$tokens = $file->getTokens();
5454

5555
if (
56-
!array_key_exists($position, $tokens)
57-
|| !in_array($tokens[$position]['code'], [T_FUNCTION, T_CLOSURE, T_FN], true)
56+
! array_key_exists($position, $tokens)
57+
|| ! in_array($tokens[$position]['code'], [T_FUNCTION, T_CLOSURE, T_FN], true)
5858
) {
5959
return [];
6060
}
6161

6262
$closeType = T_DOC_COMMENT_CLOSE_TAG;
6363
$closeTag = $file->findPrevious($closeType, $position - 1, null, false, null, true);
6464

65-
if (!$closeTag || empty($tokens[$closeTag]['comment_opener'])) {
65+
if (! $closeTag || empty($tokens[$closeTag]['comment_opener'])) {
6666
return [];
6767
}
6868

69-
$functionLine = (int)($tokens[$position]['line'] ?? -1);
70-
$closeLine = (int)($tokens[$closeTag]['line'] ?? -1);
69+
$functionLine = (int) ($tokens[$position]['line'] ?? -1);
70+
$closeLine = (int) ($tokens[$closeTag]['line'] ?? -1);
7171
if ($closeLine !== ($functionLine - 1)) {
7272
return [];
7373
}
7474

7575
/** @var array<int, array{string, string}> $tags */
7676
$tags = [];
77-
$start = (int)$tokens[$closeTag]['comment_opener'] + 1;
77+
$start = (int) $tokens[$closeTag]['comment_opener'] + 1;
7878
$key = -1;
7979
$inTag = false;
8080

@@ -84,7 +84,7 @@ public static function allTags(
8484
continue;
8585
}
8686

87-
$content = (string)$tokens[$i]['content'];
87+
$content = (string) $tokens[$i]['content'];
8888
if (($tokens[$i]['code'] === T_DOC_COMMENT_TAG)) {
8989
$inTag = true;
9090
$key++;
@@ -102,7 +102,7 @@ public static function allTags(
102102
$rand or $rand = bin2hex(random_bytes(3));
103103
foreach ($tags as [$tagName, $tagContent]) {
104104
empty($normalizedTags[$tagName]) and $normalizedTags[$tagName] = [];
105-
if (!$normalizeContent) {
105+
if (! $normalizeContent) {
106106
$normalizedTags[$tagName][] = $tagContent;
107107
continue;
108108
}
@@ -140,7 +140,7 @@ public static function tag(string $tag, File $file, int $position): array
140140
public static function allParamTypes(File $file, int $functionPosition): array
141141
{
142142
$params = static::tag('@param', $file, $functionPosition);
143-
if (!$params) {
143+
if (! $params) {
144144
return [];
145145
}
146146

@@ -173,7 +173,7 @@ public static function normalizeTypesString(string $typesString): array
173173
$splitType = substr($splitType, 1) ?: '';
174174
$hasNull = $hasNull || ($splitType !== '');
175175
}
176-
if (!$splitType) {
176+
if (! $splitType) {
177177
continue;
178178
}
179179
if (strtolower($splitType) === 'null') {

Inpsyde/Helpers/FunctionReturnStatement.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public static function allInfo(File $file, int $position): array
7676
if ($tokens[$pos]['code'] === T_RETURN) {
7777
$returnCount['total']++;
7878
$void = static::isVoid($file, $pos);
79-
$null = !$void && static::isNull($file, $pos);
79+
$null = ! $void && static::isNull($file, $pos);
8080
$void and $returnCount['void']++;
8181
$null and $returnCount['null']++;
82-
(!$void && !$null) and $returnCount['nonEmpty']++;
82+
(! $void && ! $null) and $returnCount['nonEmpty']++;
8383
}
8484

8585
$pos++;
@@ -127,7 +127,7 @@ public static function isNull(File $file, int $position): bool
127127

128128
if ($code === T_FN) {
129129
$position = $file->findNext(T_FN_ARROW, $position + 1, null, false, null, true);
130-
if (!$position) {
130+
if (! $position) {
131131
return false;
132132
}
133133
}

Inpsyde/Helpers/Functions.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public static function looksLikeFunctionCall(File $file, int $position): bool
5252
$types[] = T_VARIABLE;
5353

5454
if (
55-
!in_array($code, $types, true)
55+
! in_array($code, $types, true)
5656
|| (($code === T_VARIABLE) && Scopes::isOOProperty($file, $position))
5757
) {
5858
return false;
5959
}
6060

6161
$callOpen = $file->findNext(Tokens::$emptyTokens, $position + 1, null, true, null, true);
62-
if (!$callOpen || $tokens[$callOpen]['code'] !== T_OPEN_PARENTHESIS) {
62+
if (! $callOpen || $tokens[$callOpen]['code'] !== T_OPEN_PARENTHESIS) {
6363
return false;
6464
}
6565

@@ -158,7 +158,7 @@ public static function countYieldInBody(File $file, int $position): int
158158
*/
159159
public static function isPsrMethod(File $file, int $position): bool
160160
{
161-
if (!Scopes::isOOMethod($file, $position)) {
161+
if (! Scopes::isOOMethod($file, $position)) {
162162
return false;
163163
}
164164

@@ -167,7 +167,7 @@ public static function isPsrMethod(File $file, int $position): bool
167167

168168
$classPos = Conditions::getLastCondition($file, $position, $scopes);
169169
$type = is_int($classPos) ? ($tokens[$classPos]['code'] ?? null) : null;
170-
if (!in_array($type, $scopes, true)) {
170+
if (! in_array($type, $scopes, true)) {
171171
return false;
172172
}
173173

@@ -209,7 +209,7 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return
209209
// If "never" is there, this is valid for return types and PHP < 8.1,
210210
// not valid for argument types.
211211
if (in_array('never', $docTypes, true)) {
212-
return $return && !$is81;
212+
return $return && ! $is81;
213213
}
214214

215215
if ($count > 1) {
@@ -219,8 +219,8 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return
219219
}
220220
// Union type without null, valid if we're not on PHP < 8.0, or on PHP < 8.2 and
221221
// there's an intersection (DNF)
222-
if (!in_array('null', $docTypes, true)) {
223-
return !$is80 || (!$is82 && $isIntersection);
222+
if (! in_array('null', $docTypes, true)) {
223+
return ! $is80 || (! $is82 && $isIntersection);
224224
}
225225
$docTypes = array_diff($docTypes, ['null']);
226226
$count = count($docTypes);
@@ -229,16 +229,16 @@ public static function isNonDeclarableDocBlockType(array $docTypes, bool $return
229229
// Union type with "null" plus something else, valid if we're not on PHP < 8.0 or
230230
// on PHP < 8.2 and there's an intersection (DNF)
231231
if ($count > 1) {
232-
return !$is80 || (!$is82 && $isIntersection);
232+
return ! $is80 || (! $is82 && $isIntersection);
233233
}
234234

235235
$singleDocType = reset($docTypes);
236236

237237
// If the single type is "mixed" is valid if we are on PHP < 8.0.
238238
// If the single type is "null" is valid if we are on PHP < 8.2.
239239
// If the single is an intersection, is valid if we are on PHP < 8.1
240-
return (($singleDocType === 'mixed') && !$is80)
241-
|| (($singleDocType === 'null') && !$is82)
242-
|| ($isIntersection && !$is81);
240+
return (($singleDocType === 'mixed') && ! $is80)
241+
|| (($singleDocType === 'null') && ! $is82)
242+
|| ($isIntersection && ! $is81);
243243
}
244244
}

Inpsyde/Helpers/Misc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ final class Misc
4343
public static function minPhpTestVersion(): string
4444
{
4545
$testVersion = trim(Config::getConfigData('testVersion') ?: '');
46-
if (!$testVersion) {
46+
if (! $testVersion) {
4747
return self::MIN_SUPPORTED_VERSION;
4848
}
4949

@@ -107,8 +107,8 @@ public static function filterTokensByType(
107107
continue;
108108
}
109109
$empty = $types === [];
110-
$inArray = !$empty && in_array($token['code'] ?? '', $types, true);
111-
if ($empty || (!$excludeTypes && $inArray) || ($excludeTypes && !$inArray)) {
110+
$inArray = ! $empty && in_array($token['code'] ?? '', $types, true);
111+
if ($empty || (! $excludeTypes && $inArray) || ($excludeTypes && ! $inArray)) {
112112
$filtered[$i] = $token;
113113
}
114114
}
@@ -136,7 +136,7 @@ public static function tokensSubsetToString(
136136

137137
$content = '';
138138
foreach ($filtered as $token) {
139-
$content .= (string)($token['content'] ?? '');
139+
$content .= (string) ($token['content'] ?? '');
140140
}
141141

142142
return $content;

Inpsyde/Helpers/Names.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public static function nameableTokenName(File $file, int $position): ?string
6262
$tokens = $file->getTokens();
6363
$code = $tokens[$position]['code'] ?? null;
6464

65-
if (!in_array($code, self::NAMEABLE_TOKENS, true)) {
65+
if (! in_array($code, self::NAMEABLE_TOKENS, true)) {
6666
return null;
6767
}
6868

6969
if ($code === T_VARIABLE) {
70-
$name = ltrim((string)($tokens[$position]['content'] ?? ''), '$');
70+
$name = ltrim((string) ($tokens[$position]['content'] ?? ''), '$');
7171

7272
return ($name === '') ? null : $name;
7373
}
@@ -79,7 +79,7 @@ public static function nameableTokenName(File $file, int $position): ?string
7979
}
8080

8181
$namePosition = $file->findNext(T_STRING, $position, null, false, null, true);
82-
$name = ($namePosition === false) ? null : (string)$tokens[$namePosition]['content'];
82+
$name = ($namePosition === false) ? null : (string) $tokens[$namePosition]['content'];
8383

8484
return ($name === '') ? null : $name;
8585
}

Inpsyde/Helpers/Objects.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function countProperties(File $file, int $position): int
4747
/** @var array<int, array<string, mixed>> $tokens */
4848
$tokens = $file->getTokens();
4949
if (
50-
!in_array(
50+
! in_array(
5151
$tokens[$position]['code'] ?? null,
5252
Collections::ooPropertyScopes(),
5353
true
@@ -100,16 +100,16 @@ public static function findAllImportUses(File $file, int $position): array
100100

101101
while (true) {
102102
$nextUse = $file->findNext(T_USE, $nextUse + 1, $position - 1);
103-
if (!$nextUse) {
103+
if (! $nextUse) {
104104
break;
105105
}
106-
if (!UseStatements::isImportUse($file, $nextUse)) {
106+
if (! UseStatements::isImportUse($file, $nextUse)) {
107107
continue;
108108
}
109109
$usePositions[] = $nextUse;
110110
}
111111

112-
if (!$usePositions) {
112+
if (! $usePositions) {
113113
return [];
114114
}
115115

@@ -148,12 +148,12 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio
148148
{
149149
$tokens = $file->getTokens();
150150
$code = $tokens[$position]['code'] ?? null;
151-
if (!in_array($code, Collections::ooCanImplement(), true)) {
151+
if (! in_array($code, Collections::ooCanImplement(), true)) {
152152
return null;
153153
}
154154

155155
$implementsPos = $file->findNext(T_IMPLEMENTS, $position, null, false, null, true);
156-
if (!$implementsPos) {
156+
if (! $implementsPos) {
157157
return null;
158158
}
159159

@@ -166,14 +166,14 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio
166166
true
167167
);
168168

169-
if (!$namesEnd) {
169+
if (! $namesEnd) {
170170
return null;
171171
}
172172

173173
$uses = static::findAllImportUses($file, $position - 1);
174174
/** @var non-empty-list<string>|false $names */
175175
$names = ObjectDeclarations::findImplementedInterfaceNames($file, $position);
176-
if (!$names) {
176+
if (! $names) {
177177
return [];
178178
}
179179

Inpsyde/Helpers/WpHooks.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function isHookClosure(
4949
/** @var array<int, array<string, mixed>> $tokens */
5050
$tokens = $file->getTokens();
5151

52-
if (!in_array(($tokens[$position]['code'] ?? ''), [T_CLOSURE, T_FN], true)) {
52+
if (! in_array(($tokens[$position]['code'] ?? ''), [T_CLOSURE, T_FN], true)) {
5353
return false;
5454
}
5555

@@ -58,18 +58,18 @@ public static function isHookClosure(
5858
$exclude = $empty;
5959
$exclude[] = T_STATIC;
6060
$commaPos = $file->findPrevious($exclude, $position - 1, null, true, null, true);
61-
if (!$commaPos || ($tokens[$commaPos]['code'] ?? '') !== T_COMMA) {
61+
if (! $commaPos || ($tokens[$commaPos]['code'] ?? '') !== T_COMMA) {
6262
return false;
6363
}
6464

6565
$openType = [T_OPEN_PARENTHESIS];
6666
$openCallPos = $file->findPrevious($openType, $commaPos - 2, null, false, null, true);
67-
if (!$openCallPos) {
67+
if (! $openCallPos) {
6868
return false;
6969
}
7070

7171
$functionCallPos = $file->findPrevious($empty, $openCallPos - 1, null, true, null, true);
72-
if (!$functionCallPos || $tokens[$functionCallPos]['code'] !== T_STRING) {
72+
if (! $functionCallPos || $tokens[$functionCallPos]['code'] !== T_STRING) {
7373
return false;
7474
}
7575

@@ -87,6 +87,6 @@ public static function isHookClosure(
8787
*/
8888
public static function isHookFunction(File $file, int $position): bool
8989
{
90-
return (bool)FunctionDocBlock::tag('@wp-hook', $file, $position);
90+
return (bool) FunctionDocBlock::tag('@wp-hook', $file, $position);
9191
}
9292
}

Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public function process(File $phpcsFile, $stackPtr): void
8080
}
8181

8282
$docTypes = $docBlockTypes[$parameter['name']] ?? [];
83-
if (!Functions::isNonDeclarableDocBlockType($docTypes, false)) {
83+
if (! Functions::isNonDeclarableDocBlockType($docTypes, false)) {
8484
$errors[] = $parameter['name'];
8585
}
8686
}
8787

88-
if (!$errors) {
88+
if (! $errors) {
8989
return;
9090
}
9191

0 commit comments

Comments
 (0)