Skip to content

Commit 23a2319

Browse files
authored
chore: add psalm in all code dirs (#355)
* chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs * chore: add psalm in all code dirs
1 parent 835bc68 commit 23a2319

File tree

14 files changed

+43
-103
lines changed

14 files changed

+43
-103
lines changed

Diff for: .github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
pull_request:
88

99
jobs:
@@ -12,9 +12,9 @@ jobs:
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v4
1616

17-
- run: docker-compose pull
17+
- run: docker compose pull
1818

1919
- name: 🎻 Install dependencies
2020
run: make composer-install
@@ -35,14 +35,14 @@ jobs:
3535
sleep 2
3636
done
3737
38-
- name: 🧪 Wait for the elasticsearch to get up
38+
- name: 🧪 Wait for the Elasticsearch to get up
3939
run: |
4040
while ! make ping-elasticsearch &>/dev/null; do
4141
echo "Waiting for elasticsearch connection..."
4242
sleep 2
4343
done
4444
45-
- name: 🐰 Wait for the message broker to get up
45+
- name: 🐰 Wait for RabbitMQ to get up
4646
run: |
4747
while ! make ping-rabbitmq &>/dev/null; do
4848
echo "Waiting for RabbitMQ connection..."

Diff for: Makefile

+15-67
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,48 @@
11
current-dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
22

3-
.PHONY: build
4-
build: deps start
5-
6-
.PHONY: deps
7-
deps: composer-install
8-
9-
# 🐘 Composer
10-
composer-env-file:
11-
@if [ ! -f .env.local ]; then echo '' > .env.local; fi
12-
13-
.PHONY: composer-install
14-
composer-install: CMD=install
15-
16-
.PHONY: composer-update
17-
composer-update: CMD=update
18-
19-
.PHONY: composer-require
20-
composer-require: CMD=require
21-
composer-require: INTERACTIVE=-ti --interactive
22-
23-
.PHONY: composer-require-module
24-
composer-require-module: CMD=require $(module)
25-
composer-require-module: INTERACTIVE=-ti --interactive
26-
27-
.PHONY: composer
28-
composer composer-install composer-update composer-require composer-require-module: composer-env-file
3+
composer-install:
294
@docker run --rm $(INTERACTIVE) --volume $(current-dir):/app --user $(id -u):$(id -g) \
30-
composer:2.3.7 $(CMD) \
5+
composer:2.6.4 install \
316
--ignore-platform-reqs \
327
--no-ansi
338

34-
.PHONY: reload
35-
reload: composer-env-file
36-
@docker-compose exec php-fpm kill -USR2 1
37-
@docker-compose exec nginx nginx -s reload
38-
39-
.PHONY: test
40-
test: composer-env-file
9+
test:
4110
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite mooc
4211
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite shared
4312
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/behat -p mooc_backend --format=progress -v
4413
docker exec codely-php_ddd_skeleton-backoffice_backend-php ./vendor/bin/phpunit --testsuite backoffice
4514

46-
.PHONY: static-analysis
47-
static-analysis: composer-env-file
15+
static-analysis:
4816
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/psalm
4917

50-
.PHONY: lint
5118
lint:
5219
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/ecs check
5320

54-
.PHONY: run-tests
55-
run-tests: composer-env-file
56-
mkdir -p build/test_results/phpunit
57-
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite backoffice
58-
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite mooc
59-
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite shared
60-
./vendor/bin/behat -p mooc_backend --format=progress -v
61-
62-
# 🐳 Docker Compose
63-
.PHONY: start
64-
start: CMD=up --build -d
65-
66-
.PHONY: stop
67-
stop: CMD=stop
21+
start:
22+
@if [ ! -f .env.local ]; then echo '' > .env.local; fi
23+
UID=${shell id -u} GID=${shell id -g} docker compose up --build -d
24+
make clean-cache
6825

69-
.PHONY: destroy
70-
destroy: CMD=down
26+
stop:
27+
UID=${shell id -u} GID=${shell id -g} docker compose stop
7128

72-
# Usage: `make doco CMD="ps --services"`
73-
# Usage: `make doco CMD="build --parallel --pull --force-rm --no-cache"`
74-
.PHONY: doco
75-
doco start stop destroy: composer-env-file
76-
UID=${shell id -u} GID=${shell id -g} docker-compose $(CMD)
29+
destroy:
30+
UID=${shell id -u} GID=${shell id -g} docker compose down
7731

78-
.PHONY: rebuild
79-
rebuild: composer-env-file
80-
docker-compose build --pull --force-rm --no-cache
81-
make deps
32+
rebuild:
33+
docker compose build --pull --force-rm --no-cache
34+
make install
8235
make start
8336

84-
.PHONY: ping-mysql
8537
ping-mysql:
8638
@docker exec codely-php_ddd_skeleton-mooc-mysql mysqladmin --user=root --password= --host "127.0.0.1" ping --silent
8739

88-
.PHONY: ping-elasticsearch
8940
ping-elasticsearch:
9041
@curl -I -XHEAD localhost:9200
9142

92-
.PHONY: ping-rabbitmq
9343
ping-rabbitmq:
9444
@docker exec codely-php_ddd_skeleton-rabbitmq rabbitmqctl ping --silent
9545

9646
clean-cache:
9747
@rm -rf apps/*/*/var
98-
@docker exec codely-php_ddd_skeleton-backoffice_backend-php ./apps/backoffice/backend/bin/console cache:warmup
99-
@docker exec codely-php_ddd_skeleton-backoffice_frontend-php ./apps/backoffice/frontend/bin/console cache:warmup
10048
@docker exec codely-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console cache:warmup

Diff for: apps/backoffice/backend/bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
1212

1313
set_time_limit(0);
1414

15-
require dirname(__DIR__) . '../../../vendor/autoload.php';
15+
require dirname(__DIR__) . '/../../../vendor/autoload.php';
1616

1717
if (!class_exists(Application::class)) {
1818
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');

Diff for: apps/backoffice/backend/public/index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
1818
Request::setTrustedProxies(
19-
explode(',', (string) $trustedProxies),
20-
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
19+
explode(',', $trustedProxies),
20+
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
2121
);
2222
}
2323

Diff for: apps/backoffice/frontend/bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
1212

1313
set_time_limit(0);
1414

15-
require dirname(__DIR__) . '../../../vendor/autoload.php';
15+
require dirname(__DIR__) . '/../../../vendor/autoload.php';
1616

1717
if (!class_exists(Application::class)) {
1818
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');

Diff for: apps/backoffice/frontend/public/index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
1818
Request::setTrustedProxies(
19-
explode(',', (string) $trustedProxies),
20-
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
19+
explode(',', $trustedProxies),
20+
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
2121
);
2222
}
2323

Diff for: apps/bootstrap.php

+1-14
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,7 @@
88

99
require $rootPath . '/vendor/autoload.php';
1010

11-
// Load cached env vars if the .env.local.php file exists
12-
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
13-
if (is_array($env = @include $rootPath . '/.env.local.php')) {
14-
foreach ($env as $k => $v) {
15-
$_ENV[$k] ??= isset($_SERVER[$k]) && str_starts_with($k, 'HTTP_') ? $_SERVER[$k] : $v;
16-
}
17-
} elseif (!class_exists(Dotenv::class)) {
18-
throw new RuntimeException(
19-
'Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'
20-
);
21-
} else {
22-
// load all the .env files
23-
(new Dotenv())->loadEnv($rootPath . '/.env');
24-
}
11+
(new Dotenv())->loadEnv($rootPath . '/.env');
2512

2613
$_SERVER += $_ENV;
2714
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';

Diff for: apps/mooc/backend/bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
1212

1313
set_time_limit(0);
1414

15-
require dirname(__DIR__) . '../../../vendor/autoload.php';
15+
require dirname(__DIR__) . '/../../../vendor/autoload.php';
1616

1717
if (!class_exists(Application::class)) {
1818
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');

Diff for: apps/mooc/backend/public/index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
1818
Request::setTrustedProxies(
19-
explode(',', (string) $trustedProxies),
20-
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
19+
explode(',', $trustedProxies),
20+
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
2121
);
2222
}
2323

Diff for: ecs.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@
132132
__DIR__ . '/apps/backoffice/frontend/src/BackofficeFrontendKernel.php',
133133
__DIR__ . '/apps/mooc/backend/src/MoocBackendKernel.php',
134134
__DIR__ . '/src/Shared/Infrastructure/Bus/Event/InMemory/InMemorySymfonyEventBus.php',
135-
]
135+
],
136+
__DIR__ . '/apps/backoffice/backend/var',
137+
__DIR__ . '/apps/backoffice/frontend/var',
138+
__DIR__ . '/apps/mooc/backend/var',
139+
__DIR__ . '/apps/mooc/frontend/var',
136140
]);
137141
};

Diff for: psalm.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
findUnusedCode="false"
1010
>
1111
<projectFiles>
12-
<directory name="apps/backoffice/backend/src" />
13-
<directory name="apps/backoffice/frontend/src" />
14-
<directory name="apps/mooc/backend/src" />
15-
<directory name="apps/mooc/frontend/src" />
12+
<directory name="apps" />
1613
<directory name="src" />
1714
<directory name="tests" />
1815
<ignoreFiles>
16+
<directory name="apps/*/*/var" />
1917
<directory name="vendor" />
2018
<directory name="src/Shared/Infrastructure/Bus/Event/RabbitMq" />
2119
<directory name="src/Shared/Infrastructure/Symfony" />

Diff for: src/Shared/Infrastructure/Bus/Event/RabbitMq/RabbitMqDomainEventsConsumer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use AMQPEnvelope;
88
use AMQPQueue;
99
use AMQPQueueException;
10+
use CodelyTv\Shared\Domain\Bus\Event\DomainEventSubscriber;
1011
use CodelyTv\Shared\Infrastructure\Bus\Event\DomainEventJsonDeserializer;
1112
use Throwable;
1213

@@ -22,7 +23,7 @@ public function __construct(
2223
private int $maxRetries
2324
) {}
2425

25-
public function consume(callable $subscriber, string $queueName): void
26+
public function consume(callable|DomainEventSubscriber $subscriber, string $queueName): void
2627
{
2728
try {
2829
$this->connection->queue($queueName)->consume($this->consumer($subscriber));

Diff for: src/Shared/Infrastructure/Bus/Query/InMemorySymfonyQueryBus.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
1515
use Symfony\Component\Messenger\Stamp\HandledStamp;
1616

17-
final class InMemorySymfonyQueryBus implements QueryBus
17+
final readonly class InMemorySymfonyQueryBus implements QueryBus
1818
{
19-
private readonly MessageBus $bus;
19+
private MessageBus $bus;
2020

2121
public function __construct(iterable $queryHandlers)
2222
{

Diff for: tests/Shared/Infrastructure/PhpUnit/UnitTestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Mockery\Adapter\Phpunit\MockeryTestCase;
1616
use Mockery\Matcher\MatcherAbstract;
1717
use Mockery\MockInterface;
18+
use Throwable;
1819

1920
abstract class UnitTestCase extends MockeryTestCase
2021
{
@@ -78,6 +79,7 @@ protected function assertAskResponse(Response $expected, Query $query, callable
7879
$this->assertEquals($expected, $actual);
7980
}
8081

82+
/** @param class-string<Throwable> $expectedErrorClass */
8183
protected function assertAskThrowsException(string $expectedErrorClass, Query $query, callable $queryHandler): void
8284
{
8385
$this->expectException($expectedErrorClass);

0 commit comments

Comments
 (0)