Skip to content

Commit 261d493

Browse files
committed
Merge branch 'rector'
2 parents 7884164 + b3c337a commit 261d493

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+230
-79
lines changed

.github/workflows/linting.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ jobs:
6363
# if: always() && steps.composer-install.outcome == 'success'
6464
# run: bin/console lint:xliff translations --ansi
6565

66+
rector:
67+
name: Rector
68+
69+
runs-on: ubuntu-latest
70+
71+
steps:
72+
- name: Checkout code
73+
uses: actions/checkout@v4
74+
75+
- name: Install PHP with extensions
76+
uses: shivammathur/setup-php@v2
77+
with:
78+
php-version: 8.3
79+
tools: composer:v2
80+
81+
- name: Set Composer cache directory
82+
id: composer-cache
83+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
84+
85+
- name: Cache Composer output
86+
uses: actions/cache@v4
87+
with:
88+
path: ${{ steps.composer-cache.outputs.dir }}
89+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
90+
restore-keys: ${{ runner.os }}-composer-
91+
92+
- name: Install Composer dependencies
93+
run: composer install --ansi --no-interaction --no-progress
94+
95+
- name: Run Rector
96+
run: vendor/bin/rector process --dry-run --ansi --no-progress-bar
97+
6698
php-cs-fixer:
6799
name: PHP-CS-Fixer
68100

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"friendsofphp/php-cs-fixer": "^3.75",
6565
"phpstan/phpstan": "^2.1",
6666
"phpunit/phpunit": "^12.4",
67+
"rector/rector": "^2.3",
6768
"symfony/browser-kit": "^7.3",
6869
"symfony/css-selector": "^7.3",
6970
"symfony/debug-bundle": "^7.3",
@@ -110,6 +111,7 @@
110111
],
111112
"build:standalone": "docker build . -t dirigent-standalone",
112113
"lint": [
114+
"@lint:refactor",
113115
"@lint:coding-style",
114116
"@lint:static-analysis",
115117
"@lint:composer",
@@ -121,6 +123,7 @@
121123
"lint:coding-style": "vendor/bin/php-cs-fixer fix --diff",
122124
"lint:composer": "composer validate",
123125
"lint:container": "bin/console lint:container",
126+
"lint:refactor": "vendor/bin/rector process",
124127
"lint:static-analysis": "vendor/bin/phpstan analyze",
125128
"lint:templates": "bin/console lint:twig templates",
126129
"lint:translations": "bin/console lint:translations",
@@ -146,10 +149,11 @@
146149
"scripts-descriptions": {
147150
"build:standalone": "Build the standalone image",
148151
"lint": "Perform all linting validations",
149-
"lint:coding-style": "Validate the code style of the PHP code",
152+
"lint:coding-style": "Validate the code style of the PHP code (using PHP-CS-Fixer)",
150153
"lint:composer": "Validate the Composer configuration",
151154
"lint:container": "Validate the Symfony container configuration",
152-
"lint:static-analysis": "Run static analysis on the PHP code",
155+
"lint:refactor": "Run automated code refactoring (using Rector)",
156+
"lint:static-analysis": "Run static analysis on the PHP code (using PHPStan)",
153157
"lint:templates": "Validate the Twig templates",
154158
"lint:translations": "Validate the translations",
155159
"lint:yaml": "Validate YAML files",

composer.lock

Lines changed: 62 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rector.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
7+
8+
return RectorConfig::configure()
9+
->withCache(__DIR__ . '/var/cache/rector')
10+
->withRootFiles()
11+
->withPaths([
12+
__DIR__ . '/bin',
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
])
16+
->withImportNames(importShortClasses: false)
17+
->withPhpSets()
18+
->withComposerBased(
19+
twig: true,
20+
doctrine: true,
21+
phpunit: true,
22+
symfony: true,
23+
)
24+
->withAttributesSets(
25+
symfony: true,
26+
doctrine: true,
27+
phpunit: true,
28+
)
29+
->withSkip([
30+
// Exclude promotion of properties to the constructor for Doctrine entities
31+
ClassPropertyAssignToConstructorPromotionRector::class => [__DIR__ . '/src/Doctrine/Entity'],
32+
]);

src/ConsoleApplication.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ class ConsoleApplication extends Application
1212
private bool $commandsRegistered = false;
1313

1414
public function __construct(
15-
private KernelInterface $kernel,
15+
private readonly KernelInterface $kernel,
1616
) {
1717
parent::__construct('Dirigent', Kernel::VERSION);
1818
}
1919

20+
#[\Override]
2021
public function doRun(InputInterface $input, OutputInterface $output): int
2122
{
2223
$this->registerCommands();

src/Controller/ApiController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,7 @@ public function packageDistribution(Request $request, string $reference, string
152152
public function trackInstallations(Request $request): Response
153153
{
154154
$contents = json_decode($request->getContent(), true);
155-
$invalidInputs = static function ($item) {
156-
return !isset($item['name'], $item['version']);
157-
};
155+
$invalidInputs = static fn ($item) => !isset($item['name'], $item['version']);
158156

159157
if (!is_array($contents) || !isset($contents['downloads']) || !is_array($contents['downloads']) || array_filter($contents['downloads'], $invalidInputs)) {
160158
return new JsonResponse(['status' => 'error', 'message' => 'Invalid request format, must be a json object containing a downloads key filled with an array of name/version objects'], 200);

src/Controller/Dashboard/DashboardAccessTokenController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static function getSubscribedEvents(): array
3535
];
3636
}
3737

38+
#[\Override]
3839
public function configureCrud(Crud $crud): Crud
3940
{
4041
return $crud
@@ -43,19 +44,22 @@ public function configureCrud(Crud $crud): Crud
4344
->overrideTemplate('crud/index', 'dashboard/access_token/index.html.twig');
4445
}
4546

47+
#[\Override]
4648
public function configureActions(Actions $actions): Actions
4749
{
4850
return $actions
4951
->remove(Crud::PAGE_INDEX, Action::EDIT)
5052
->remove(Crud::PAGE_NEW, Action::SAVE_AND_ADD_ANOTHER);
5153
}
5254

55+
#[\Override]
5356
public function configureFields(string $pageName): iterable
5457
{
5558
yield TextField::new('name');
5659
yield DateTimeField::new('expiresAt');
5760
}
5861

62+
#[\Override]
5963
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
6064
{
6165
/** @var User $user */

src/Controller/Dashboard/DashboardCredentialsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static function getEntityFqcn(): string
1919
return Credentials::class;
2020
}
2121

22+
#[\Override]
2223
public function configureCrud(Crud $crud): Crud
2324
{
2425
return parent::configureCrud($crud)
@@ -27,6 +28,7 @@ public function configureCrud(Crud $crud): Crud
2728
->overrideTemplate('layout', 'dashboard/credentials/layout.html.twig');
2829
}
2930

31+
#[\Override]
3032
public function configureFields(string $pageName): iterable
3133
{
3234
yield TextField::new('name');
@@ -36,9 +38,7 @@ public function configureFields(string $pageName): iterable
3638
->setTemplatePath('dashboard/fields/credentials_type.html.twig')
3739
->setRequired(true)
3840
->setChoices(CredentialsType::cases())
39-
->setFormTypeOption('choice_label', static function (CredentialsType $choice): string {
40-
return "credentials.type.{$choice->value}";
41-
})
41+
->setFormTypeOption('choice_label', static fn (CredentialsType $choice): string => "credentials.type.{$choice->value}")
4242
->renderExpanded();
4343
yield TextField::new('username')
4444
->setFormTypeOption('row_attr', ['data-credentials-field' => 'username'])

src/Controller/Dashboard/DashboardPackagesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function addMirroring(Request $request): Response
6464
if ($form->isSubmitted() && $form->isValid()) {
6565
$registry = $form->get('registry')->getData();
6666

67-
$packageNamesInput = $form->get('packages')->getData();
67+
$packageNamesInput = (string) $form->get('packages')->getData();
6868
$packageNames = preg_split('#(\s|,)+#', $packageNamesInput);
6969

7070
$results = [];

src/Controller/Dashboard/DashboardRegistryController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public static function getEntityFqcn(): string
2828
return Registry::class;
2929
}
3030

31+
#[\Override]
3132
public function configureCrud(Crud $crud): Crud
3233
{
3334
return $crud
@@ -36,6 +37,7 @@ public function configureCrud(Crud $crud): Crud
3637
->setEntityPermission('ROLE_ADMIN');
3738
}
3839

40+
#[\Override]
3941
public function configureActions(Actions $actions): Actions
4042
{
4143
$upAction = Action::new('moveUp', icon: 'fa fa-arrow-up')
@@ -48,6 +50,7 @@ public function configureActions(Actions $actions): Actions
4850
->add(Crud::PAGE_INDEX, $upAction);
4951
}
5052

53+
#[\Override]
5154
public function configureFields(string $pageName): iterable
5255
{
5356
yield TextField::new('name')
@@ -69,9 +72,7 @@ public function configureFields(string $pageName): iterable
6972
->setTemplatePath('dashboard/fields/registry_package_mirroring.html.twig')
7073
->setRequired(true)
7174
->setChoices(RegistryPackageMirroring::cases())
72-
->setFormTypeOption('choice_label', static function (RegistryPackageMirroring $choice): string {
73-
return "registry.package-mirroring.{$choice->value}";
74-
})
75+
->setFormTypeOption('choice_label', static fn (RegistryPackageMirroring $choice): string => "registry.package-mirroring.{$choice->value}")
7576
->renderExpanded();
7677

7778
yield DateIntervalField::new('dynamicUpdateDelay')

0 commit comments

Comments
 (0)