A free open source IT asset/license management system
Readability
Marcus Moore3de7d3fcb091
diff --git a/app/Console/Commands/RegenerateAcceptances.php b/app/Console/Commands/RegenerateAcceptances.phpindex 3c10f713fb..390de2b50e 100644--- a/app/Console/Commands/RegenerateAcceptances.php+++ b/app/Console/Commands/RegenerateAcceptances.php@@ -78,7 +78,7 @@ class RegenerateAcceptances extends Command* would pin every item this run touches in memory and undo the chunking that bounds* the command.*- * @var array<int, array{user: User, items: array<int, array{name: string, type: class-string, qty: int|null}>}>+ * @var array<int, array{user: User, items: array<int, array{name: string, type: 'asset'|'license'|'accessory'|'consumable'|'component', qty: int|null}>}>*/private array $holdersToNotify = [];@@ -443,11 +443,28 @@ class RegenerateAcceptances extends Command$this->holdersToNotify[$holder->id]['user'] = $holder;$this->holdersToNotify[$holder->id]['items'][] = ['name' => $pair['item']->present()->name,- 'type' => $pair['item']::class,+ 'type' => $this->itemType($pair['item']),'qty' => $this->creationQty($pair['item'], $pair['qty']),];}+ /**+ * Which kind of thing this is, as the token the mail turns into a word.+ *+ * @param Checkoutable $item+ * @return 'asset'|'license'|'accessory'|'consumable'|'component'+ */+ private function itemType(Model $item): string+ {+ return match (true) {+ $item instanceof Asset => 'asset',+ $item instanceof LicenseSeat => 'license',+ $item instanceof Accessory => 'accessory',+ $item instanceof Consumable => 'consumable',+ $item instanceof Component => 'component',+ };+ }+/*** Emails the holders this run created rows for, when --notify was passed.*diff --git a/app/Mail/AcceptanceReRequestMail.php b/app/Mail/AcceptanceReRequestMail.phpindex 4358f5a5aa..f047081514 100644--- a/app/Mail/AcceptanceReRequestMail.php+++ b/app/Mail/AcceptanceReRequestMail.php@@ -2,10 +2,6 @@namespace App\Mail;-use App\Models\Accessory;-use App\Models\Asset;-use App\Models\Consumable;-use App\Models\LicenseSeat;use App\Models\User;use Illuminate\Bus\Queueable;use Illuminate\Mail\Mailables\Address;@@ -24,7 +20,7 @@ class AcceptanceReRequestMail extends BaseMailableprivate const ITEM_LIST_LIMIT = 10;/**- * @param array<int, array{name: string, type: class-string, qty: int|null}> $items+ * @param array<int, array{name: string, type: 'asset'|'license'|'accessory'|'consumable'|'component', qty: int|null}> $items*/public function __construct(public readonly User $holder,@@ -52,20 +48,30 @@ class AcceptanceReRequestMail extends BaseMailablewith: ['assigned_to' => $this->holder->present()->fullName,'count' => count($this->items),- 'shown_items' => array_map(- fn (array $item) => [- 'name' => $item['name'],- 'type' => $this->typeLabel($item['type']),- 'qty' => $item['qty'],- ],- array_slice($this->items, 0, self::ITEM_LIST_LIMIT),- ),+ 'shown_items' => $this->shownItems(),'remaining' => max(count($this->items) - self::ITEM_LIST_LIMIT, 0),'accept_url' => route('account.accept'),],);}+ /**+ * The items the message names, each labelled in words a holder uses.+ *+ * @return array<int, array{name: string, type: string, qty: int|null}>+ */+ private function shownItems(): array+ {+ return collect($this->items)+ ->take(self::ITEM_LIST_LIMIT)+ ->map(fn (array $item) => [+ 'name' => $item['name'],+ 'type' => $this->typeLabel($item['type']),+ 'qty' => $item['qty'],+ ])+ ->all();+ }+/*** What a holder calls the kind of thing they hold.*@@ -73,16 +79,16 @@ class AcceptanceReRequestMail extends BaseMailable* is not a word anyone outside this codebase uses. This runs while the mailable is* being rendered, so it is already inside the holder's locale.*- * @param class-string $type+ * @param 'asset'|'license'|'accessory'|'consumable'|'component' $type*/private function typeLabel(string $type): string{return match ($type) {- Asset::class => trans('general.asset'),- LicenseSeat::class => trans('general.license'),- Accessory::class => trans('general.accessory'),- Consumable::class => trans('general.consumable'),- default => trans('general.component'),+ 'asset' => trans('general.asset'),+ 'license' => trans('general.license'),+ 'accessory' => trans('general.accessory'),+ 'consumable' => trans('general.consumable'),+ 'component' => trans('general.component'),};}