Files
pricebuddy/app/Casts/StoreScraperStrategySetCast.php
JeremyandClaude Sonnet 4.6 f7d24f52b7 chore: scrape strategy DTO refactor — phpcs + full suite green
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>
2026-06-14 13:03:28 +10:00

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());
}
}