25 lines
944 B
PHP
25 lines
944 B
PHP
<?php
|
||||
|
|
|
|||
|
|
namespace App\Serp\Data;
|
|||
|
|
|
|||
|
|
use InvalidArgumentException;
|
|||
|
|
|
|||
|
|
final readonly class SerpResponse
|
|||
|
|
{
|
|||
|
|
public array $results;
|
|||
|
|
|
|||
|
|
public function __construct(public string $providerKey, array $results, public ?string $referenceId = null, int $limit = 100, public string|int|float|null $cost = null, public string $currency = 'USD', public ?int $statusCode = null)
|
|||
|
|
{
|
|||
|
|
if (count($results) > $limit) {
|
|||
|
|
throw new InvalidArgumentException('Sonuç limiti aşıldı.');
|
|||
|
|
}foreach ($results as $r) {
|
|||
|
|
if (! $r instanceof SerpResultData) {
|
|||
|
|
throw new InvalidArgumentException('Geçersiz sonuç verisi.');
|
|||
|
|
}
|
|||
|
|
}$positions = array_map(fn ($r) => $r->position, $results);
|
|||
|
|
if (count($positions) !== count(array_unique($positions))) {
|
|||
|
|
throw new InvalidArgumentException('Tekrarlanan sonuç pozisyonu.');
|
|||
|
|
}$this->results = array_values($results);
|
|||
|
|
}
|
|||
|
|
}
|