ldc-cocotte/app/Models/Setting.php
Jérémy Munsch 6b649a8e7d
refactor(models): update property types in Setting model
Updated the type annotations for employee_sites to allow mixed types and reordered arcadia_sites for clarity.
2026-10-27 09:58:45 +01:00

80 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Domain\Models\ValueObjects\ShopperSiteCode;
use Illuminate\Database\Eloquent\Model;
/**
* @property int $id
* @property array<array-key, mixed>|null $employee_sites
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property array<string>|null $arcadia_sites
*
* @mixin \Eloquent
*/
class Setting extends Model
{
public const int SINGLETON_ID = 1;
protected $fillable = [
'employee_sites',
];
/**
* @return array<string, string>
*/
#[\Override]
protected function casts(): array
{
return [
'employee_sites' => 'array',
];
}
/**
* Backward-compatibility accessor
*
* @return array<string>|null
*/
public function getArcadiaSitesAttribute(): ?array
{
return $this->employee_sites;
}
/**
* Backward-compatibility mutator
*
* @param array<string>|null $value
*/
public function setArcadiaSitesAttribute(?array $value): void
{
$this->employee_sites = $value;
}
public static function getSingleton(): self
{
/** @var self $setting */
$setting = self::query()->firstOrCreate(['id' => self::SINGLETON_ID], [
'employee_sites' => [],
]);
return $setting;
}
/**
* @return array<int, ShopperSiteCode>
*/
public function getShopperSiteCodes(): array
{
$sites = $this->employee_sites ?? [];
return array_map(
static fn (string $site): ShopperSiteCode => new ShopperSiteCode($site),
$sites
);
}
}