diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e11d3aa..459f1a7b 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 - "" @@ -93,7 +90,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/MO4/Library/PregLibrary.php b/MO4/Library/PregLibrary.php index b694108a..b41efcd9 100644 --- a/MO4/Library/PregLibrary.php +++ b/MO4/Library/PregLibrary.php @@ -43,7 +43,6 @@ public static function MO4PregSplit(string $pattern, string $subject, int $limit { $pregSplitResult = \preg_split($pattern, $subject, $limit, $flags); - // @phan-suppress-next-line PhanTypeComparisonToArray if (false === $pregSplitResult) { throw new RuntimeException('Unexpected Error in MO4 Coding Standard.'); } diff --git a/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php b/MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php index d4ee76b0..1ccf49cb 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 { @@ -96,7 +98,7 @@ public function process(File $phpcsFile, $stackPtr): void $previous = $tokens[($i - 1)]; // Skip nested arrays. - if (true === \in_array($current['code'], $this->arrayTokens, true)) { + if (\in_array($current['code'], $this->arrayTokens, true)) { $i = T_ARRAY === $current['code'] ? ($current['parenthesis_closer'] + 1) : ($current['bracket_closer'] + 1); continue; @@ -145,7 +147,7 @@ public function process(File $phpcsFile, $stackPtr): void $j = ($i - 1); while (($j >= 0) && ($tokens[$j]['line'] === $current['line'])) { - if (false === \in_array($tokens[$j]['code'], PHP_CodeSniffer_Tokens::$emptyTokens, true)) { + if (!\in_array($tokens[$j]['code'], PHP_CodeSniffer_Tokens::$emptyTokens, true)) { $hasKeyInLine = true; } diff --git a/MO4/Sniffs/Arrays/MultiLineArraySniff.php b/MO4/Sniffs/Arrays/MultiLineArraySniff.php index 596f9dc9..6ed29d4a 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 { diff --git a/MO4/Sniffs/Commenting/PropertyCommentSniff.php b/MO4/Sniffs/Commenting/PropertyCommentSniff.php index 2a6e0ac5..7696481b 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 { @@ -109,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', diff --git a/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php b/MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php index 86f00e2f..43fe70ee 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 { @@ -89,7 +91,7 @@ class AlphabeticalUseStatementsSniff extends UseDeclarationSniff */ public function process(File $phpcsFile, $stackPtr): void { - if (false === \in_array($this->order, self::SUPPORTED_ORDERING_METHODS, true)) { + if (!\in_array($this->order, self::SUPPORTED_ORDERING_METHODS, true)) { $error = \sprintf( "'%s' is not a valid order function for %s! Pick one of: %s", $this->order, @@ -292,7 +294,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; @@ -332,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), + }; } /** diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index 28860e98..c755491d 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 { @@ -125,7 +127,7 @@ public function process(File $phpcsFile, $stackPtr): void foreach ($tokens[$nsSep]['comment_tags'] as $tag) { $content = $tokens[$tag]['content']; - if (false === \array_key_exists($content, $docCommentTags)) { + if (!\array_key_exists($content, $docCommentTags)) { continue; } @@ -179,7 +181,7 @@ public function process(File $phpcsFile, $stackPtr): void // phpcs:enable foreach ($typeTokens as $typeToken) { - if (true === \in_array($typeToken, $useStatements, true)) { + if (\in_array($typeToken, $useStatements, true)) { continue; } @@ -341,7 +343,7 @@ private function checkShorthandPossible(File $phpcsFile, array $useStatements, s $fullClassName = $this->getFullyQualifiedClassName($className); - if (true === \array_key_exists($fullClassName, $useStatements)) { + if (\array_key_exists($fullClassName, $useStatements)) { $replacement = $useStatements[$fullClassName]; $data = [ @@ -357,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 = [ @@ -381,6 +383,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..fc5007ac 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 { @@ -76,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; } diff --git a/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php b/MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php index 7784f6b6..ed614655 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 { diff --git a/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php b/MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php index e52853cd..093e22ca 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 { /** diff --git a/composer.json b/composer.json index 475b6a22..c00fb83b 100644 --- a/composer.json +++ b/composer.json @@ -23,20 +23,22 @@ "source": "https://github.com/mayflower/mo4-coding-standard" }, "require": { - "php": "~7.2 || ~8.0", - "dealerdirect/phpcodesniffer-composer-installer": "~0.7 || ~1.0", + "php": "^8.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", "escapestudios/symfony2-coding-standard": "^3.10.0", "slevomat/coding-standard": "^8.14", "squizlabs/php_codesniffer": "^3.8.0" }, "require-dev": { - "ergebnis/composer-normalize": ">=2.19 <2.30", - "phan/phan": "^5.4.2", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-strict-rules": "^1.0", - "phpunit/phpunit": "^7.5.20 || ^8.5.36 || ^9.6.15", - "psalm/plugin-phpunit": "^0.18", - "vimeo/psalm": "^4.30" + "ergebnis/composer-normalize": "^2.45", + "phan/phan": "^5.4.5", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-strict-rules": "^1.6", + "phpunit/phpunit": "^9.6.15", + "psalm/plugin-phpunit": "^0.19", + "sabre/event": "^5.1.6", + "symfony/filesystem": ">= 5.4.45", + "vimeo/psalm": "^6.0.0" }, "config": { "allow-plugins": { diff --git a/phpstan.neon b/phpstan.neon index 603b51ee..a42fc6b5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,6 +5,7 @@ parameters: paths: - %rootDir%/../../../MO4 - %rootDir%/../../../tests - checkMissingIterableValueType: false + ignoreErrors: + - identifier: missingType.iterableValue includes: - vendor/phpstan/phpstan-strict-rules/rules.neon 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 - - + +