Skip to content

Commit f8c0d51

Browse files
committed
- fixed PHP-CS-FiXER warnings
- added Rector command and in CI
1 parent b51f883 commit f8c0d51

File tree

5 files changed

+149
-2
lines changed

5 files changed

+149
-2
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ jobs:
2727

2828
- name: Run static type checks (PHPStan)
2929
run: vendor/bin/phpstan analyse src/ tests/
30+
31+
- name: Run code style latest (Rector)
32+
run: vendor/bin/rector process src --dry-run

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
"phpstan/phpstan-doctrine": "^2.0.3",
103103
"phpstan/phpstan-symfony": "^2.0.6",
104104
"phpunit/phpunit": "^12.2.2",
105+
"rector/rector": "^2.0",
105106
"symfony/browser-kit": "7.3.*",
106107
"symfony/css-selector": "7.3.*",
107108
"symfony/debug-bundle": "7.3.*",

composer.lock

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
if (!is_string($environment)) {
99
// we expect the environment variable to be a string, if not, we throw an error
1010
// Symfony's default cast non-string APP_ENV to string, but I changed it (mainly for PHPStan checks)
11-
die(sprintf('Error: APP_ENV environment variable must be a string, but got %s.', get_debug_type($environment)));
11+
exit(sprintf('Error: APP_ENV environment variable must be a string, but got %s.', get_debug_type($environment)));
1212
}
1313

1414
return function (array $context) use ($environment) {

rector.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Set\ValueObject\LevelSetList;
7+
use Rector\Set\ValueObject\SetList;
8+
use Rector\Symfony\Set\SymfonySetList;
9+
use Rector\Doctrine\Set\DoctrineSetList;
10+
use Rector\PHPUnit\Set\PHPUnitSetList;
11+
12+
return RectorConfig::configure()
13+
// Define paths to be analyzed by Rector
14+
->withPaths([
15+
__DIR__ . '/src',
16+
__DIR__ . '/tests',
17+
])
18+
19+
// For Symfony projects, load the container XML to enable smarter refactoring based on service definitions.
20+
// Adjust the path according to your Symfony version and environment.
21+
// Typically, it's located at var/cache/{env}/App_Kernel{Env}DebugContainer.xml
22+
->withSymfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml')
23+
24+
// Apply framework-specific rules based on Composer dependencies.
25+
// This enables automatic refactoring for frameworks like Symfony, Doctrine, etc., including version upgrades.
26+
->withComposerBased(
27+
symfony: true,
28+
doctrine: true,
29+
phpunit: true,
30+
twig: true
31+
)
32+
33+
// Apply common code quality improvements and PHP version upgrade sets.
34+
// withPreparedSets() offers a concise way to enable frequently used rule sets.
35+
->withPreparedSets(
36+
deadCode: true,
37+
codeQuality: true,
38+
codingStyle: true,
39+
typeDeclarations: true,
40+
privatization: true,
41+
)
42+
43+
// Apply rule sets tailored to the latest PHP version.
44+
// Choose the appropriate LevelSetList for your project's PHP version (e.g., LevelSetList::UP_TO_PHP_84).
45+
// withSets() is used to explicitly add specific sets not covered by withPreparedSets().
46+
->withSets([
47+
LevelSetList::UP_TO_PHP_84,
48+
// SetList::EARLY_RETURN, // Example: Enable early return refactoring
49+
// SetList::INSTANCEOF, // Example: Optimize instanceof checks
50+
// SetList::STRICT_BOOLEANS, // Example: Enforce strict boolean usage
51+
// ---------------------------------------------
52+
SymfonySetList::CONFIGS,
53+
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES, // Example: Convert Symfony annotations to PHP attributes
54+
SymfonySetList::SYMFONY_CODE_QUALITY,
55+
SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
56+
// SymfonySetList::SYMFONY_73, // Example: Specific Symfony 7.3 upgrade rules if needed
57+
// ---------------------------------------------
58+
DoctrineSetList::DOCTRINE_CODE_QUALITY,
59+
// ---------------------------------------------
60+
PHPUnitSetList::PHPUNIT_120, // Example: PHPUnit 12.0 upgrade rules
61+
])
62+
63+
// Convert annotations to native PHP attributes (for PHP 8.0+).
64+
// This is useful for migrating from Doctrine or Symfony annotations.
65+
->withAttributesSets(
66+
doctrine: true,
67+
symfony: true,
68+
)
69+
70+
// Add individual Rector rules as needed
71+
// ->withRules([
72+
// YourCustomRectorRule::class,
73+
// ])
74+
75+
// Optimize import statements (sort and remove unused 'use' statements)
76+
->withImportNames()
77+
78+
// Exclude specific files or directories from analysis
79+
->withSkip([
80+
// __DIR__ . '/src/SomeLegacyCode.php',
81+
// SetList::DEAD_CODE => [
82+
// __DIR__ . '/src/SpecificFileWithFalsePositive.php',
83+
// ],
84+
]);

0 commit comments

Comments
 (0)