refactor: Add explicit return type declarations to methods in various traits.
This commit is contained in:
parent
2f9c73576b
commit
8ccca5b7cc
@ -4,7 +4,7 @@
|
||||
|
||||
trait WithAuthorization
|
||||
{
|
||||
public function canOrAbort(string $ability, $model = null)
|
||||
public function canOrAbort(string $ability, $model = null): void
|
||||
{
|
||||
if (auth()->user()->cannot($ability, $model)) {
|
||||
abort(403);
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
trait WithCategorySelector
|
||||
{
|
||||
public function selectAllCategories()
|
||||
public function selectAllCategories(): void
|
||||
{
|
||||
$this->form->category_ids = array_keys($this->categories);
|
||||
}
|
||||
|
||||
public function deselectAllCategories()
|
||||
public function deselectAllCategories(): void
|
||||
{
|
||||
$this->form->category_ids = [];
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
trait WithCloseModal
|
||||
{
|
||||
public function closeModal(string $modalName, ?bool $isCloseAll = false)
|
||||
public function closeModal(string $modalName, ?bool $isCloseAll = false): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
$this->resetValidation();
|
||||
|
||||
@ -14,7 +14,7 @@ trait WithConfirmation
|
||||
public function confirmAction(
|
||||
string $id,
|
||||
string $target = 'delete'
|
||||
) {
|
||||
): void {
|
||||
$this->confirmingId = $id;
|
||||
$this->target = $target;
|
||||
}
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
trait WithOutletSelector
|
||||
{
|
||||
public function selectAllOutlets()
|
||||
public function selectAllOutlets(): void
|
||||
{
|
||||
$this->form->outlet_ids = array_keys($this->outlets);
|
||||
}
|
||||
|
||||
public function deselectAllOutlets()
|
||||
public function deselectAllOutlets(): void
|
||||
{
|
||||
$this->form->outlet_ids = [];
|
||||
}
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
trait WithRoleSelector
|
||||
{
|
||||
public function selectAllRoles()
|
||||
public function selectAllRoles(): void
|
||||
{
|
||||
$this->form->role_ids = array_keys($this->roles);
|
||||
}
|
||||
|
||||
public function deselectAllRoles()
|
||||
public function deselectAllRoles(): void
|
||||
{
|
||||
$this->form->role_ids = [];
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
trait WithToast
|
||||
{
|
||||
public function toast(string $text, string $heading = 'Berhasil', string $variant = 'success', int $duration = 5000)
|
||||
public function toast(string $text, string $heading = 'Berhasil', string $variant = 'success', int $duration = 5000): void
|
||||
{
|
||||
Flux::toast(
|
||||
heading: $heading,
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
trait WithUserSelector
|
||||
{
|
||||
public function selectAllUsers()
|
||||
public function selectAllUsers(): void
|
||||
{
|
||||
$this->form->user_ids = array_keys($this->users);
|
||||
}
|
||||
|
||||
public function deselectAllUsers()
|
||||
public function deselectAllUsers(): void
|
||||
{
|
||||
$this->form->user_ids = [];
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
trait WithCommentEnum
|
||||
{
|
||||
public static function comment()
|
||||
public static function comment(): string
|
||||
{
|
||||
return implode(', ', array_map(fn ($case) => "{$case->value}: {$case->label()}", self::cases()));
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
trait WithValueEnum
|
||||
{
|
||||
public static function values()
|
||||
public static function values(): array
|
||||
{
|
||||
return array_map(fn ($case) => $case->value, self::cases());
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
trait WithMediaHandler
|
||||
{
|
||||
public function mapMediaCollection(MediaCollection $mediaCollection)
|
||||
public function mapMediaCollection(MediaCollection $mediaCollection): array
|
||||
{
|
||||
return $mediaCollection->map(fn ($media) => [
|
||||
'id' => $media->id,
|
||||
@ -20,7 +20,7 @@ public function mapMediaCollection(MediaCollection $mediaCollection)
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
protected function syncMedia(array $newMedia, $model, string $collectionName)
|
||||
protected function syncMedia(array $newMedia, $model, string $collectionName): void
|
||||
{
|
||||
$existingMediaIds = $model->getMedia($collectionName)->pluck('id')->toArray();
|
||||
|
||||
@ -36,7 +36,7 @@ protected function syncMedia(array $newMedia, $model, string $collectionName)
|
||||
}
|
||||
}
|
||||
|
||||
protected function uploadMedia(array $mediaArray, $model, string $collectionName)
|
||||
protected function uploadMedia(array $mediaArray, $model, string $collectionName): void
|
||||
{
|
||||
foreach ($mediaArray as $file) {
|
||||
if (isset($file['path'])) {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
trait WithSubscribeNotification
|
||||
{
|
||||
#[On('notification:subscribe')]
|
||||
public function notificationSubscribe(string $subscription)
|
||||
public function notificationSubscribe(string $subscription): void
|
||||
{
|
||||
$subscription = json_decode($subscription, true);
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ public function updatedFormBottleSize(string $value)
|
||||
* Entry point to add a perfume item to the cart.
|
||||
* Determines the action based on the currently active tab.
|
||||
*/
|
||||
public function addPerfume()
|
||||
public function addPerfume(): void
|
||||
{
|
||||
match ($this->tab) {
|
||||
'new' => $this->handleNewPerfume(),
|
||||
@ -72,7 +72,7 @@ public function addPerfume()
|
||||
/**
|
||||
* Handles the process of adding a new perfume with a bottle and selected quality.
|
||||
*/
|
||||
protected function handleNewPerfume()
|
||||
protected function handleNewPerfume(): void
|
||||
{
|
||||
$perfume = Perfume::find($this->form->perfume_id);
|
||||
$bottle = Bottle::find($this->form->bottle_id);
|
||||
@ -106,7 +106,7 @@ protected function handleNewPerfume()
|
||||
/**
|
||||
* Handles the process of adding a refill perfume based on selected size and quality.
|
||||
*/
|
||||
protected function handleRefillPerfume()
|
||||
protected function handleRefillPerfume(): void
|
||||
{
|
||||
$perfume = Perfume::find($this->form->perfume_id);
|
||||
$quality = Formula::find($this->form->quality_id);
|
||||
@ -131,7 +131,7 @@ protected function handleRefillPerfume()
|
||||
/**
|
||||
* Handles adding a regular product (non-perfume) to the cart.
|
||||
*/
|
||||
public function addProduct()
|
||||
public function addProduct(): void
|
||||
{
|
||||
$product = Product::find($this->form->product_id);
|
||||
|
||||
|
||||
@ -4,12 +4,12 @@
|
||||
|
||||
trait WithCalculateTotal
|
||||
{
|
||||
public function getSubTotal()
|
||||
public function getSubTotal(): int
|
||||
{
|
||||
return $this->items->sum(fn ($item) => $item->unit_price * $item->quantity);
|
||||
}
|
||||
|
||||
public function getTotal()
|
||||
public function getTotal(): int
|
||||
{
|
||||
return $this->items->sum(fn ($item) => $item->unit_price * $item->quantity - parseRupiahToInt($this->form->discount) - $this->voucherDiscount);
|
||||
}
|
||||
|
||||
@ -7,12 +7,12 @@
|
||||
|
||||
trait WithDiscount
|
||||
{
|
||||
public function updatedFormDiscount(string $value)
|
||||
public function updatedFormDiscount(string $value): void
|
||||
{
|
||||
$this->total = $this->getTotal();
|
||||
}
|
||||
|
||||
public function calculateDiscount(int $subtotal, string $voucherId)
|
||||
public function calculateDiscount(int $subtotal, string $voucherId): array|int
|
||||
{
|
||||
$voucher = Voucher::find($voucherId);
|
||||
$discount = 0;
|
||||
|
||||
@ -12,7 +12,7 @@ trait WithManageItem
|
||||
* @param mixed $model The model instance (Perfume, Bottle, or Product)
|
||||
* @param int $quantity The quantity to add
|
||||
*/
|
||||
protected function addOrUpdateOrderItem($model, int $quantity)
|
||||
protected function addOrUpdateOrderItem($model, int $quantity): void
|
||||
{
|
||||
$existing = $this->items->firstWhere(fn ($i) => $i->orderable_type === get_class($model) && $i->orderable_id === $model->id);
|
||||
|
||||
@ -38,7 +38,7 @@ protected function addOrUpdateOrderItem($model, int $quantity)
|
||||
$this->total = $this->getTotal();
|
||||
}
|
||||
|
||||
public function deleteItem(OrderItem $item)
|
||||
public function deleteItem(OrderItem $item): void
|
||||
{
|
||||
$this->items = $this->items->reject(fn ($i) => $i->id === $item->id);
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ trait WithMember
|
||||
public string $searchMember = '';
|
||||
|
||||
#[Computed]
|
||||
public function members()
|
||||
public function members(): array
|
||||
{
|
||||
if ($this->searchMember === '') {
|
||||
return [];
|
||||
@ -29,7 +29,7 @@ public function members()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function updatedFormVoucherId(?string $voucherId = null)
|
||||
public function updatedFormVoucherId(?string $voucherId = null): void
|
||||
{
|
||||
$voucher = Voucher::find($voucherId);
|
||||
|
||||
@ -48,7 +48,7 @@ public function updatedFormVoucherId(?string $voucherId = null)
|
||||
$this->total = $this->getTotal();
|
||||
}
|
||||
|
||||
public function updatedFormMemberId(?string $memberId = null)
|
||||
public function updatedFormMemberId(?string $memberId = null): void
|
||||
{
|
||||
$customer = Customer::with('user')->find($memberId);
|
||||
|
||||
@ -67,7 +67,7 @@ public function updatedFormMemberId(?string $memberId = null)
|
||||
$this->loadVouchers($customer->user?->id, $this->form->outlet_id);
|
||||
}
|
||||
|
||||
public function updatedFormOutletId(?string $outletId = null)
|
||||
public function updatedFormOutletId(?string $outletId = null): void
|
||||
{
|
||||
$customer = Customer::with('user')->find($this->form->member_id);
|
||||
if (! $customer) {
|
||||
@ -77,7 +77,7 @@ public function updatedFormOutletId(?string $outletId = null)
|
||||
$this->loadVouchers($customer->user?->id, $outletId);
|
||||
}
|
||||
|
||||
private function loadVouchers(?string $memberId, ?string $outletId)
|
||||
private function loadVouchers(?string $memberId, ?string $outletId): void
|
||||
{
|
||||
$this->vouchers = Voucher::whereHas('users', fn ($q) => $q->where('user_id', $memberId))
|
||||
->whereHas('outlets', fn ($q) => $q->where('outlet_id', $outletId))
|
||||
|
||||
@ -3,10 +3,11 @@
|
||||
namespace App\Traits\Order;
|
||||
|
||||
use App\Models\OrderItem;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
trait WithOrderItem
|
||||
{
|
||||
public function loadOrderItems()
|
||||
public function loadOrderItems(): Collection
|
||||
{
|
||||
return $this->items = OrderItem::query()
|
||||
->currentUser()
|
||||
|
||||
@ -11,7 +11,7 @@ trait WithUpdateItem
|
||||
public string $modalTitle = 'Ubah Item';
|
||||
|
||||
#[On('modal:open')]
|
||||
public function openModal(OrderItem $item)
|
||||
public function openModal(OrderItem $item): void
|
||||
{
|
||||
$this->modalTitle = $item->orderable->name;
|
||||
|
||||
@ -20,12 +20,12 @@ public function openModal(OrderItem $item)
|
||||
$this->form->quantity_edit = formatCurrencyNumber($item->quantity, '');
|
||||
}
|
||||
|
||||
public function closeModal()
|
||||
public function closeModal(): void
|
||||
{
|
||||
$this->reset('form.item_id');
|
||||
}
|
||||
|
||||
public function updateItem()
|
||||
public function updateItem(): void
|
||||
{
|
||||
$item = OrderItem::find($this->form->item_id);
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
trait WithUpdateStock
|
||||
{
|
||||
public function increaseOutletStock($outlet, $item)
|
||||
public function increaseOutletStock($outlet, $item): void
|
||||
{
|
||||
$quantity = $item->quantity;
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
|
||||
trait WithShowPrice
|
||||
{
|
||||
public function requestPrice(string $module)
|
||||
public function requestPrice(string $module): void
|
||||
{
|
||||
$recentRequest = PriceRequest::where('user_id', auth()->id())
|
||||
->where('module', $module)
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
trait WithAddItem
|
||||
{
|
||||
public function addItem(string $type)
|
||||
public function addItem(string $type): void
|
||||
{
|
||||
switch ($type) {
|
||||
case 'parfum':
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
trait WithCalculateTotal
|
||||
{
|
||||
public function getTotal()
|
||||
public function getTotal(): int
|
||||
{
|
||||
return $this->purchaseItems->sum(fn ($item) => $item->unit_price * $item->quantity);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
|
||||
trait WithDeleteItem
|
||||
{
|
||||
public function deleteItem(PurchaseItem $item)
|
||||
public function deleteItem(PurchaseItem $item): void
|
||||
{
|
||||
$this->purchaseItems = $this->purchaseItems->reject(fn ($i) => $i->id === $item->id);
|
||||
|
||||
|
||||
@ -3,10 +3,11 @@
|
||||
namespace App\Traits\Purchase;
|
||||
|
||||
use App\Models\PurchaseItem;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
trait WithPurchaseItems
|
||||
{
|
||||
public function loadPurchaseItems()
|
||||
public function loadPurchaseItems(): Collection
|
||||
{
|
||||
return $this->purchaseItems = PurchaseItem::query()
|
||||
->currentUser()
|
||||
|
||||
@ -11,7 +11,7 @@ trait WithUpdateItem
|
||||
public string $modalTitle = 'Ubah Item';
|
||||
|
||||
#[On('modal:open')]
|
||||
public function openModal(PurchaseItem $item)
|
||||
public function openModal(PurchaseItem $item): void
|
||||
{
|
||||
$this->modalTitle = $item->purchasable->name;
|
||||
|
||||
@ -25,7 +25,7 @@ public function closeModal()
|
||||
$this->reset('form.item_id');
|
||||
}
|
||||
|
||||
public function updateItem()
|
||||
public function updateItem(): void
|
||||
{
|
||||
$item = PurchaseItem::find($this->form->item_id);
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
trait WithUpdateStock
|
||||
{
|
||||
public function increaseOutletStock($outlet, $item)
|
||||
public function increaseOutletStock($outlet, $item): void
|
||||
{
|
||||
$quantity = $item->quantity;
|
||||
|
||||
@ -56,7 +56,7 @@ public function increaseOutletStock($outlet, $item)
|
||||
->log('Stok '.$item->purchasable->name.' di '.$outlet->name.' bertambah '.formatCurrencyNumber($quantity));
|
||||
}
|
||||
|
||||
public function decreaseOutletStock($outlet, $item)
|
||||
public function decreaseOutletStock($outlet, $item): void
|
||||
{
|
||||
$quantity = $item->quantity;
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
trait WithUpdatedData
|
||||
{
|
||||
public function updated(string $propertyName, $value)
|
||||
public function updated(string $propertyName, $value): void
|
||||
{
|
||||
$this->validateOnly($propertyName);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user