test(casts): add tests for ShopperEstablishmentCodeCast functionality test(casts): add tests for ShopperServiceCodeCast functionality test(casts): add tests for ShopperSiteCodeCast functionality test(dto): update ProductDtoTest to include additional fields test(dto): update SettingDtoTest to remove arcadiaSites assertions test(events): update AnOrderHasBeenPlacedTest to use value objects test(entities): update OrderTest to use value objects for employee details test(value-objects): update EmployeeUpsertDataTest to use value objects test(pagination): update PaginationTest to access value properties test(services): update AppCustomerAuthServiceTest to use CrmHashcode test(services): update CrmServiceTest to use CrmHashcode for customer retrieval
85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\Setting;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class SettingDto implements Arrayable, UrlRoutable
|
|
{
|
|
/**
|
|
* @param array<int, string> $employeeSites
|
|
*/
|
|
public function __construct(
|
|
public int $id,
|
|
public array $employeeSites = [],
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(Setting $setting): self
|
|
{
|
|
return new self(
|
|
id: $setting->id,
|
|
employeeSites: $setting->employee_sites ?? [],
|
|
);
|
|
}
|
|
|
|
public function employeeSitesAsString(): string
|
|
{
|
|
return implode(', ', $this->employeeSites);
|
|
}
|
|
|
|
/**
|
|
* @return array<int, \Domain\Models\ValueObjects\ShopperSiteCode>
|
|
*/
|
|
public function getShopperSiteCodes(): array
|
|
{
|
|
return array_map(
|
|
static fn (string $site): ShopperSiteCode => new ShopperSiteCode($site),
|
|
$this->employeeSites
|
|
);
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'setting';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array{id: int, employee_sites: array<int, string>}
|
|
*/
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'employee_sites' => $this->employeeSites,
|
|
];
|
|
}
|
|
}
|