Skip to content

raise minimum PHP version to 8.1 #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- ""
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
'MO4',
'tests',
'vendor/squizlabs/php_codesniffer',
'vendor/symfony/polyfill-php83',
],

// A directory list that defines files that will be excluded
Expand Down
2 changes: 1 addition & 1 deletion MO4/Library/PregLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use PHP_CodeSniffer\Exceptions\RuntimeException;

class PregLibrary
final class PregLibrary
{
/**
* Split string by a regular expression
Expand Down
4 changes: 4 additions & 0 deletions MO4/Sniffs/Arrays/ArrayDoubleArrowAlignmentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -51,6 +53,7 @@ class ArrayDoubleArrowAlignmentSniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return $this->arrayTokens;
Expand All @@ -67,6 +70,7 @@ public function register(): array
*
* @return void
*/
#[\Override]
public function process(File $phpcsFile, $stackPtr): void
{
$tokens = $phpcsFile->getTokens();
Expand Down
4 changes: 4 additions & 0 deletions MO4/Sniffs/Arrays/MultiLineArraySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -48,6 +50,7 @@ class MultiLineArraySniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return $this->arrayTokens;
Expand All @@ -64,6 +67,7 @@ public function register(): array
*
* @return void
*/
#[\Override]
public function process(File $phpcsFile, $stackPtr): void
{
$tokens = $phpcsFile->getTokens();
Expand Down
8 changes: 6 additions & 2 deletions MO4/Sniffs/Commenting/PropertyCommentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -75,6 +77,7 @@ public function __construct()
*
* @throws RuntimeException
*/
#[\Override]
protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope): void
{
$find = [
Expand Down Expand Up @@ -109,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',
Expand Down Expand Up @@ -243,6 +246,7 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
*
* @return void
*/
#[\Override]
protected function processTokenOutsideScope(File $phpcsFile, $stackPtr): void
{
}
Expand Down
24 changes: 12 additions & 12 deletions MO4/Sniffs/Formatting/AlphabeticalUseStatementsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -332,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),
};
}

/**
Expand Down
7 changes: 6 additions & 1 deletion MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -54,6 +56,7 @@ class UnnecessaryNamespaceUsageSniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return [T_CLASS];
Expand All @@ -75,6 +78,7 @@ public function register(): array
*
* @throws RuntimeException
*/
#[\Override]
public function process(File $phpcsFile, $stackPtr): void
{
$docCommentTags = [
Expand Down Expand Up @@ -357,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 = [
Expand All @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion MO4/Sniffs/Strings/VariableInDoubleQuotedStringSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -39,6 +41,7 @@ class VariableInDoubleQuotedStringSniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return [T_DOUBLE_QUOTED_STRING];
Expand All @@ -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]*/';
Expand All @@ -76,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;
}
Expand Down
4 changes: 4 additions & 0 deletions MO4/Sniffs/WhiteSpace/ConstantSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -46,6 +48,7 @@ class ConstantSpacingSniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return $this->arrayTokens;
Expand All @@ -62,6 +65,7 @@ public function register(): array
*
* @return void
*/
#[\Override]
public function process(File $phpcsFile, $stackPtr): void
{
$tokens = $phpcsFile->getTokens();
Expand Down
5 changes: 5 additions & 0 deletions MO4/Sniffs/WhiteSpace/MultipleEmptyLinesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

/**
* @psalm-api
*/
class MultipleEmptyLinesSniff implements Sniff
{
/**
Expand All @@ -22,6 +25,7 @@ class MultipleEmptyLinesSniff implements Sniff
*
* @see Tokens.php
*/
#[\Override]
public function register(): array
{
return [
Expand All @@ -41,6 +45,7 @@ public function register(): array
*
* @return void|int
*/
#[\Override]
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
Expand Down
2 changes: 2 additions & 0 deletions MO4/Tests/AbstractMo4SniffUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ abstract class AbstractMo4SniffUnitTest extends AbstractSniffUnitTest
*
* @throws RuntimeException
*/
#[\Override]
protected function getErrorList(string $testFile = ''): array
{
return $this->getRecordForTestFile($testFile, $this->expectedErrorList);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Arrays/ArrayDoubleArrowAlignmentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Arrays/MultiLineArrayUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Commenting/PropertyCommentUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/Strings/VariableInDoubleQuotedStringUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/WhiteSpace/ConstantSpacingUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
2 changes: 1 addition & 1 deletion MO4/Tests/WhiteSpace/MultipleEmptyLinesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
Expand Down
Loading