Skip to content

Commit 523563a

Browse files
authored
ci: add lint (#312)
* feat: add php cs fixer * feat: pass php cs fixer * ci: add lint step
1 parent 98ec963 commit 523563a

File tree

119 files changed

+660
-241
lines changed

Some content is hidden

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

119 files changed

+660
-241
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: 🐳 Start all the environment
2323
run: make start
2424

25+
- name: 🔦 Lint
26+
run: make lint
27+
2528
- name: 🏁 Static analysis
2629
run: make static-analysis
2730

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
.phpunit.result.cache
1111

1212
/build
13+
14+
.php-cs-fixer.cache

.php-cs-fixer.dist.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()->in(
4+
[
5+
__DIR__ . '/apps/backoffice/backend/src',
6+
__DIR__ . '/apps/backoffice/frontend/src',
7+
__DIR__ . '/apps/mooc/backend/src',
8+
__DIR__ . '/apps/mooc/frontend/src',
9+
__DIR__ . '/src',
10+
__DIR__ . '/tests',
11+
]
12+
);
13+
14+
$config = new PhpCsFixer\Config();
15+
16+
return $config->setRules(
17+
[
18+
'@PSR12' => true,
19+
'strict_param' => true,
20+
'modernize_strpos' => true,
21+
'array_syntax' => ['syntax' => 'short'],
22+
]
23+
)->setFinder($finder);

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ test: composer-env-file
4747
static-analysis: composer-env-file
4848
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/psalm
4949

50+
.PHONY: lint
51+
lint:
52+
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/php-cs-fixer fix --config .php-cs-fixer.dist.php --allow-risky=yes --dry-run
53+
5054
.PHONY: run-tests
5155
run-tests: composer-env-file
5256
mkdir -p build/test_results/phpunit

apps/backoffice/backend/src/Controller/Courses/CoursesGetController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public function __invoke(Request $request): JsonResponse
3030
new SearchBackofficeCoursesByCriteriaQuery(
3131
(array) $request->query->get('filters'),
3232
null === $orderBy ? null : (string) $orderBy,
33-
null === $order ? null: (string) $order,
33+
null === $order ? null : (string) $order,
3434
null === $limit ? null : (int) $limit,
3535
null === $offset ? null : (int) $offset
3636
)
3737
);
3838

3939
return new JsonResponse(
4040
map(
41-
fn(BackofficeCourseResponse $course) => [
41+
fn (BackofficeCourseResponse $course) => [
4242
'id' => $course->id(),
4343
'name' => $course->name(),
4444
'duration' => $course->duration(),

apps/mooc/backend/src/Command/DomainEvents/MySql/ConsumeMySqlDomainEventsCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3737
{
3838
$quantityEventsToProcess = (int) $input->getArgument('quantity');
3939

40-
$consumer = pipe($this->consumer(), fn() => $this->connections->clear());
40+
$consumer = pipe($this->consumer(), fn () => $this->connections->clear());
4141

4242
$this->consumer->consume($consumer, $quantityEventsToProcess);
4343

@@ -46,8 +46,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4646

4747
private function consumer(): callable
4848
{
49-
return function (DomainEvent $domainEvent) {
50-
$subscribers = $this->subscriberLocator->allSubscribedTo(get_class($domainEvent));
49+
return function (DomainEvent $domainEvent): void {
50+
$subscribers = $this->subscriberLocator->allSubscribedTo($domainEvent::class);
5151

5252
foreach ($subscribers as $subscriber) {
5353
$subscriber($domainEvent);

apps/mooc/backend/src/Command/DomainEvents/RabbitMq/ConsumeRabbitMqDomainEventsCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4545

4646
private function consumer(string $queueName): callable
4747
{
48-
return function () use ($queueName) {
48+
return function () use ($queueName): void {
4949
$subscriber = $this->locator->withRabbitMqQueueNamed($queueName);
5050

5151
$this->consumer->consume($subscriber, $queueName);

apps/mooc/backend/src/Command/DomainEvents/RabbitMq/GenerateSupervisorRabbitMqConsumerFilesCommand.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4343

4444
private function configCreator(string $path): callable
4545
{
46-
return function (DomainEventSubscriber $subscriber) use ($path) {
46+
return function (DomainEventSubscriber $subscriber) use ($path): void {
4747
$queueName = RabbitMqQueueNameFormatter::format($subscriber);
4848
$subscriberName = RabbitMqQueueNameFormatter::shortFormat($subscriber);
4949

@@ -72,16 +72,16 @@ private function configCreator(string $path): callable
7272
private function template(): string
7373
{
7474
return <<<EOF
75-
[program:codelytv_{queue_name}]
76-
command = {path}/apps/mooc/backend/bin/console codelytv:domain-events:rabbitmq:consume --env=prod {queue_name} {events_to_process}
77-
process_name = %(program_name)s_%(process_num)02d
78-
numprocs = {processes}
79-
startsecs = 1
80-
startretries = 10
81-
exitcodes = 2
82-
stopwaitsecs = 300
83-
autostart = true
84-
EOF;
75+
[program:codelytv_{queue_name}]
76+
command = {path}/apps/mooc/backend/bin/console codelytv:domain-events:rabbitmq:consume --env=prod {queue_name} {events_to_process}
77+
process_name = %(program_name)s_%(process_num)02d
78+
numprocs = {processes}
79+
startsecs = 1
80+
startretries = 10
81+
exitcodes = 2
82+
stopwaitsecs = 300
83+
autostart = true
84+
EOF;
8585
}
8686

8787
private function fileName(string $queue): string

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"fakerphp/faker": "^1",
5252

5353
"symfony/error-handler": "^6",
54-
"vimeo/psalm": "^4"
54+
"vimeo/psalm": "^4",
55+
"friendsofphp/php-cs-fixer": "^3.8"
5556
},
5657
"autoload": {
5758
"psr-4": {

0 commit comments

Comments
 (0)