Skip to content

Commit 0d8e5be

Browse files
committed
4565: Cleaned up code
1 parent f4a7b33 commit 0d8e5be

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"cache:clear": "symfony-cmd",
122122
"assets:install %PUBLIC_DIR%": "symfony-cmd"
123123
},
124-
"code-analysis": "vendor/bin/psalm",
124+
"code-analysis": "vendor/bin/psalm --no-cache",
125125
"coding-standards-apply": [
126126
"vendor/bin/php-cs-fixer fix"
127127
],

src/Command/Template/TemplatesListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final protected function execute(InputInterface $input, OutputInterface $output)
4040
try {
4141
$templates = $this->templateService->getTemplates();
4242

43-
$coreTemplateCount = count(array_filter($templates, fn (TemplateData $template) => $template->type === ResourceTypeEnum::CORE));
43+
$coreTemplateCount = count(array_filter($templates, fn (TemplateData $template) => ResourceTypeEnum::CORE === $template->type));
4444

4545
if (0 === $coreTemplateCount) {
4646
$io->error('No core templates found.');

src/Utils/ResourceLoader.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace App\Utils;
66

7-
use App\Entity\ScreenLayout;
87
use App\Entity\Template;
98
use App\Enum\ResourceTypeEnum;
109
use App\Exceptions\NotImplementedException;
1110
use App\Model\ScreenLayoutData;
1211
use App\Model\TemplateData;
12+
use App\Repository\ScreenLayoutRepository;
13+
use App\Repository\TemplateRepository;
1314
use Doctrine\ORM\EntityManagerInterface;
1415
use JsonSchema\Constraints\Factory;
1516
use JsonSchema\SchemaStorage;
@@ -20,7 +21,9 @@
2021
readonly class ResourceLoader
2122
{
2223
public function __construct(
23-
private EntityManagerInterface $entityManager,
24+
private readonly EntityManagerInterface $entityManager,
25+
private readonly ScreenLayoutRepository $screenLayoutRepository,
26+
private readonly TemplateRepository $templateRepository,
2427
) {}
2528

2629
public function getResourceJsonInDirectory(string $path, string $resourceType, ResourceTypeEnum $type): array
@@ -48,11 +51,9 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
4851

4952
switch ($resourceType) {
5053
case ScreenLayoutData::class:
51-
$repository = $this->entityManager->getRepository(ScreenLayout::class);
5254
$jsonSchemaObject = $this->getScreenLayoutJsonSchema();
5355
break;
5456
case TemplateData::class:
55-
$repository = $this->entityManager->getRepository(Template::class);
5657
$jsonSchemaObject = $this->getTemplateJsonSchema();
5758
break;
5859
default:
@@ -81,10 +82,10 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
8182
throw new \Exception('The Ulid is not valid');
8283
}
8384

84-
$entity = $repository->findOneBy(['id' => Ulid::fromString($content->id)]);
85-
8685
switch ($resourceType) {
8786
case ScreenLayoutData::class:
87+
$entity = $this->screenLayoutRepository->find(Ulid::fromString($content->id));
88+
8889
$results[] = new ScreenLayoutData(
8990
$content->id,
9091
$content->title,
@@ -98,6 +99,8 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
9899

99100
break;
100101
case TemplateData::class:
102+
$entity = $this->templateRepository->find(Ulid::fromString($content->id));
103+
101104
$results[] = new TemplateData(
102105
$content->id,
103106
$content->title,

0 commit comments

Comments
 (0)