From 9e014e4ac5099674bc6fe5fbd85fe41ab8f9a1a0 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Mon, 16 Dec 2024 21:31:32 +0100 Subject: [PATCH 1/6] Update psalm to 6.x and minimum PHP to 8.1 --- .github/workflows/ci.yml | 7 ++----- .phan/config.php | 1 + MO4/Library/PregLibrary.php | 2 +- .../Arrays/ArrayDoubleArrowAlignmentSniff.php | 4 ++++ MO4/Sniffs/Arrays/MultiLineArraySniff.php | 4 ++++ MO4/Sniffs/Commenting/PropertyCommentSniff.php | 4 ++++ .../Formatting/AlphabeticalUseStatementsSniff.php | 6 +++++- .../Formatting/UnnecessaryNamespaceUsageSniff.php | 5 +++++ .../Strings/VariableInDoubleQuotedStringSniff.php | 4 ++++ MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php | 4 ++++ MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php | 5 +++++ MO4/Tests/AbstractMo4SniffUnitTest.php | 2 ++ .../Arrays/ArrayDoubleArrowAlignmentUnitTest.php | 2 +- MO4/Tests/Arrays/MultiLineArrayUnitTest.php | 2 +- MO4/Tests/Commenting/PropertyCommentUnitTest.php | 2 +- .../AlphabeticalUseStatementsUnitTest.php | 2 +- .../UnnecessaryNamespaceUsageUnitTest.php | 2 +- .../VariableInDoubleQuotedStringUnitTest.php | 2 +- MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php | 2 +- .../WhiteSpace/MultipleEmptyLinesUnitTest.php | 2 +- composer.json | 14 +++++++++----- 21 files changed, 58 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b560af9d..943c6fff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,13 +40,10 @@ jobs: matrix: os: [ubuntu-latest] php_version: - - 7.2 - - 7.3 - - 7.4 - - 8.0 - 8.1 - 8.2 - 8.3 + - 8.4 dependencies_level: - --prefer-lowest - "" @@ -90,7 +87,7 @@ jobs: run: vendor/bin/phpstan analyse --no-progress - name: Run psalm if: ${{ matrix.os != 'windows-latest' }} - run: vendor/bin/psalm --show-info=true + run: vendor/bin/psalm - name: Run phan if: ${{ matrix.os != 'windows-latest' }} run: vendor/bin/phan diff --git a/.phan/config.php b/.phan/config.php index 698ecb8c..48d2cfc5 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -23,6 +23,7 @@ 'MO4', 'tests', 'vendor/squizlabs/php_codesniffer', + 'vendor/symfony/polyfill-php83', ], // A directory list that defines files that will be excluded diff --git a/MO4/Library/PregLibrary.php b/MO4/Library/PregLibrary.php index b694108a..e32445eb 100644 --- a/MO4/Library/PregLibrary.php +++ b/MO4/Library/PregLibrary.php @@ -16,7 +16,7 @@ use PHP_CodeSniffer\Exceptions\RuntimeException; -class PregLibrary +final class PregLibrary { /** * Split string by a regular expression diff --git a/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php b/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php index 839d6e04..dd0ea4a3 100644 --- a/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php +++ b/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php @@ -30,6 +30,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class ArrayDoubleArrowAlignmentSniff implements Sniff { @@ -51,6 +53,7 @@ class ArrayDoubleArrowAlignmentSniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return $this->arrayTokens; @@ -67,6 +70,7 @@ public function register(): array * * @return void */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { $tokens = $phpcsFile->getTokens(); diff --git a/MO4/Sniffs/Arrays/MultiLineArraySniff.php b/MO4/Sniffs/Arrays/MultiLineArraySniff.php index 596f9dc9..b83d1e7e 100644 --- a/MO4/Sniffs/Arrays/MultiLineArraySniff.php +++ b/MO4/Sniffs/Arrays/MultiLineArraySniff.php @@ -27,6 +27,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class MultiLineArraySniff implements Sniff { @@ -48,6 +50,7 @@ class MultiLineArraySniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return $this->arrayTokens; @@ -64,6 +67,7 @@ public function register(): array * * @return void */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { $tokens = $phpcsFile->getTokens(); diff --git a/MO4/Sniffs/Commenting/PropertyCommentSniff.php b/MO4/Sniffs/Commenting/PropertyCommentSniff.php index 2a6e0ac5..036673f9 100644 --- a/MO4/Sniffs/Commenting/PropertyCommentSniff.php +++ b/MO4/Sniffs/Commenting/PropertyCommentSniff.php @@ -32,6 +32,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class PropertyCommentSniff extends AbstractScopeSniff { @@ -75,6 +77,7 @@ public function __construct() * * @throws RuntimeException */ + #[\Override] protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope): void { $find = [ @@ -243,6 +246,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop * * @return void */ + #[\Override] protected function processTokenOutsideScope(File $phpcsFile, $stackPtr): void { } diff --git a/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php b/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php index 02b4ff9a..0bd08a35 100644 --- a/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php +++ b/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php @@ -33,6 +33,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class AlphabeticalUseStatementsSniff extends UseDeclarationSniff { @@ -87,6 +89,7 @@ class AlphabeticalUseStatementsSniff extends UseDeclarationSniff * * @return void */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { if (!\in_array($this->order, self::SUPPORTED_ORDERING_METHODS, true)) { @@ -292,7 +295,8 @@ private function findNewDestination(File $phpcsFile, int $stackPtr, string $impo { $tokens = $phpcsFile->getTokens(); - $line = $tokens[$stackPtr]['line']; + $line = $tokens[$stackPtr]['line']; + /** @var int|bool $prevLine */ $prevLine = false; $prevPtr = $stackPtr; diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index 0f3ccb30..cf5dc953 100644 --- a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php +++ b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php @@ -34,6 +34,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class UnnecessaryNamespaceUsageSniff implements Sniff { @@ -54,6 +56,7 @@ class UnnecessaryNamespaceUsageSniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return [T_CLASS]; @@ -75,6 +78,7 @@ public function register(): array * * @throws RuntimeException */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { $docCommentTags = [ @@ -381,6 +385,7 @@ private function checkShorthandPossible(File $phpcsFile, array $useStatements, s if (true === $isDocBlock) { $tokens = $phpcsFile->getTokens(); $oldContent = $tokens[$startPtr]['content']; + /** @var string $newContent */ $newContent = \str_replace($className, $replacement, $oldContent); $phpcsFile->fixer->replaceToken($startPtr, $newContent); } else { diff --git a/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php b/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php index 9cb14753..39d4e7b9 100644 --- a/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php +++ b/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php @@ -29,6 +29,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class VariableInDoubleQuotedStringSniff implements Sniff { @@ -39,6 +41,7 @@ class VariableInDoubleQuotedStringSniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return [T_DOUBLE_QUOTED_STRING]; @@ -58,6 +61,7 @@ public function register(): array * * @return void */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { $varRegExp = '/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/'; diff --git a/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php b/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php index 7784f6b6..0b0dc95a 100644 --- a/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php +++ b/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php @@ -27,6 +27,8 @@ * @license http://spdx.org/licenses/MIT MIT License * * @link https://github.com/mayflower/mo4-coding-standard + * + * @psalm-api */ class ConstantSpacingSniff implements Sniff { @@ -46,6 +48,7 @@ class ConstantSpacingSniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return $this->arrayTokens; @@ -62,6 +65,7 @@ public function register(): array * * @return void */ + #[\Override] public function process(File $phpcsFile, $stackPtr): void { $tokens = $phpcsFile->getTokens(); diff --git a/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php b/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php index e52853cd..fb7cfc5c 100644 --- a/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php +++ b/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php @@ -13,6 +13,9 @@ use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Sniffs\Sniff; +/** + * @psalm-api + */ class MultipleEmptyLinesSniff implements Sniff { /** @@ -22,6 +25,7 @@ class MultipleEmptyLinesSniff implements Sniff * * @see Tokens.php */ + #[\Override] public function register(): array { return [ @@ -41,6 +45,7 @@ public function register(): array * * @return void|int */ + #[\Override] public function process(File $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); diff --git a/MO4/Tests/AbstractMo4SniffUnitTest.php b/MO4/Tests/AbstractMo4SniffUnitTest.php index 958c6ea9..875462a7 100644 --- a/MO4/Tests/AbstractMo4SniffUnitTest.php +++ b/MO4/Tests/AbstractMo4SniffUnitTest.php @@ -68,6 +68,7 @@ abstract class AbstractMo4SniffUnitTest extends AbstractSniffUnitTest * * @throws RuntimeException */ + #[\Override] protected function getErrorList(string $testFile = ''): array { return $this->getRecordForTestFile($testFile, $this->expectedErrorList); @@ -85,6 +86,7 @@ protected function getErrorList(string $testFile = ''): array * * @throws RuntimeException */ + #[\Override] protected function getWarningList(string $testFile = ''): array { return $this->getRecordForTestFile($testFile, $this->expectedWarningList); diff --git a/MO4/Tests/Arrays/ArrayDoubleArrowAlignmentUnitTest.php b/MO4/Tests/Arrays/ArrayDoubleArrowAlignmentUnitTest.php index 576203e5..78ecf0a3 100644 --- a/MO4/Tests/Arrays/ArrayDoubleArrowAlignmentUnitTest.php +++ b/MO4/Tests/Arrays/ArrayDoubleArrowAlignmentUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class ArrayDoubleArrowAlignmentUnitTest extends AbstractMo4SniffUnitTest +final class ArrayDoubleArrowAlignmentUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'ArrayDoubleArrowAlignmentUnitTest.pass.inc' => [], diff --git a/MO4/Tests/Arrays/MultiLineArrayUnitTest.php b/MO4/Tests/Arrays/MultiLineArrayUnitTest.php index 8f738436..711aaaaa 100644 --- a/MO4/Tests/Arrays/MultiLineArrayUnitTest.php +++ b/MO4/Tests/Arrays/MultiLineArrayUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class MultiLineArrayUnitTest extends AbstractMo4SniffUnitTest +final class MultiLineArrayUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'MultiLineArrayUnitTest.pass.inc' => [], diff --git a/MO4/Tests/Commenting/PropertyCommentUnitTest.php b/MO4/Tests/Commenting/PropertyCommentUnitTest.php index 453c9805..659a006e 100644 --- a/MO4/Tests/Commenting/PropertyCommentUnitTest.php +++ b/MO4/Tests/Commenting/PropertyCommentUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class PropertyCommentUnitTest extends AbstractMo4SniffUnitTest +final class PropertyCommentUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'PropertyCommentUnitTest.pass.inc' => [], diff --git a/MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php b/MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php index 94a23c4a..4e38b656 100644 --- a/MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php +++ b/MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class AlphabeticalUseStatementsUnitTest extends AbstractMo4SniffUnitTest +final class AlphabeticalUseStatementsUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'AlphabeticalUseStatementsUnitTest.pass.inc' => [], diff --git a/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php index 2cc60485..a811f1cf 100644 --- a/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php +++ b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php @@ -32,7 +32,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class UnnecessaryNamespaceUsageUnitTest extends AbstractMo4SniffUnitTest +final class UnnecessaryNamespaceUsageUnitTest extends AbstractMo4SniffUnitTest { protected $expectedWarningList = [ 'UnnecessaryNamespaceUsageUnitTest.pass.1.inc' => [], diff --git a/MO4/Tests/Strings/VariableInDoubleQuotedStringUnitTest.php b/MO4/Tests/Strings/VariableInDoubleQuotedStringUnitTest.php index 7081ea50..ed30c8df 100644 --- a/MO4/Tests/Strings/VariableInDoubleQuotedStringUnitTest.php +++ b/MO4/Tests/Strings/VariableInDoubleQuotedStringUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class VariableInDoubleQuotedStringUnitTest extends AbstractMo4SniffUnitTest +final class VariableInDoubleQuotedStringUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'VariableInDoubleQuotedStringUnitTest.pass.inc' => [], diff --git a/MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php b/MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php index 29dce6be..a4f52b62 100644 --- a/MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php +++ b/MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class ConstantSpacingUnitTest extends AbstractMo4SniffUnitTest +final class ConstantSpacingUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'ConstantSpacingUnitTest.pass.inc' => [], diff --git a/MO4/Tests/WhiteSpace/MultipleEmptyLinesUnitTest.php b/MO4/Tests/WhiteSpace/MultipleEmptyLinesUnitTest.php index 6864140d..13703b4a 100644 --- a/MO4/Tests/WhiteSpace/MultipleEmptyLinesUnitTest.php +++ b/MO4/Tests/WhiteSpace/MultipleEmptyLinesUnitTest.php @@ -30,7 +30,7 @@ * * @link https://github.com/mayflower/mo4-coding-standard */ -class MultipleEmptyLinesUnitTest extends AbstractMo4SniffUnitTest +final class MultipleEmptyLinesUnitTest extends AbstractMo4SniffUnitTest { protected $expectedErrorList = [ 'MultipleEmptyLinesUnitTest.pass.inc' => [], diff --git a/composer.json b/composer.json index 615c1e61..b602a2b8 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "source": "https://github.com/mayflower/mo4-coding-standard" }, "require": { - "php": "~7.2 || ~8.0", + "php": "~8.1", "dealerdirect/phpcodesniffer-composer-installer": "~0.7 || ~1.0", "escapestudios/symfony2-coding-standard": "^3.16.0", "slevomat/coding-standard": "^8.14", @@ -31,12 +31,16 @@ }, "require-dev": { "ergebnis/composer-normalize": ">=2.19 <2.30", - "phan/phan": "^5.4.2", + "nikic/php-parser": "< 5.0.1", + "phan/phan": "^5.4.5", "phpstan/phpstan": "^1.12", "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "^7.5.20 || ^8.5.36 || ^9.6.15", - "psalm/plugin-phpunit": "^0.18", - "vimeo/psalm": "^4.30" + "phpunit/phpunit": "^8.5.36 || ^9.6.15", + "psalm/plugin-phpunit": "^0.19", + "sabre/event": ">= 5.1.6", + "symfony/filesystem": ">= 5.4.45", + "symfony/polyfill-php83": "^1.32", + "vimeo/psalm": "^6.0.0" }, "config": { "allow-plugins": { From 627391336c73a3ebdab1ee3f042fedede7d10ed0 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 26 Jan 2025 19:02:11 +0100 Subject: [PATCH 2/6] Raise minimum PHPUnit version --- composer.json | 2 +- phpunit.xml.dist | 10 ++++++---- tests/bootstrap.php | 17 ----------------- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index b602a2b8..c0e352eb 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "phan/phan": "^5.4.5", "phpstan/phpstan": "^1.12", "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "^8.5.36 || ^9.6.15", + "phpunit/phpunit": "^9.6.15", "psalm/plugin-phpunit": "^0.19", "sabre/event": ">= 5.1.6", "symfony/filesystem": ">= 5.4.45", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f1c788d3..6f0aabe5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,7 @@ vendor/squizlabs/php_codesniffer/tests/Standards/AllSniffs.php - - + + ./MO4/Sniffs - - + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0a7e8fa3..364cf046 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -43,20 +43,3 @@ static function ($v) use ($myStandardName): bool { ); putenv("PHPCS_IGNORE_TESTS={$ignoredStandardsStr}"); - -/* - * PHPUnit 9.3 is the first version which supports Xdebug 3, but we're using older versions. - * - * For now, until a fix is pulled into the whole stack, this will allow older PHPUnit - * versions to run with Xdebug 3 for code coverage. - */ - -if ((true === extension_loaded('xdebug')) && (true === version_compare((string) phpversion('xdebug'), '3', '>='))) { - if (false === defined('XDEBUG_CC_UNUSED')) { - define('XDEBUG_CC_UNUSED', null); - } - - if (false === defined('XDEBUG_CC_DEAD_CODE')) { - define('XDEBUG_CC_DEAD_CODE', null); - } -} From 6dea54b8d012d965fdf7b123e83023e316c2c5b0 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 15 Jul 2025 16:33:04 +0200 Subject: [PATCH 3/6] Update PHPStan to 2.x --- composer.json | 4 ++-- phpstan.neon | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c0e352eb..6d8cb9df 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ "ergebnis/composer-normalize": ">=2.19 <2.30", "nikic/php-parser": "< 5.0.1", "phan/phan": "^5.4.5", - "phpstan/phpstan": "^1.12", - "phpstan/phpstan-strict-rules": "^1.6", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^9.6.15", "psalm/plugin-phpunit": "^0.19", "sabre/event": ">= 5.1.6", diff --git a/phpstan.neon b/phpstan.neon index bab22017..c8811dd0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: max + level: 9 bootstrapFiles: - %rootDir%/../../../tests/static_analysis_bootstrap.php paths: From 59f14449bbc07fef216378d1f69080e77f8911fe Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 26 Jan 2025 17:37:34 +0100 Subject: [PATCH 4/6] Use PHP 8 language contructs --- MO4/Sniffs/Commenting/PropertyCommentSniff.php | 4 ++-- .../AlphabeticalUseStatementsSniff.php | 18 +++++++----------- .../UnnecessaryNamespaceUsageSniff.php | 2 +- .../VariableInDoubleQuotedStringSniff.php | 2 +- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/MO4/Sniffs/Commenting/PropertyCommentSniff.php b/MO4/Sniffs/Commenting/PropertyCommentSniff.php index 036673f9..fde822be 100644 --- a/MO4/Sniffs/Commenting/PropertyCommentSniff.php +++ b/MO4/Sniffs/Commenting/PropertyCommentSniff.php @@ -112,8 +112,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', diff --git a/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php b/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php index 0bd08a35..bf096562 100644 --- a/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php +++ b/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php @@ -336,17 +336,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), + }; } /** diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index cf5dc953..28620a2a 100644 --- a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php +++ b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php @@ -361,7 +361,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 = [ diff --git a/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php b/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php index 39d4e7b9..10c7ed8c 100644 --- a/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php +++ b/MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php @@ -80,7 +80,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; } From 66cdfe052f8b4ee8b25e98894b61add8b1c57368 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 26 Jan 2025 15:40:33 +0100 Subject: [PATCH 5/6] Update composer-normalize --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 6d8cb9df..c59be4e3 100644 --- a/composer.json +++ b/composer.json @@ -23,14 +23,14 @@ "source": "https://github.com/mayflower/mo4-coding-standard" }, "require": { - "php": "~8.1", - "dealerdirect/phpcodesniffer-composer-installer": "~0.7 || ~1.0", + "php": "^8.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", "escapestudios/symfony2-coding-standard": "^3.16.0", "slevomat/coding-standard": "^8.14", "squizlabs/php_codesniffer": "^3.8.0" }, "require-dev": { - "ergebnis/composer-normalize": ">=2.19 <2.30", + "ergebnis/composer-normalize": "^2.45", "nikic/php-parser": "< 5.0.1", "phan/phan": "^5.4.5", "phpstan/phpstan": "^2.0", From c62820332358012ff7d90178f6881ea68e185119 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sat, 2 Aug 2025 16:29:23 +0200 Subject: [PATCH 6/6] Use cobertura for qlty coverage --- .github/workflows/ci.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 943c6fff..7c74bb2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,7 @@ on: push: schedule: - cron: '30 5 1 * *' + jobs: style-checks: env: @@ -97,7 +98,7 @@ jobs: run: vendor/bin/phan --allow-polyfill-parser - name: Run tests with coverage if: ${{ matrix.os != 'windows-latest' && matrix.php_version == '8.1' && matrix.dependencies_level != '--prefer-lowest' }} - run: php vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=junit.xml + run: php vendor/bin/phpunit --coverage-clover=coverage.xml --coverage-cobertura=cobertura.xml --log-junit=junit.xml - name: Upload coverage to Codecov if: ${{ matrix.os != 'windows-latest' && matrix.php_version == '8.1' && matrix.dependencies_level != '--prefer-lowest' }} uses: codecov/codecov-action@v5 @@ -113,7 +114,9 @@ jobs: uses: qltysh/qlty-action/coverage@v1 with: token: ${{ secrets.QLTY_COVERAGE_TOKEN }} - files: coverage.xml + files: cobertura.xml + strip-prefix: '/home/runner/work/mo4-coding-standard' + add-prefix: 'MO4/Sniffs/' env: QLTY_COVERAGE_TOKEN: ${{ secrets.QLTY_COVERAGE_TOKEN }}