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