Skip to content

Commit

Permalink
Use PHP 8 language contructs
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoll committed Jan 26, 2025
1 parent 5c416ec commit 39b264f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions MO4/Sniffs/Commenting/PropertyCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
$stackPtr,
'NoDocBlockAllowed'
);
} elseif (0 !== \strncmp($tokens[$postComment]['content'], '//', 2)
&& '*/' !== \substr($tokens[$postComment]['content'], -2)
} elseif (!\str_starts_with($tokens[$postComment]['content'], '//')
&& !\str_ends_with($tokens[$postComment]['content'], '*/')
) {
$phpcsFile->addError(
'no multiline comments after declarations allowed',
Expand Down
18 changes: 7 additions & 11 deletions MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,13 @@ private function findNewDestination(File $phpcsFile, int $stackPtr, string $impo
*/
private function compareString(string $a, string $b): int
{
switch ($this->order) {
case 'string':
return \strcmp($a, $b);
case 'string-locale':
return \strcoll($a, $b);
case 'string-case-insensitive':
return \strcasecmp($a, $b);
default:
// Default is 'dictionary'.
return $this->dictionaryCompare($a, $b);
}
return match ($this->order) {
'string' => \strcmp($a, $b),
'string-locale' => \strcoll($a, $b),
'string-case-insensitive' => \strcasecmp($a, $b),
// Default is 'dictionary'.
default => $this->dictionaryCompare($a, $b),
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ private function checkShorthandPossible(File $phpcsFile, array $useStatements, s
);

$replaceClassName = true;
} elseif ('' !== $namespace && 0 === \strpos($fullClassName, $namespace)) {
} elseif ('' !== $namespace && \str_starts_with($fullClassName, $namespace)) {
$replacement = \substr($fullClassName, \strlen($namespace));

$data = [
Expand Down
2 changes: 1 addition & 1 deletion MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function process(File $phpcsFile, $stackPtr): void
}

if (\strpos(\substr($content, 0, $pos), '{') > 0
&& false === \strpos(\substr($content, 0, $pos), '}')
&& !\str_contains(\substr($content, 0, $pos), '}')
) {
continue;
}
Expand Down

0 comments on commit 39b264f

Please sign in to comment.