mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
Fix 3 PHPStan errors in StoreScraperStrategySetCast (redundant is_array after @implements generic narrows type) and AiConfigHealer (assign array to DTO-typed property — wrap in StoreScraperStrategySetDto::fromArray). Update DeterministicHealTest and StoreSelfHealUiTest to assert against DTO properties instead of legacy array shapes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use App\Dto\StoreScraperStrategySetDto;
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Casts the stores.scrape_strategy JSON column to/from a StoreScraperStrategySetDto.
|
|
*
|
|
* @implements CastsAttributes<StoreScraperStrategySetDto, StoreScraperStrategySetDto|array<string, mixed>>
|
|
*/
|
|
class StoreScraperStrategySetCast implements CastsAttributes
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $attributes
|
|
*/
|
|
public function get(Model $model, string $key, mixed $value, array $attributes): StoreScraperStrategySetDto
|
|
{
|
|
$decoded = is_string($value) ? json_decode($value, true) : $value;
|
|
|
|
return StoreScraperStrategySetDto::fromArray(is_array($decoded) ? $decoded : null);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $attributes
|
|
*/
|
|
public function set(Model $model, string $key, mixed $value, array $attributes): ?string
|
|
{
|
|
if ($value === null) {
|
|
return null;
|
|
}
|
|
|
|
if ($value instanceof StoreScraperStrategySetDto) {
|
|
return json_encode($value->toArray());
|
|
}
|
|
|
|
return json_encode(StoreScraperStrategySetDto::fromArray($value)->toArray());
|
|
}
|
|
}
|