Skip to content

Commit 47d186c

Browse files
committed
4565: Cleaned up enum use
1 parent b2f8927 commit 47d186c

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/Command/ScreenLayout/ScreenLayoutsListCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ final protected function execute(InputInterface $input, OutputInterface $output)
4747

4848
if ($status) {
4949
$numberOfScreenLayouts = count($screenLayouts);
50-
$numberOfInstallledScreenLayouts = count(array_filter($screenLayouts, fn ($entry): bool => $entry->installed));
51-
$text = $numberOfInstallledScreenLayouts.' / '.$numberOfScreenLayouts.' templates installed.';
50+
$numberOfInstalledScreenLayouts = count(array_filter($screenLayouts, fn ($entry): bool => $entry->installed));
51+
$text = $numberOfInstalledScreenLayouts.' / '.$numberOfScreenLayouts.' templates installed.';
5252

5353
$io->success($text);
5454
} else {
5555
$io->table(['ID', 'Title', 'Status', 'Type'], array_map(fn (ScreenLayoutData $screenLayout) => [
5656
$screenLayout->id,
5757
$screenLayout->title,
5858
$screenLayout->installed ? 'Installed' : 'Not Installed',
59-
$screenLayout->type,
59+
$screenLayout->type->value,
6060
], $screenLayouts));
6161
}
6262

src/Command/Template/TemplatesListCommand.php

Lines changed: 4 additions & 4 deletions
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->value));
43+
$coreTemplateCount = count(array_filter($templates, fn (TemplateData $template) => $template->type === ResourceTypeEnum::CORE));
4444

4545
if (0 === $coreTemplateCount) {
4646
$io->error('No core templates found.');
@@ -50,16 +50,16 @@ final protected function execute(InputInterface $input, OutputInterface $output)
5050

5151
if ($status) {
5252
$numberOfTemplates = count($templates);
53-
$numberOfInstallledTemplates = count(array_filter($templates, fn ($entry): bool => $entry->installed));
54-
$text = $numberOfInstallledTemplates.' / '.$numberOfTemplates.' templates installed.';
53+
$numberOfInstalledTemplates = count(array_filter($templates, fn ($entry): bool => $entry->installed));
54+
$text = $numberOfInstalledTemplates.' / '.$numberOfTemplates.' templates installed.';
5555

5656
$io->success($text);
5757
} else {
5858
$io->table(['ID', 'Title', 'Status', 'Type'], array_map(fn (TemplateData $templateData) => [
5959
$templateData->id,
6060
$templateData->title,
6161
$templateData->installed ? 'Installed' : 'Not Installed',
62-
$templateData->type,
62+
$templateData->type->value,
6363
], $templates));
6464
}
6565

src/Model/ScreenLayoutData.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace App\Model;
66

77
use App\Entity\ScreenLayout;
8+
use App\Enum\ResourceTypeEnum;
89

910
class ScreenLayoutData
1011
{
1112
public function __construct(
1213
public readonly string $id,
1314
public readonly string $title,
14-
public readonly string $type,
15+
public readonly ResourceTypeEnum $type,
1516
public readonly int $gridRows,
1617
public readonly int $gridColumns,
1718
public readonly ?ScreenLayout $screenLayoutEntity,

src/Model/TemplateData.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Model;
66

77
use App\Entity\Template;
8+
use App\Enum\ResourceTypeEnum;
89

910
class TemplateData
1011
{
@@ -15,6 +16,6 @@ public function __construct(
1516
public readonly object $options,
1617
public readonly ?Template $templateEntity,
1718
public readonly bool $installed,
18-
public readonly string $type,
19+
public readonly ResourceTypeEnum $type,
1920
) {}
2021
}

src/Service/ScreenLayoutService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function installScreenLayout(ScreenLayoutData $screenLayoutData, bool $up
106106

107107
public function updateScreenLayout(ScreenLayoutData $screenLayoutToUpdate): void
108108
{
109+
// This only handles screen layouts that have an entity in the database.
109110
if (null !== $screenLayoutToUpdate->screenLayoutEntity) {
110111
$this->installScreenLayout($screenLayoutToUpdate, true);
111112
}

src/Utils/ResourceLoader.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
use Symfony\Component\Finder\Finder;
1818
use Symfony\Component\Uid\Ulid;
1919

20-
class ResourceLoader
20+
readonly class ResourceLoader
2121
{
2222
public function __construct(
23-
private readonly EntityManagerInterface $entityManager,
23+
private EntityManagerInterface $entityManager,
2424
) {}
2525

2626
public function getResourceJsonInDirectory(string $path, string $resourceType, ResourceTypeEnum $type): array
@@ -45,7 +45,7 @@ public function getResourceJsonInDirectory(string $path, string $resourceType, R
4545
return [];
4646
}
4747

48-
public function getTemplateData(iterable $finder, ResourceTypeEnum $type): array
48+
private function getTemplateData(iterable $finder, ResourceTypeEnum $type): array
4949
{
5050
$templates = [];
5151

@@ -82,7 +82,7 @@ public function getTemplateData(iterable $finder, ResourceTypeEnum $type): array
8282
$content->options,
8383
$template,
8484
null !== $template,
85-
$type->value,
85+
$type,
8686
);
8787
}
8888

@@ -122,7 +122,7 @@ private function getScreenLayoutData(iterable $finder, ResourceTypeEnum $type):
122122
$screenLayouts[] = new ScreenLayoutData(
123123
$content->id,
124124
$content->title,
125-
$type->value,
125+
$type,
126126
$content->grid->rows,
127127
$content->grid->columns,
128128
$screenLayout,
@@ -189,7 +189,7 @@ private function getScreenLayoutJsonSchema(): object
189189
"$schema": "https://json-schema.org/draft/2020-12/schema",
190190
"$id": "https://os2display.dk/config-schema.json",
191191
"title": "Config file schema",
192-
"description": "Schema for defining config files for templates",
192+
"description": "Schema for defining config files for screen layouts",
193193
"type": "object",
194194
"properties": {
195195
"id": {

0 commit comments

Comments
 (0)