Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add psalm in all code dirs #355

Merged
merged 10 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
push:
branches:
- master
- main
pull_request:

jobs:
Expand All @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- run: docker-compose pull
- run: docker compose pull

- name: 🎻 Install dependencies
run: make composer-install
Expand All @@ -35,14 +35,14 @@ jobs:
sleep 2
done

- name: 🧪 Wait for the elasticsearch to get up
- name: 🧪 Wait for the Elasticsearch to get up
run: |
while ! make ping-elasticsearch &>/dev/null; do
echo "Waiting for elasticsearch connection..."
sleep 2
done

- name: 🐰 Wait for the message broker to get up
- name: 🐰 Wait for RabbitMQ to get up
run: |
while ! make ping-rabbitmq &>/dev/null; do
echo "Waiting for RabbitMQ connection..."
Expand Down
82 changes: 15 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,100 +1,48 @@
current-dir := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

.PHONY: build
build: deps start

.PHONY: deps
deps: composer-install

# 🐘 Composer
composer-env-file:
@if [ ! -f .env.local ]; then echo '' > .env.local; fi

.PHONY: composer-install
composer-install: CMD=install

.PHONY: composer-update
composer-update: CMD=update

.PHONY: composer-require
composer-require: CMD=require
composer-require: INTERACTIVE=-ti --interactive

.PHONY: composer-require-module
composer-require-module: CMD=require $(module)
composer-require-module: INTERACTIVE=-ti --interactive

.PHONY: composer
composer composer-install composer-update composer-require composer-require-module: composer-env-file
composer-install:
@docker run --rm $(INTERACTIVE) --volume $(current-dir):/app --user $(id -u):$(id -g) \
composer:2.3.7 $(CMD) \
composer:2.6.4 install \
--ignore-platform-reqs \
--no-ansi

.PHONY: reload
reload: composer-env-file
@docker-compose exec php-fpm kill -USR2 1
@docker-compose exec nginx nginx -s reload

.PHONY: test
test: composer-env-file
test:
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite mooc
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpunit --testsuite shared
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/behat -p mooc_backend --format=progress -v
docker exec codely-php_ddd_skeleton-backoffice_backend-php ./vendor/bin/phpunit --testsuite backoffice

.PHONY: static-analysis
static-analysis: composer-env-file
static-analysis:
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/psalm

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

.PHONY: run-tests
run-tests: composer-env-file
mkdir -p build/test_results/phpunit
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite backoffice
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite mooc
./vendor/bin/phpunit --exclude-group='disabled' --log-junit build/test_results/phpunit/junit.xml --testsuite shared
./vendor/bin/behat -p mooc_backend --format=progress -v

# 🐳 Docker Compose
.PHONY: start
start: CMD=up --build -d

.PHONY: stop
stop: CMD=stop
start:
@if [ ! -f .env.local ]; then echo '' > .env.local; fi
UID=${shell id -u} GID=${shell id -g} docker compose up --build -d
make clean-cache

.PHONY: destroy
destroy: CMD=down
stop:
UID=${shell id -u} GID=${shell id -g} docker compose stop

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

.PHONY: rebuild
rebuild: composer-env-file
docker-compose build --pull --force-rm --no-cache
make deps
rebuild:
docker compose build --pull --force-rm --no-cache
make install
make start

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

.PHONY: ping-elasticsearch
ping-elasticsearch:
@curl -I -XHEAD localhost:9200

.PHONY: ping-rabbitmq
ping-rabbitmq:
@docker exec codely-php_ddd_skeleton-rabbitmq rabbitmqctl ping --silent

clean-cache:
@rm -rf apps/*/*/var
@docker exec codely-php_ddd_skeleton-backoffice_backend-php ./apps/backoffice/backend/bin/console cache:warmup
@docker exec codely-php_ddd_skeleton-backoffice_frontend-php ./apps/backoffice/frontend/bin/console cache:warmup
@docker exec codely-php_ddd_skeleton-mooc_backend-php ./apps/mooc/backend/bin/console cache:warmup
2 changes: 1 addition & 1 deletion apps/backoffice/backend/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {

set_time_limit(0);

require dirname(__DIR__) . '../../../vendor/autoload.php';
require dirname(__DIR__) . '/../../../vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
Expand Down
4 changes: 2 additions & 2 deletions apps/backoffice/backend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', (string) $trustedProxies),
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
explode(',', $trustedProxies),
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/backoffice/frontend/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {

set_time_limit(0);

require dirname(__DIR__) . '../../../vendor/autoload.php';
require dirname(__DIR__) . '/../../../vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
Expand Down
4 changes: 2 additions & 2 deletions apps/backoffice/frontend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', (string) $trustedProxies),
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
explode(',', $trustedProxies),
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}

Expand Down
15 changes: 1 addition & 14 deletions apps/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,7 @@

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

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

$_SERVER += $_ENV;
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
Expand Down
2 changes: 1 addition & 1 deletion apps/mooc/backend/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {

set_time_limit(0);

require dirname(__DIR__) . '../../../vendor/autoload.php';
require dirname(__DIR__) . '/../../../vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
Expand Down
4 changes: 2 additions & 2 deletions apps/mooc/backend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(
explode(',', (string) $trustedProxies),
Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST
explode(',', $trustedProxies),
Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
);
}

Expand Down
6 changes: 5 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
__DIR__ . '/apps/backoffice/frontend/src/BackofficeFrontendKernel.php',
__DIR__ . '/apps/mooc/backend/src/MoocBackendKernel.php',
__DIR__ . '/src/Shared/Infrastructure/Bus/Event/InMemory/InMemorySymfonyEventBus.php',
]
],
__DIR__ . '/apps/backoffice/backend/var',
__DIR__ . '/apps/backoffice/frontend/var',
__DIR__ . '/apps/mooc/backend/var',
__DIR__ . '/apps/mooc/frontend/var',
]);
};
6 changes: 2 additions & 4 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
findUnusedCode="false"
>
<projectFiles>
<directory name="apps/backoffice/backend/src" />
<directory name="apps/backoffice/frontend/src" />
<directory name="apps/mooc/backend/src" />
<directory name="apps/mooc/frontend/src" />
<directory name="apps" />
<directory name="src" />
<directory name="tests" />
<ignoreFiles>
<directory name="apps/*/*/var" />
<directory name="vendor" />
<directory name="src/Shared/Infrastructure/Bus/Event/RabbitMq" />
<directory name="src/Shared/Infrastructure/Symfony" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AMQPEnvelope;
use AMQPQueue;
use AMQPQueueException;
use CodelyTv\Shared\Domain\Bus\Event\DomainEventSubscriber;
use CodelyTv\Shared\Infrastructure\Bus\Event\DomainEventJsonDeserializer;
use Throwable;

Expand All @@ -22,7 +23,7 @@ public function __construct(
private int $maxRetries
) {}

public function consume(callable $subscriber, string $queueName): void
public function consume(callable|DomainEventSubscriber $subscriber, string $queueName): void
{
try {
$this->connection->queue($queueName)->consume($this->consumer($subscriber));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware;
use Symfony\Component\Messenger\Stamp\HandledStamp;

final class InMemorySymfonyQueryBus implements QueryBus
final readonly class InMemorySymfonyQueryBus implements QueryBus
{
private readonly MessageBus $bus;
private MessageBus $bus;

public function __construct(iterable $queryHandlers)
{
Expand Down
2 changes: 2 additions & 0 deletions tests/Shared/Infrastructure/PhpUnit/UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\Matcher\MatcherAbstract;
use Mockery\MockInterface;
use Throwable;

abstract class UnitTestCase extends MockeryTestCase
{
Expand Down Expand Up @@ -78,6 +79,7 @@ protected function assertAskResponse(Response $expected, Query $query, callable
$this->assertEquals($expected, $actual);
}

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