Refactor ship status to be enum instead of string.
This commit is contained in:
11
src/Enum/StarshipStatusEnum.php
Normal file
11
src/Enum/StarshipStatusEnum.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enum;
|
||||
|
||||
enum StarshipStatusEnum: string
|
||||
{
|
||||
case WAITING = 'waiting';
|
||||
case IN_PROGRESS = 'in_progress';
|
||||
case COMPLETED = 'completed';
|
||||
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Enum\StarshipStatusEnum;
|
||||
|
||||
class Starship
|
||||
{
|
||||
public function __construct(
|
||||
@@ -9,7 +11,7 @@ class Starship
|
||||
private string $name,
|
||||
private string $class,
|
||||
private string $captain,
|
||||
private string $status,
|
||||
private StarshipStatusEnum $status,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -33,7 +35,7 @@ class Starship
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
public function getStatus(): StarshipStatusEnum
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Enum\StarshipStatusEnum;
|
||||
use App\Model\Starship;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
@@ -16,18 +17,18 @@ class StarshipRepository
|
||||
$this->logger->info('Starship Repository: Finding Starships');
|
||||
|
||||
return [
|
||||
new Starship(1, 'Starship 01', 'Heavy Starship', 'Human Captain', 'damaged'),
|
||||
new Starship(2, 'Starship 02', 'Light Starship', 'Robot Captain', 'new'),
|
||||
new Starship(3, 'USS Voyager', 'Intrepid-class', 'Kathryn Janeway', 'Active'),
|
||||
new Starship(4, 'Starblade', 'Interceptor-class', 'Lance Stellar', 'In repair'),
|
||||
new Starship(5, 'Black Star', 'Battlecruiser-class', 'Zara Nox', 'Active'),
|
||||
new Starship(6, 'SS Horizon', 'Explorer-class', 'James Marshall', 'Decommissioned'),
|
||||
new Starship(7, 'Nebula Queen', 'Transport-class', 'Elara Trent', 'Under inspection'),
|
||||
new Starship(8, 'Celestial Wave', 'Frigate-class', 'Talon Skye', 'On mission'),
|
||||
new Starship(9, 'Galactic Serpent', 'Destroyer-class', 'Viktor Helios', 'Active'),
|
||||
new Starship(10, 'Phoenix Wing', 'Carrier-class', 'Aurora Drake', 'Awaiting orders'),
|
||||
new Starship(11, 'Silver Comet', 'Scout-class', 'Finn O\'Neil', 'In dock'),
|
||||
new Starship(12, 'Crimson Spear', 'Corvette-class', 'Raven Callen', 'Destroyed'),
|
||||
new Starship(1, 'Starship 01', 'Heavy Starship', 'Human Captain', StarshipStatusEnum::COMPLETED),
|
||||
new Starship(2, 'Starship 02', 'Light Starship', 'Robot Captain', StarshipStatusEnum::IN_PROGRESS),
|
||||
new Starship(3, 'USS Voyager', 'Intrepid-class', 'Kathryn Janeway', StarshipStatusEnum::WAITING),
|
||||
new Starship(4, 'Starblade', 'Interceptor-class', 'Lance Stellar', StarshipStatusEnum::COMPLETED),
|
||||
new Starship(5, 'Black Star', 'Battlecruiser-class', 'Zara Nox', StarshipStatusEnum::WAITING),
|
||||
new Starship(6, 'SS Horizon', 'Explorer-class', 'James Marshall', StarshipStatusEnum::COMPLETED),
|
||||
new Starship(7, 'Nebula Queen', 'Transport-class', 'Elara Trent', StarshipStatusEnum::IN_PROGRESS),
|
||||
new Starship(8, 'Celestial Wave', 'Frigate-class', 'Talon Skye', StarshipStatusEnum::IN_PROGRESS),
|
||||
new Starship(9, 'Galactic Serpent', 'Destroyer-class', 'Viktor Helios', StarshipStatusEnum::COMPLETED),
|
||||
new Starship(10, 'Phoenix Wing', 'Carrier-class', 'Aurora Drake', StarshipStatusEnum::COMPLETED),
|
||||
new Starship(11, 'Silver Comet', 'Scout-class', 'Finn O\'Neil', StarshipStatusEnum::WAITING),
|
||||
new Starship(12, 'Crimson Spear', 'Corvette-class', 'Raven Callen', StarshipStatusEnum::IN_PROGRESS),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,36 +12,37 @@
|
||||
</h1>
|
||||
|
||||
<div class="space-y-5">
|
||||
<!-- start ship item -->
|
||||
|
||||
{% for ship in ships %}
|
||||
<div class="bg-[#16202A] rounded-2xl pl-5 py-5 pr-11 flex flex-col min-[1174px]:flex-row min-[1174px]:justify-between">
|
||||
<div class="flex justify-center min-[1174px]:justify-start">
|
||||
<img class="h-[83px] w-[84px]" src="/images/status-in-progress.png" alt="Status: in progress">
|
||||
<img class="h-[83px] w-[84px]" src="/images/status-in-progress.png" alt="Status: {{ ship.status.value }}">
|
||||
<div class="ml-5">
|
||||
<div class="rounded-2xl py-1 px-3 flex justify-center w-32 items-center bg-amber-400/10">
|
||||
<div class="rounded-full h-2 w-2 bg-amber-400 blur-[1px] mr-2"></div>
|
||||
<p class="uppercase text-xs text-nowrap">in progress</p>
|
||||
<p class="uppercase text-xs text-nowrap">{{ ship.status.value }}</p>
|
||||
</div>
|
||||
<h4 class="text-[22px] pt-1 font-semibold">
|
||||
<a
|
||||
class="hover:text-slate-200"
|
||||
href="#"
|
||||
>USS LeafyCruiser</a>
|
||||
href="{{ path('app_starship_show', {id: ship.id}) }}"
|
||||
>{{ ship.name }}</a>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex justify-center min-[1174px]:justify-start mt-2 min-[1174px]:mt-0 shrink-0">
|
||||
<div class="border-r border-white/20 pr-8">
|
||||
<p class="text-slate-400 text-xs">Captain</p>
|
||||
<p class="text-xl">Jean-Luc Pickles</p>
|
||||
<p class="text-xl">{{ ship.captain }}</p>
|
||||
</div>
|
||||
|
||||
<div class="pl-8 w-[100px]">
|
||||
<p class="text-slate-400 text-xs">Class</p>
|
||||
<p class="text-xl">Garden</p>
|
||||
<p class="text-xl">{{ ship.class }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- end ship item -->
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<p class="text-lg mt-5 text-center md:text-left">
|
||||
|
||||
Reference in New Issue
Block a user