Proje dosyaları eklendi
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user