diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5ace460..4aaf59d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,7 @@ updates: directory: "/" schedule: interval: "weekly" + groups: + all-dependencies: + patterns: + - "*" diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/lint.yml similarity index 52% rename from .github/workflows/php-cs-fixer.yml rename to .github/workflows/lint.yml index 6db3755..d47bbaa 100644 --- a/.github/workflows/php-cs-fixer.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: PHP CS Fixer +name: Lint on: push: @@ -7,18 +7,21 @@ on: workflow_dispatch: jobs: - php-cs-fixer: + lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - - uses: shivammathur/setup-php@v2 + - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 with: php-version: '8.3' - name: Install dependencies run: composer install --no-interaction --no-progress - - name: Run PHP CS Fixer + - name: PHP CS Fixer run: php vendor/bin/php-cs-fixer fix --diff --dry-run + + - name: Rector + run: php vendor/bin/rector -c .rector.php --dry-run diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index c4b73ba..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Rector - -on: - push: - branches: [main] - pull_request: - workflow_dispatch: - -jobs: - rector: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v6 - - - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - - - name: Install dependencies - run: composer install --no-interaction --no-progress - - - name: Run Rector - run: php vendor/bin/rector -c .rector.php --dry-run diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2ba78cb..53d5172 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,16 +1,21 @@ setRiskyAllowed(true) ->setParallelConfig(new PhpCsFixer\Runner\Parallel\ParallelConfig()) ->setRules([ + // see https://cs.symfony.com/doc/ruleSets/PER-CS2.0.html '@PER-CS2.0' => true, + // RISKY: Use && and || logical operators instead of and and or. 'logical_operators' => true, + // RISKY: Replaces intval, floatval, doubleval, strval and boolval function calls with according type casting operator. 'modernize_types_casting' => true, + // PHP84: Adds or removes ? before single type declarations or |null at the end of union types when parameters have a default null value. 'nullable_type_declaration_for_default_null_value' => true, + // Convert double quotes to single quotes for simple strings. 'single_quote' => true, + // PHPdoc stuff 'phpdoc_indent' => true, 'phpdoc_param_order' => true, 'phpdoc_single_line_var_spacing' => true, @@ -19,8 +24,19 @@ ]) ->setFinder( PhpCsFixer\Finder::create() - ->in([__DIR__ . '/app']) - ->name(['*.php']) + // Same canonical list as the maho repo; only the dirs that exist in + // this repo are scanned, so the one config works for app-only modules. + ->in(array_values(array_filter([ + __DIR__ . '/app', + __DIR__ . '/lib', + __DIR__ . '/public', + __DIR__ . '/tests', + __DIR__ . '/src', + ], 'is_dir'))) + // Root-level entry points (e.g. the infra tool's sync.php / config.php). + // glob skips dotfiles, so these very config files aren't included. + ->append(glob(__DIR__ . '/*.php') ?: []) + ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true) ); diff --git a/.rector.php b/.rector.php index 0bed012..62e9abf 100644 --- a/.rector.php +++ b/.rector.php @@ -2,50 +2,65 @@ declare(strict_types=1); -use Rector\CodeQuality\Rector\BooleanNot\ReplaceMultipleBooleanNotRector; -use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; -use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; -use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; -use Rector\CodeQuality\Rector\Identical\SimplifyArraySearchRector; -use Rector\CodeQuality\Rector\Identical\SimplifyConditionsRector; -use Rector\CodeQuality\Rector\Identical\StrlenZeroToIdenticalEmptyStringRector; -use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector; -use Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector; -use Rector\CodeQuality\Rector\Ternary\SimplifyTautologyTernaryRector; -use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector; -use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; +use Rector\CodeQuality\Rector as CodeQuality; +use Rector\CodingStyle\Rector as CodingStyle; use Rector\Config\RectorConfig; -use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; -use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; -use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector; -use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; -use Rector\EarlyReturn\Rector\If_\ChangeNestedIfsToEarlyReturnRector; -use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; -use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector; -use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector; +use Rector\DeadCode\Rector as DeadCode; +use Rector\EarlyReturn\Rector as EarlyReturn; +use Rector\TypeDeclaration\Rector as TypeDeclaration; +// Shared by every repo that consumes the org baseline. Only standard Rector +// rules, so it needs no extra dependency: maho's own .rector.php (with the +// Maho\Rector\* rules and the Varien->Maho migration) stays in maho and is not +// synced. Only the paths that exist in a given repo are scanned, so the one +// config works for app-only modules and the infra tool's src/ alike. return RectorConfig::configure() - ->withPaths([__DIR__ . '/app']) - ->withPhpSets(php83: true) + ->withPaths(array_values(array_merge( + array_filter([ + __DIR__ . '/app', + __DIR__ . '/lib', + __DIR__ . '/public', + __DIR__ . '/src', + ], 'is_dir'), + // Root-level entry points (e.g. the infra tool's sync.php / config.php). + // glob skips dotfiles, so this very config file isn't included. + glob(__DIR__ . '/*.php') ?: [], + ))) + // No argument: Rector reads the target PHP version from composer.json + // (require.php's floor, else config.platform.php), kept at 8.3 by the sync. + ->withPhpSets() ->withRules([ - ReplaceMultipleBooleanNotRector::class, - UnusedForeachValueToArrayKeysRector::class, - ChangeArrayPushToArrayAssignRector::class, - CompactToVariablesRector::class, - SimplifyArraySearchRector::class, - SimplifyConditionsRector::class, - StrlenZeroToIdenticalEmptyStringRector::class, - CommonNotEqualRector::class, - LogicalToBooleanRector::class, - SimplifyTautologyTernaryRector::class, - SwitchNegatedTernaryRector::class, - MakeInheritedMethodVisibilitySameAsParentRector::class, - RemoveUselessParamTagRector::class, - RemoveUselessReturnTagRector::class, - RemoveNullArgOnNullDefaultParamRector::class, - RemoveUselessVarTagRector::class, - ChangeNestedIfsToEarlyReturnRector::class, - RemoveAlwaysElseRector::class, - AddOverrideAttributeToOverriddenMethodsRector::class, - DeclareStrictTypesRector::class, + CodeQuality\BooleanNot\ReplaceMultipleBooleanNotRector::class, + CodeQuality\Foreach_\UnusedForeachValueToArrayKeysRector::class, + CodeQuality\FuncCall\ChangeArrayPushToArrayAssignRector::class, + CodeQuality\FuncCall\CompactToVariablesRector::class, + CodeQuality\Identical\SimplifyArraySearchRector::class, + CodeQuality\Identical\SimplifyConditionsRector::class, + CodeQuality\Identical\StrlenZeroToIdenticalEmptyStringRector::class, + CodeQuality\LogicalAnd\LogicalToBooleanRector::class, + CodeQuality\NotEqual\CommonNotEqualRector::class, + CodeQuality\Ternary\SimplifyTautologyTernaryRector::class, + CodeQuality\Ternary\SwitchNegatedTernaryRector::class, + CodingStyle\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector::class, + DeadCode\ClassMethod\RemoveUselessParamTagRector::class, + DeadCode\ClassMethod\RemoveUselessReturnTagRector::class, + DeadCode\MethodCall\RemoveNullArgOnNullDefaultParamRector::class, + DeadCode\Property\RemoveUselessVarTagRector::class, + EarlyReturn\If_\ChangeNestedIfsToEarlyReturnRector::class, + EarlyReturn\If_\RemoveAlwaysElseRector::class, + Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector::class, + Rector\Php71\Rector\List_\ListToArrayDestructRector::class, + Rector\Php74\Rector\Assign\NullCoalescingOperatorRector::class, + Rector\Php80\Rector\Class_\StringableForToStringRector::class, + Rector\Php80\Rector\ClassConstFetch\ClassOnThisVariableObjectRector::class, + Rector\Php80\Rector\FuncCall\ClassOnObjectRector::class, + Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector::class, + Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector::class, + TypeDeclaration\ClassMethod\ReturnNeverTypeRector::class, + TypeDeclaration\StmtsAwareInterface\SafeDeclareStrictTypesRector::class, + ]) + ->withConfiguredRule(Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector::class, [ + 'sensitive_parameters' => [ + 'token', 'apiKey', 'email', 'useremail', 'username', 'password', + ], ]); diff --git a/composer.json b/composer.json index 7704e4a..54c125e 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,9 @@ "config": { "allow-plugins": { "mahocommerce/maho-composer-plugin": true + }, + "platform": { + "php": "8.3" } } }