Skip to content

Commit 39b264f

Browse files
committed
Use PHP 8 language contructs
1 parent 5c416ec commit 39b264f

4 files changed

+11
-15
lines changed

MO4/Sniffs/Commenting/PropertyCommentSniff.php

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

MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php

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

351347
/**

MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private function checkShorthandPossible(File $phpcsFile, array $useStatements, s
359359
);
360360

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

365365
$data = [

MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function process(File $phpcsFile, $stackPtr): void
7878
}
7979

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

0 commit comments

Comments
 (0)