Skip to content
Closed
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
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
"pear/pear-core-minimal": "^v1.10.15"
},
"require-dev": {
"codeigniter/coding-standard": "^1.8.1",
"nexusphp/tachycardia": "^2.0",
"codeigniter/coding-standard": "^1.8.9 || ^1.9.1",
"nexusphp/tachycardia": "^2.4",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.1.11",
"phpstan/phpstan-strict-rules": "^2.0.4",
"phpunit/phpcov": "^9.0.2 || ^10.0",
"phpunit/phpunit": "^10.5.16 || ^11.2",
"rector/rector": "2.0.11"
"phpstan/phpstan": "^2.1.40",
"phpstan/phpstan-strict-rules": "^2.0.10",
"phpunit/phpcov": "^9.0.2 || ^10.0.1 || ^11.0.4",
"phpunit/phpunit": "^10.5.16 || ^11.5",
"rector/rector": "2.3.8"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
66 changes: 27 additions & 39 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,8 @@
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has parameter \\$keyBits with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has parameter \\$password with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has parameter \\$saltValue with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has parameter \\$spinCount with no type specified\\.$#',
'identifier' => 'missingType.parameter',
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_convertPasswordToKey\\(\\) has parameter \\$saltValue with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
Expand All @@ -50,20 +32,20 @@
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_createUInt32LEBuffer\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_createUInt32LEBuffer\\(\\) return type has no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_crypt\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_crypt\\(\\) has parameter \\$key with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_crypt\\(\\) has parameter \\$key with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_crypt\\(\\) should return list\\<mixed\\> but returns array\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
Expand All @@ -79,12 +61,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:output\\(\\) should return string but returns string\\|false\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Offset \'name\' might not exist on array\\<string, string\\>\\|string\\.$#',
'identifier' => 'offsetAccess.notFound',
Expand All @@ -98,37 +74,37 @@
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$array of function array_pad expects array, mixed given\\.$#',
'identifier' => 'argument.type',
'message' => '#^PHPDoc tag @param for parameter \\$input with type mixed is not subtype of native type Closure\\|null\\.$#',
'identifier' => 'parameter.phpDocType',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$encryptionInfo of method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_buildEncryptionInfo\\(\\) expects array\\<string, array\\<string, array\\<string, int\\|string\\>\\>\\>, array\\<string, array\\<string, mixed\\>\\> given\\.$#',
'message' => '#^Parameter \\#1 \\$array of function array_pad expects array, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#',
'message' => '#^Parameter \\#1 \\$encryptionInfo of method PHPDevsr\\\\Spreadsheet\\\\Secure\\:\\:_buildEncryptionInfo\\(\\) expects array\\<string, array\\<string, array\\<string, int\\|string\\>\\>\\>, array\\<string, array\\<string, array\\|int\\|string\\>\\> given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$stream of function feof expects resource, resource\\|false given\\.$#',
'message' => '#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$stream of function fread expects resource, resource\\|false given\\.$#',
'message' => '#^Parameter \\#1 \\$stream of function feof expects resource, resource\\|false given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$string of function bin2hex expects string, array\\<int, string\\>\\|string\\|false given\\.$#',
'message' => '#^Parameter \\#1 \\$stream of function fread expects resource, resource\\|false given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
Expand Down Expand Up @@ -175,6 +151,18 @@
'count' => 1,
'path' => __DIR__ . '/src/Secure.php',
];
$ignoreErrors[] = [
'message' => '#^Method Tests\\\\SecureTest\\:\\:provideEncryptor\\(\\) return type has no value type specified in iterable type iterable\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/tests/SecureTest.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/tests/SecureTest.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$length of function fread expects int\\<1, max\\>, int\\<0, max\\> given\\.$#',
'identifier' => 'argument.type',
Expand Down
217 changes: 62 additions & 155 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,172 +11,79 @@
* the LICENSE file that was distributed with this source code.
*/

use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
use Rector\CodeQuality\Rector\BooleanNot\ReplaceMultipleBooleanNotRector;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector;
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfNotNullReturnRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfNullableReturnRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\LogicalAnd\AndAssignsToSeparateLinesRector;
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
use Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector;
use Rector\CodeQuality\Rector\Ternary\NumberCompareToMaxFuncCallRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector;
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector;
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
use Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector;
use Rector\DeadCode\Rector\Return_\RemoveDeadConditionAboveReturnRector;
use Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\ValueObject\PhpVersion;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
SetList::STRICT_BOOLEANS,
LevelSetList::UP_TO_PHP_80,
]);

// The paths to refactor (can also be supplied with CLI arguments)
$rectorConfig->paths([
use Rector\Renaming\Rector\ConstFetch\RenameConstantRector;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector;
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
use Rector\TypeDeclaration\Rector\Function_\AddFunctionVoidReturnTypeWhereNoReturnRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return RectorConfig::configure()
->withPhpSets(php81: true)
->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, instanceOf: true, phpunitCodeQuality: true, typeDeclarations: true, earlyReturn: true)
->withAutoloadPaths([
__DIR__ . '/vendor/autoload.php',
])
->withComposerBased(phpunit: true)
->withParallel(200, 16, 16)
->withCache(
// Github action cache or local
is_dir('/tmp') ? '/tmp/rector' : null,
FileCacheStorage::class,
)
// paths to refactor; solid alternative to CLI arguments
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// Include Composer's autoload - required for global execution, remove if running locally
$rectorConfig->autoloadPaths([
__DIR__ . '/vendor/autoload.php',
]);

if (is_file(__DIR__ . '/phpstan.neon.dist')) {
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist');
}

// Set the target version for refactoring
$rectorConfig->phpVersion(PhpVersion::PHP_82);

// Auto-import fully qualified class names
$rectorConfig->importNames();

// Are there files or rules you need to skip?
$rectorConfig->skip([
__DIR__ . '/src/_support',
])
->withPHPStanConfigs([
__DIR__ . '/phpstan.neon.dist',
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
])
// is there a file you need to skip?
->withSkip([
__DIR__ . '/tests/_support',

ExplicitReturnNullRector::class,
]);

])
// auto import fully qualified class names
$rectorConfig->importNames();

// Code Quality
$rectorConfig->rule(JoinStringConcatRector::class);
$rectorConfig->rule(CombinedAssignRector::class);
$rectorConfig->rule(ReplaceMultipleBooleanNotRector::class);
$rectorConfig->rule(InlineArrayReturnAssignRector::class);
$rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
$rectorConfig->rule(UseIdenticalOverEqualWithSameTypeRector::class);
$rectorConfig->rule(TernaryFalseExpressionToIfRector::class);
$rectorConfig->rule(ArrayMergeOfNonArraysToSimpleArrayRector::class);
$rectorConfig->rule(ExplicitBoolCompareRector::class);
$rectorConfig->rule(SimplifyIfNotNullReturnRector::class);
$rectorConfig->rule(SimplifyIfNullableReturnRector::class);
$rectorConfig->rule(SimplifyUselessVariableRector::class);
$rectorConfig->rule(AndAssignsToSeparateLinesRector::class);
$rectorConfig->rule(LogicalToBooleanRector::class);
$rectorConfig->rule(CommonNotEqualRector::class);
$rectorConfig->rule(NumberCompareToMaxFuncCallRector::class);
$rectorConfig->rule(SwitchNegatedTernaryRector::class);
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
$rectorConfig->rule(SimplifyRegexPatternRector::class);
$rectorConfig->rule(SimplifyStrposLowerRector::class);
$rectorConfig->rule(CombineIfRector::class);
$rectorConfig->rule(CompleteMissingIfElseBracketRector::class);
$rectorConfig->rule(ShortenElseIfRector::class);
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);

// Coding Stlye
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);

// Dead Code
$rectorConfig->rule(RemoveDuplicatedArrayKeyRector::class);
$rectorConfig->rule(RemoveDoubleAssignRector::class);
$rectorConfig->rule(RemoveUnusedVariableAssignRector::class);
$rectorConfig->rule(RemoveAndTrueRector::class);
$rectorConfig->rule(RecastingRemovalRector::class);
$rectorConfig->rule(RemoveUnusedPrivateClassConstantRector::class);
$rectorConfig->rule(RemoveEmptyClassMethodRector::class);
$rectorConfig->rule(RemoveUnusedConstructorParamRector::class);
$rectorConfig->rule(RemoveUnusedPrivateMethodParameterRector::class);
$rectorConfig->rule(RemoveUnusedPrivateMethodRector::class);
$rectorConfig->rule(RemoveUselessParamTagRector::class);
$rectorConfig->rule(RemoveUselessReturnTagRector::class);
$rectorConfig->rule(RemoveConcatAutocastRector::class);
$rectorConfig->rule(RemovePhpVersionIdCheckRector::class);
$rectorConfig->rule(RemoveDeadStmtRector::class);
$rectorConfig->rule(SimplifyMirrorAssignRector::class);
$rectorConfig->rule(RemoveDeadZeroAndOneOperationRector::class);
$rectorConfig->rule(RemoveDeadConditionAboveReturnRector::class);
$rectorConfig->rule(RemoveDeadTryCatchRector::class);

// Another
$rectorConfig->rule(RemoveAlwaysElseRector::class);
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
};
->withImportNames(removeUnusedImports: true)
->withRules([
DeclareStrictTypesRector::class,
SimplifyUselessVariableRector::class,
RemoveAlwaysElseRector::class,
ChangeNestedForeachIfsToEarlyContinueRector::class,
ChangeIfElseValueAssignToEarlyReturnRector::class,
PreparedValueToEarlyReturnRector::class,
SimplifyEmptyCheckOnEmptyArrayRector::class,
TernaryEmptyArrayArrayDimFetchToCoalesceRector::class,
EmptyOnNullableObjectToInstanceOfRector::class,
DisallowedEmptyRuleFixerRector::class,
PrivatizeFinalClassPropertyRector::class,
AddClosureVoidReturnTypeWhereNoReturnRector::class,
AddFunctionVoidReturnTypeWhereNoReturnRector::class,
AddMethodCallBasedStrictParamTypeRector::class,
TypedPropertyFromAssignsRector::class,
ClosureReturnTypeRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
AddArrowFunctionReturnTypeRector::class,
])
->withConfiguredRule(RenameConstantRector::class, [
'FILTER_DEFAULT' => 'FILTER_UNSAFE_RAW',
]);
Loading
Loading