Skip to content

Commit 59f1444

Browse files
committed
Use PHP 8 language contructs
1 parent 6dea54b commit 59f1444

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

MO4/Sniffs/Commenting/PropertyCommentSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
112112
$stackPtr,
113113
'NoDocBlockAllowed'
114114
);
115-
} elseif (0 !== \strncmp($tokens[$postComment]['content'], '//', 2)
116-
&& '*/' !== \substr($tokens[$postComment]['content'], -2)
115+
} elseif (!\str_starts_with($tokens[$postComment]['content'], '//')
116+
&& !\str_ends_with($tokens[$postComment]['content'], '*/')
117117
) {
118118
$phpcsFile->addError(
119119
'no multiline comments after declarations allowed',

MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -336,17 +336,13 @@ private function findNewDestination(File $phpcsFile, int $stackPtr, string $impo
336336
*/
337337
private function compareString(string $a, string $b): int
338338
{
339-
switch ($this->order) {
340-
case 'string':
341-
return \strcmp($a, $b);
342-
case 'string-locale':
343-
return \strcoll($a, $b);
344-
case 'string-case-insensitive':
345-
return \strcasecmp($a, $b);
346-
default:
347-
// Default is 'dictionary'.
348-
return $this->dictionaryCompare($a, $b);
349-
}
339+
return match ($this->order) {
340+
'string' => \strcmp($a, $b),
341+
'string-locale' => \strcoll($a, $b),
342+
'string-case-insensitive' => \strcasecmp($a, $b),
343+
// Default is 'dictionary'.
344+
default => $this->dictionaryCompare($a, $b),
345+
};
350346
}
351347

352348
/**

MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ private function checkShorthandPossible(File $phpcsFile, array $useStatements, s
361361
);
362362

363363
$replaceClassName = true;
364-
} elseif ('' !== $namespace && 0 === \strpos($fullClassName, $namespace)) {
364+
} elseif ('' !== $namespace && \str_starts_with($fullClassName, $namespace)) {
365365
$replacement = \substr($fullClassName, \strlen($namespace));
366366

367367
$data = [

MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function process(File $phpcsFile, $stackPtr): void
8080
}
8181

8282
if (\strpos(\substr($content, 0, $pos), '{') > 0
83-
&& false === \strpos(\substr($content, 0, $pos), '}')
83+
&& !\str_contains(\substr($content, 0, $pos), '}')
8484
) {
8585
continue;
8686
}

0 commit comments

Comments
 (0)