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

feat: update codely coding standard #367

Merged
merged 1 commit into from
Oct 23, 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
6 changes: 3 additions & 3 deletions apps/backoffice/backend/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
// WouterJ\EloquentBundle\WouterJEloquentBundle::class => ['test' => true]
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
// WouterJ\EloquentBundle\WouterJEloquentBundle::class => ['test' => true]
];
14 changes: 7 additions & 7 deletions apps/backoffice/backend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
require dirname(__DIR__) . '/../../bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);
umask(0000);

Debug::enable();
Debug::enable();
}

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

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new BackofficeBackendKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
Expand Down
58 changes: 29 additions & 29 deletions apps/backoffice/backend/src/BackofficeBackendKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@

class BackofficeBackendKernel extends Kernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';

public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getProjectDir(): string
{
return dirname(__DIR__);
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';

$loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services/*' . self::CONFIG_EXTS, 'glob');
}
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';

public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getProjectDir(): string
{
return dirname(__DIR__);
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';

$loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services/*' . self::CONFIG_EXTS, 'glob');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,37 @@

final readonly class CoursesGetController
{
public function __construct(private QueryBus $queryBus) {}

public function __invoke(Request $request): JsonResponse
{
$orderBy = $request->query->get('order_by');
$order = $request->query->get('order');
$limit = $request->query->get('limit');
$offset = $request->query->get('offset');

/** @var BackofficeCoursesResponse $response */
$response = $this->queryBus->ask(
new SearchBackofficeCoursesByCriteriaQuery(
(array) $request->query->get('filters'),
$orderBy,
$order,
$limit === null ? null : (int) $limit,
$offset === null ? null : (int) $offset
)
);

return new JsonResponse(
map(
fn (BackofficeCourseResponse $course): array => [
'id' => $course->id(),
'name' => $course->name(),
'duration' => $course->duration(),
],
$response->courses()
),
200,
['Access-Control-Allow-Origin' => '*']
);
}
public function __construct(private QueryBus $queryBus) {}

public function __invoke(Request $request): JsonResponse
{
$orderBy = $request->query->get('order_by');
$order = $request->query->get('order');
$limit = $request->query->get('limit');
$offset = $request->query->get('offset');

/** @var BackofficeCoursesResponse $response */
$response = $this->queryBus->ask(
new SearchBackofficeCoursesByCriteriaQuery(
(array) $request->query->get('filters'),
$orderBy,
$order,
$limit === null ? null : (int) $limit,
$offset === null ? null : (int) $offset
)
);

return new JsonResponse(
map(
fn (BackofficeCourseResponse $course): array => [
'id' => $course->id(),
'name' => $course->name(),
'duration' => $course->duration(),
],
$response->courses()
),
200,
['Access-Control-Allow-Origin' => '*']
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

final class HealthCheckGetController
{
public function __invoke(Request $request): JsonResponse
{
return new JsonResponse(
[
'backoffice-backend' => 'ok',
]
);
}
public function __invoke(Request $request): JsonResponse
{
return new JsonResponse(
[
'backoffice-backend' => 'ok',
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

final readonly class MetricsController
{
public function __construct(private PrometheusMonitor $monitor) {}
public function __construct(private PrometheusMonitor $monitor) {}

public function __invoke(Request $request): Response
{
$renderer = new RenderTextFormat();
$result = $renderer->render($this->monitor->registry()->getMetricFamilySamples());
public function __invoke(Request $request): Response
{
$renderer = new RenderTextFormat();
$result = $renderer->render($this->monitor->registry()->getMetricFamilySamples());

return new Response($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
}
return new Response($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
}
}
8 changes: 4 additions & 4 deletions apps/backoffice/frontend/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
// WouterJ\EloquentBundle\WouterJEloquentBundle::class => ['test' => true]
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
// WouterJ\EloquentBundle\WouterJEloquentBundle::class => ['test' => true]
];
14 changes: 7 additions & 7 deletions apps/backoffice/frontend/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
require dirname(__DIR__) . '/../../bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);
umask(0000);

Debug::enable();
Debug::enable();
}

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

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new BackofficeFrontendKernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
Expand Down
58 changes: 29 additions & 29 deletions apps/backoffice/frontend/src/BackofficeFrontendKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@

class BackofficeFrontendKernel extends Kernel
{
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';

public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getProjectDir(): string
{
return dirname(__DIR__);
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';

$loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services/*' . self::CONFIG_EXTS, 'glob');
}
use MicroKernelTrait;

private const CONFIG_EXTS = '.{xml,yaml}';

public function registerBundles(): iterable
{
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}

public function getProjectDir(): string
{
return dirname(__DIR__);
}

protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', true);
$confDir = $this->getProjectDir() . '/config';

$loader->load($confDir . '/services' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services_' . $this->environment . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/services/*' . self::CONFIG_EXTS, 'glob');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

final class ImportCoursesToElasticsearchCommand extends Command
{
public function __construct(
private readonly MySqlBackofficeCourseRepository $mySqlRepository,
private readonly ElasticsearchBackofficeCourseRepository $elasticRepository
) {
parent::__construct();
}
public function __construct(
private readonly MySqlBackofficeCourseRepository $mySqlRepository,
private readonly ElasticsearchBackofficeCourseRepository $elasticRepository
) {
parent::__construct();
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$courses = $this->mySqlRepository->searchAll();
public function execute(InputInterface $input, OutputInterface $output): int
{
$courses = $this->mySqlRepository->searchAll();

foreach ($courses as $course) {
$this->elasticRepository->save($course);
}
foreach ($courses as $course) {
$this->elasticRepository->save($course);
}

return 0;
}
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

final class CoursesGetWebController extends WebController
{
public function __invoke(Request $request): Response
{
/** @var CoursesCounterResponse $coursesCounterResponse */
$coursesCounterResponse = $this->ask(new FindCoursesCounterQuery());
public function __invoke(Request $request): Response
{
/** @var CoursesCounterResponse $coursesCounterResponse */
$coursesCounterResponse = $this->ask(new FindCoursesCounterQuery());

return $this->render(
'pages/courses/courses.html.twig',
[
'title' => 'Courses',
'description' => 'Courses CodelyTV - Backoffice',
'courses_counter' => $coursesCounterResponse->total(),
'new_course_id' => SimpleUuid::random()->value(),
]
);
}
return $this->render(
'pages/courses/courses.html.twig',
[
'title' => 'Courses',
'description' => 'Courses CodelyTV - Backoffice',
'courses_counter' => $coursesCounterResponse->total(),
'new_course_id' => SimpleUuid::random()->value(),
]
);
}

protected function exceptions(): array
{
return [];
}
protected function exceptions(): array
{
return [];
}
}
Loading