Skip to content

Commit

Permalink
[TASK] Drop PHP7.4 support; add PHP8.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
aoekrz committed Aug 8, 2023
1 parent 7153ee0 commit 6a51267
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 160 deletions.
37 changes: 13 additions & 24 deletions .code-quality/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,41 @@
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer;
use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer;
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer;
use PhpCsFixer\Fixer\Strict\StrictComparisonFixer;
use PhpCsFixer\Fixer\Strict\StrictParamFixer;
use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer;
use PhpCsFixer\Fixer\Whitespace\ArrayIndentationFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer;
use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer;
use Symplify\CodingStandard\Fixer\LineLength\DocBlockLineLengthFixer;
use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths(
[
__DIR__ . '/../Classes',
__DIR__ . '/ecs.php',
]
);

$containerConfigurator->import(SetList::COMMON);
$containerConfigurator->import(SetList::CLEAN_CODE);
$containerConfigurator->import(SetList::PSR_12);
$containerConfigurator->import(SetList::SYMPLIFY);
$ecsConfig->import(SetList::COMMON);
$ecsConfig->import(SetList::CLEAN_CODE);
$ecsConfig->import(SetList::PSR_12);
$ecsConfig->import(SetList::SYMPLIFY);

$containerConfigurator->services()
$ecsConfig->services()
->set(LineLengthFixer::class)
->call('configure', [[
LineLengthFixer::LINE_LENGTH => 140,
LineLengthFixer::INLINE_SHORT_LINES => false,
]]);

$ecsConfig->indentation('spaces');
$ecsConfig->lineEnding(PHP_EOL);
$ecsConfig->cacheDirectory('.cache/ecs/default/');

// Skip Rules and Sniffer
$parameters->set(
Option::SKIP,
$ecsConfig->skip(
[
// Default Skips
Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer::class => [
Expand All @@ -59,13 +55,6 @@
DocBlockLineLengthFixer::class => null,
'\SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff.DuplicateSpaces' => null,
'\SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff.PartialUse' => null,

// @todo for next upgrade
NoSuperfluousPhpdocTagsFixer::class => null,
// @todo strict php
DeclareStrictTypesFixer::class => null,
StrictComparisonFixer::class => null,
StrictParamFixer::class => null,
]
);
};
31 changes: 21 additions & 10 deletions .code-quality/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
message: "#^Method Aoe\\\\UpdateRefindex\\\\Scheduler\\\\UpdateRefIndexTask\\:\\:getRefIndex\\(\\) should return Aoe\\\\UpdateRefindex\\\\Typo3\\\\RefIndex but returns object\\.$#"
count: 1
path: ../Classes/Scheduler/UpdateRefIndexTask.php

-
message: "#^Cannot call method fetchAll\\(\\) on Doctrine\\\\DBAL\\\\Result\\|int\\.$#"
count: 2
Expand All @@ -20,21 +21,31 @@ parameters:
path: ../Classes/Typo3/RefIndex.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$predicates of method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryBuilder\\:\\:where\\(\\) expects array\\<int, mixed\\>\\|Doctrine\\\\DBAL\\\\Query\\\\Expression\\\\CompositeExpression, string given\\.$#"
count: 3
message: "#^Property Aoe\\\\UpdateRefindex\\\\Typo3\\\\RefIndex\\:\\:\\$connectionPool \\(TYPO3\\\\CMS\\\\Core\\\\Database\\\\ConnectionPool\\|null\\) does not accept object\\.$#"
count: 1
path: ../Classes/Typo3/RefIndex.php

-
message: "#^Parameter \\#1 \\.\\.\\.\\$where of method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\QueryBuilder\\:\\:andWhere\\(\\) expects array\\<int, string\\>\\|Doctrine\\\\DBAL\\\\Query\\\\Expression\\\\CompositeExpression, string given\\.$#"
count: 2
message: "#^Property Aoe\\\\UpdateRefindex\\\\Typo3\\\\RefIndex\\:\\:\\$referenceIndex \\(TYPO3\\\\CMS\\\\Core\\\\Database\\\\ReferenceIndex\\|null\\) does not accept object\\.$#"
count: 1
path: ../Classes/Typo3/RefIndex.php

-
message: "#^Property Aoe\\\\UpdateRefindex\\\\Typo3\\\\RefIndex\\:\\:\\$connectionPool \\(TYPO3\\\\CMS\\\\Core\\\\Database\\\\ConnectionPool\\|null\\) does not accept object\\.$#"
count: 1
path: ../Classes/Typo3/RefIndex.php
message: "#^Relative file path \"(.*)\" is not allowed, use absolute one with __DIR__$#"
paths:
- ../Classes/

-
message: "#^Property Aoe\\\\UpdateRefindex\\\\Typo3\\\\RefIndex\\:\\:\\$referenceIndex \\(TYPO3\\\\CMS\\\\Core\\\\Database\\\\ReferenceIndex\\|null\\) does not accept object\\.$#"
count: 1
path: ../Classes/Typo3/RefIndex.php
message: "#^Use custom exceptions instead of native \"InvalidArgumentException\"$#"
paths:
- ../Classes/

-
message: "#^Anonymous variable in a (.*) method call can lead to false dead methods\\. Make sure the variable type is known$#"
paths:
- ../Classes/

-
message: "#^There are 2 way to get \"updateAllTables\" value: public property and getter now - pick one to avoid variant behavior\\.$#"
paths:
- ../Classes/
19 changes: 7 additions & 12 deletions .code-quality/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- phpstan-baseline.neon
- ../.Build/vendor/symplify/phpstan-rules/packages/cognitive-complexity/config/cognitive-complexity-rules.neon
- ../.Build/vendor/symplify/phpstan-rules/config/code-complexity-rules.neon

rules:
- Symplify\PHPStanRules\Rules\NoDefaultExceptionRule
Expand All @@ -15,17 +15,12 @@ parameters:
checkGenericClassInNonGenericObjectType: false

services:
- class: Symplify\Astral\Naming\SimpleNameResolver
- class: Symplify\PHPStanRules\CognitiveComplexity\AstCognitiveComplexityAnalyzer
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeTraverser\ComplexityNodeTraverserFactory
- class: Symplify\PHPStanRules\CognitiveComplexity\DataCollector\CognitiveComplexityDataCollector
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\NestingNodeVisitor
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeVisitor\ComplexityNodeVisitor
- class: Symplify\PHPStanRules\CognitiveComplexity\NodeAnalyzer\ComplexityAffectingNodeFinder
- class: Symplify\PackageBuilder\Php\TypeChecker
- class: Symplify\PackageBuilder\Matcher\ArrayStringAndFnMatcher
- class: Symplify\PHPStanRules\TypeAnalyzer\ObjectTypeAnalyzer
- class: Symplify\PHPStanRules\TypeAnalyzer\TypeUnwrapper
- class: Symplify\PHPStanRules\TypeResolver\ClassMethodReturnTypeResolver
- class: Symplify\PHPStanRules\Reflection\MethodCallNodeAnalyzer
- class: Symplify\PHPStanRules\NodeAnalyzer\MethodCall\MethodCallClassConstFetchPositionResolver
- class: Symplify\PHPStanRules\TypeAnalyzer\CallableTypeAnalyzer
- class: Symplify\PHPStanRules\Matcher\ArrayStringAndFnMatcher
- class: Symplify\PHPStanRules\Formatter\RequiredWithMessageFormatter
-
class: Symplify\PHPStanRules\Rules\ForbiddenFuncCallRule
tags: [phpstan.rules.rule]
Expand Down
30 changes: 0 additions & 30 deletions .code-quality/rector-8_0.php

This file was deleted.

51 changes: 51 additions & 0 deletions .code-quality/rector-8_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths(
[
__DIR__ . '/../Classes',
__DIR__ . '/../Tests',
__DIR__ . '/rector-8_1.php',
]
);

$rectorConfig->import(SetList::PHP_82);

$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);

$rectorConfig->importNames(false);
$rectorConfig->autoloadPaths([__DIR__ . '/../Classes']);
$rectorConfig->cacheDirectory('.cache/rector/upgrade_8-1/');
$rectorConfig->skip(
[
RecastingRemovalRector::class,
PostIncDecToPreIncDecRector::class,
FinalizeClassesWithoutChildrenRector::class,
ChangeAndIfToEarlyReturnRector::class,

IssetOnPropertyObjectToPropertyExistsRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
AddLiteralSeparatorToNumberRector::class,
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
]
);

$rectorConfig->rule(RemoveUnusedPrivatePropertyRector::class);
};
51 changes: 51 additions & 0 deletions .code-quality/rector-8_2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths(
[
__DIR__ . '/../Classes',
__DIR__ . '/../Tests',
__DIR__ . '/rector-8_2.php',
]
);

$rectorConfig->import(SetList::PHP_82);

$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);

$rectorConfig->importNames(false);
$rectorConfig->autoloadPaths([__DIR__ . '/../Classes']);
$rectorConfig->cacheDirectory('.cache/rector/upgrade_8-2/');
$rectorConfig->skip(
[
RecastingRemovalRector::class,
PostIncDecToPreIncDecRector::class,
FinalizeClassesWithoutChildrenRector::class,
ChangeAndIfToEarlyReturnRector::class,

IssetOnPropertyObjectToPropertyExistsRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
AddLiteralSeparatorToNumberRector::class,
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
]
);

$rectorConfig->rule(RemoveUnusedPrivatePropertyRector::class);
};
62 changes: 13 additions & 49 deletions .code-quality/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

declare(strict_types=1);

use Rector\Arguments\Rector\ClassMethod\ArgumentAdderRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodeQualityStrict\Rector\If_\MoveOutMethodCallInsideIfConditionRector;
use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector;
use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector;
Expand All @@ -24,7 +19,6 @@
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
Expand All @@ -35,44 +29,25 @@
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector;
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return static function (ContainerConfigurator $containerConfigurator): void {

$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODE_QUALITY_STRICT);
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::EARLY_RETURN);
$containerConfigurator->import(SetList::PRIVATIZATION);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::PSR_4);
$containerConfigurator->import(SetList::MYSQL_TO_MYSQLI);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);
$containerConfigurator->import(SetList::UNWRAP_COMPAT);

$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::PHP_74);
$containerConfigurator->import(SetList::PHP_80);

$containerConfigurator->import(PHPUnitSetList::PHPUNIT_CODE_QUALITY);

$parameters = $containerConfigurator->parameters();
$parameters->set(
Option::PATHS,
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths(
[
__DIR__ . '/../Classes',
__DIR__ . '/rector.php',
__DIR__ . '/../code-quality',
]
);

$parameters->set(Option::AUTO_IMPORT_NAMES, false);
$parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/../Classes']);
$parameters->set(
Option::SKIP,
$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class);

$rectorConfig->importNames(false);
$rectorConfig->autoloadPaths([__DIR__ . '/../Classes']);
$rectorConfig->cacheDirectory('.cache/rector/default/');
$rectorConfig->skip(
[
RecastingRemovalRector::class,
ConsistentPregDelimiterRector::class,
Expand All @@ -97,19 +72,8 @@
PrivatizeLocalPropertyToPrivatePropertyRector::class,
RemoveDelegatingParentCallRector::class,
RemoveUnusedVariableInCatchRector::class,

// @todo strict php
ArgumentAdderRector::class,
ParamTypeDeclarationRector::class,
ReturnTypeDeclarationRector::class,
RemoveExtraParametersRector::class,
EncapsedStringsToSprintfRector::class,
AddFalseDefaultToBoolPropertyRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,
UseIdenticalOverEqualWithSameTypeRector::class,
]
);

$services = $containerConfigurator->services();
$services->set(RemoveUnusedPrivatePropertyRector::class);
$rectorConfig->rule(RemoveUnusedPrivatePropertyRector::class);
};
Loading

0 comments on commit 6a51267

Please sign in to comment.