Skip to content

upgraded to native enums #20

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/Commands/UpgradeStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class UpgradeStatus extends Command

public function handle()
{
$this->table(TableHeader::values()->toArray(), (new Service())->handle());
$this->table(TableHeader::mappings(), (new Service())->handle());
}
}
56 changes: 34 additions & 22 deletions src/Enums/TableHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,41 @@

namespace LaravelEnso\Upgrade\Enums;

use LaravelEnso\Enums\Services\Enum;
use Illuminate\Support\Collection;
use LaravelEnso\Enums\Contracts\Mappable;

class TableHeader extends Enum

enum TableHeader: int implements Mappable
{
public const NrCrt = 1;
public const Package = 2;
public const Upgrade = 3;
public const Applicable = 4;
public const Manual = 5;
public const Priority = 6;
public const Migration = 7;
public const Ran = 8;
public const LastModifiedAt = 9;
case NrCrt = 1;
case Package = 2;
case Upgrade = 3;
case Applicable = 4;
case Manual = 5;
case Priority = 6;
case Migration = 7;
case Ran = 8;
case LastModifiedAt = 9;

public function map(): string
{
return match ($this) {
self::NrCrt => 'Nr Crt',
self::Package => 'Package',
self::Upgrade => 'Upgrade',
self::Applicable => 'Applicable',
self::Manual => 'Manual',
self::Priority => 'Priority',
self::Migration => 'Migration',
self::Ran => 'Ran',
self::LastModifiedAt => 'Last Modified At',
};
}

protected static array $data = [
self::NrCrt => 'Nr Crt',
self::Package => 'Package',
self::Upgrade => 'Upgrade',
self::Applicable => 'Applicable',
self::Manual => 'Manual',
self::Priority => 'Priority',
self::Migration => 'Migration',
self::Ran => 'Ran',
self::LastModifiedAt => 'Last Modified At',
];
public static function mappings(): array
{
return Collection::wrap(self::cases())
->map(fn ($case) => $case->map())
->toArray();
}
}
20 changes: 10 additions & 10 deletions src/Services/UpgradeStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class UpgradeStatus extends Upgrade
public function handle()
{
return $this->sorted()->values()->map(fn (Contract $upgrade, $index) => [
TableHeader::NrCrt => $index + 1,
TableHeader::Package => Reflection::package($upgrade),
TableHeader::Upgrade => Reflection::upgrade($upgrade),
TableHeader::Applicable => $this->applicable($upgrade),
TableHeader::Manual => $this->isManual($upgrade),
TableHeader::Priority => $this->priority($upgrade),
TableHeader::Migration => $this->migration($upgrade),
TableHeader::Ran => $this->ran($upgrade),
TableHeader::LastModifiedAt => $this->changedAt($upgrade),
TableHeader::NrCrt->value => $index + 1,
TableHeader::Package->value => Reflection::package($upgrade),
TableHeader::Upgrade->value => Reflection::upgrade($upgrade),
TableHeader::Applicable->value => $this->applicable($upgrade),
TableHeader::Manual->value => $this->isManual($upgrade),
TableHeader::Priority->value => $this->priority($upgrade),
TableHeader::Migration->value => $this->migration($upgrade),
TableHeader::Ran->value => $this->ran($upgrade),
TableHeader::LastModifiedAt->value => $this->changedAt($upgrade),
]);
}

private function applicable(Contract $upgrade): string
{
return ! $upgrade instanceof Applicable || $upgrade->applicable()
return !$upgrade instanceof Applicable || $upgrade->applicable()
? $this->green('yes')
: $this->yellow('no');
}
Expand Down