Skip to content

Commit 2a0ee12

Browse files
committed
Merge branch 'template-semicolon-sniff' into version/2
# Conflicts: # Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php # Inpsyde/Sniffs/CodeQuality/LineLengthSniff.php # Inpsyde/Sniffs/CodeQuality/NestingLevelSniff.php # Inpsyde/Sniffs/CodeQuality/VariablesNameSniff.php
2 parents d56e53f + cd931e0 commit 2a0ee12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+292
-88
lines changed

Inpsyde/Helpers/Boundaries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ 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 === false) {
109109
return [-1, -1];
110110
}
111111

Inpsyde/Helpers/FunctionDocBlock.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function allTags(
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 === false) || !isset($tokens[$closeTag]['comment_opener'])) {
6666
return [];
6767
}
6868

@@ -101,7 +101,7 @@ public static function allTags(
101101
static $rand;
102102
$rand or $rand = bin2hex(random_bytes(3));
103103
foreach ($tags as [$tagName, $tagContent]) {
104-
empty($normalizedTags[$tagName]) and $normalizedTags[$tagName] = [];
104+
isset($normalizedTags[$tagName]) or $normalizedTags[$tagName] = [];
105105
if (!$normalizeContent) {
106106
$normalizedTags[$tagName][] = $tagContent;
107107
continue;
@@ -147,7 +147,7 @@ public static function allParamTypes(File $file, int $functionPosition): array
147147
$types = [];
148148
foreach ($params as $param) {
149149
preg_match('~^([^$]+)\s*(\$\S+)~', trim($param), $matches);
150-
if (($matches[1] ?? null) && ($matches[2] ?? null)) {
150+
if (isset($matches[1]) && isset($matches[2])) {
151151
$types[$matches[2]] = static::normalizeTypesString($matches[1]);
152152
}
153153
}
@@ -170,10 +170,10 @@ public static function normalizeTypesString(string $typesString): array
170170
if (strpos($splitType, '&') !== false) {
171171
$splitType = rtrim(ltrim($splitType, '('), ')');
172172
} elseif (strpos($splitType, '?') === 0) {
173-
$splitType = substr($splitType, 1) ?: '';
173+
$splitType = (string) 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 === false) {
131131
return false;
132132
}
133133
}

Inpsyde/Helpers/Functions.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,33 @@ public static function looksLikeFunctionCall(File $file, int $position): bool
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 === false) || $tokens[$callOpen]['code'] !== T_OPEN_PARENTHESIS) {
6363
return false;
6464
}
6565

6666
$prevExclude = Tokens::$emptyTokens;
6767
$prevMeaningful = $file->findPrevious($prevExclude, $position - 1, null, true, null, true);
6868

69-
if ($prevMeaningful && ($tokens[$prevMeaningful]['code'] ?? -1) === T_NS_SEPARATOR) {
69+
if (
70+
($prevMeaningful !== false)
71+
&& ($tokens[$prevMeaningful]['code'] ?? -1) === T_NS_SEPARATOR
72+
) {
7073
$prevExclude = array_merge($prevExclude, [T_STRING, T_NS_SEPARATOR]);
7174
$prevStart = $prevMeaningful - 1;
7275
$prevMeaningful = $file->findPrevious($prevExclude, $prevStart, null, true, null, true);
7376
}
7477

75-
$prevMeaningfulCode = $prevMeaningful ? $tokens[$prevMeaningful]['code'] : null;
76-
if ($prevMeaningfulCode && in_array($prevMeaningfulCode, [T_NEW, T_FUNCTION], true)) {
78+
$prevMeaningfulCode = ($prevMeaningful !== false)
79+
? $tokens[$prevMeaningful]['code']
80+
: null;
81+
if (in_array($prevMeaningfulCode, [T_NEW, T_FUNCTION], true)) {
7782
return false;
7883
}
7984

8085
$callClose = $file->findNext([T_CLOSE_PARENTHESIS], $callOpen + 1, null, false, null, true);
8186
$expectedCallClose = $tokens[$callOpen]['parenthesis_closer'] ?? -1;
8287

83-
return $callClose && ($callClose === $expectedCallClose);
88+
return ($callClose !== false) && ($callClose === $expectedCallClose);
8489
}
8590

8691
/**

Inpsyde/Helpers/Misc.php

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

Inpsyde/Helpers/Names.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ public static function nameableTokenName(File $file, int $position): ?string
7373
}
7474

7575
if ($code === T_NAMESPACE) {
76-
return Namespaces::isDeclaration($file, $position)
77-
? (Namespaces::getDeclaredName($file, $position) ?: '')
78-
: null;
76+
if (!Namespaces::isDeclaration($file, $position)) {
77+
return null;
78+
}
79+
$declaredName = Namespaces::getDeclaredName($file, $position);
80+
81+
return ($declaredName !== '' && is_string($declaredName)) ? $declaredName : null;
7982
}
8083

8184
$namePosition = $file->findNext(T_STRING, $position, null, false, null, true);

Inpsyde/Helpers/Objects.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ public static function findAllImportUses(File $file, int $position): array
9696
{
9797
// phpcs:enable Generic.Metrics.CyclomaticComplexity
9898
$usePositions = [];
99-
$nextUse = $file->findPrevious(T_NAMESPACE, $position - 1) ?: 0;
99+
$nextUse = $file->findPrevious(T_NAMESPACE, $position - 1);
100+
($nextUse === false) and $nextUse = 0;
100101

101102
while (true) {
102103
$nextUse = $file->findNext(T_USE, $nextUse + 1, $position - 1);
103-
if (!$nextUse) {
104+
if ($nextUse === false) {
104105
break;
105106
}
106107
if (!UseStatements::isImportUse($file, $nextUse)) {
@@ -121,14 +122,14 @@ public static function findAllImportUses(File $file, int $position): array
121122
$asPos = $file->findNext(T_AS, $usePosition + 1, $end, false, null, true);
122123
$useName = Misc::tokensSubsetToString(
123124
$usePosition + 1,
124-
($asPos ?: $end) - 1,
125+
(($asPos !== false) ? $asPos : $end) - 1,
125126
$file,
126127
[T_STRING, T_NS_SEPARATOR]
127128
);
128129
$useName = trim($useName, '\\');
129130
$useNameParts = explode('\\', $useName);
130131
$key = end($useNameParts);
131-
if ($asPos) {
132+
if ($asPos !== false) {
132133
$keyPos = $file->findNext(T_STRING, $asPos + 1, null, false, null, true);
133134
/** @var string $key */
134135
$key = $tokens[$keyPos]['content'] ?? '';
@@ -153,7 +154,7 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio
153154
}
154155

155156
$implementsPos = $file->findNext(T_IMPLEMENTS, $position, null, false, null, true);
156-
if (!$implementsPos) {
157+
if ($implementsPos === false) {
157158
return null;
158159
}
159160

@@ -166,7 +167,7 @@ public static function allInterfacesFullyQualifiedNames(File $file, int $positio
166167
true
167168
);
168169

169-
if (!$namesEnd) {
170+
if ($namesEnd === false) {
170171
return null;
171172
}
172173

Inpsyde/Helpers/WpHooks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 === false) || ($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 === false) {
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 === false) || $tokens[$functionCallPos]['code'] !== T_STRING) {
7373
return false;
7474
}
7575

Inpsyde/Sniffs/CodeQuality/ArgumentTypeDeclarationSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function process(File $phpcsFile, $stackPtr): void
7575

7676
$errors = [];
7777
foreach ($parameters as $parameter) {
78-
if ($parameter['type_hint'] ?? null) {
78+
$typeHint = $parameter['type_hint'] ?? '';
79+
if (($typeHint !== '') && ($typeHint !== false)) {
7980
continue;
8081
}
8182

Inpsyde/Sniffs/CodeQuality/FunctionBodyStartSniff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function process(File $phpcsFile, $stackPtr): void
6666

6767
$bodyStart = $phpcsFile->findNext([T_WHITESPACE], $scopeOpener + 1, null, true);
6868
if (
69-
!$bodyStart
69+
($bodyStart === false)
7070
|| !array_key_exists($bodyStart, $tokens)
7171
|| $bodyStart <= $scopeOpener
7272
|| $bodyStart >= $scopeCloser
@@ -82,9 +82,9 @@ public function process(File $phpcsFile, $stackPtr): void
8282
);
8383

8484
if (
85-
$code
86-
&& $message
87-
&& $expectedLine
85+
(($code !== null) && ($code !== ''))
86+
&& (($message !== null) && ($message !== ''))
87+
&& ($expectedLine !== null)
8888
&& $phpcsFile->addFixableWarning($message, $stackPtr, $code)
8989
) {
9090
$this->fix($bodyStart, $expectedLine, $scopeOpener, $phpcsFile);

0 commit comments

Comments
 (0)