25 lines
1.1 KiB
PHP
25 lines
1.1 KiB
PHP
<?php
|
||||
|
|
|
|||
|
|
namespace App\Serp\Data;
|
|||
|
|
|
|||
|
|
use InvalidArgumentException;
|
|||
|
|
|
|||
|
|
final readonly class SerpResultData
|
|||
|
|
{
|
|||
|
|
public function __construct(public int $position, public string $url, public ?string $title = null, public ?string $displayUrl = null, public ?string $snippet = null, public string $resultType = 'organic')
|
|||
|
|
{
|
|||
|
|
if ($position < 1) {
|
|||
|
|
throw new InvalidArgumentException('Position pozitif olmalıdır.');
|
|||
|
|
}
|
|||
|
|
if ($resultType !== 'organic') {
|
|||
|
|
throw new InvalidArgumentException('Desteklenmeyen sonuç türü.');
|
|||
|
|
}
|
|||
|
|
if (strlen($url) > 2048 || ! filter_var($url, FILTER_VALIDATE_URL) || ! in_array(strtolower((string) parse_url($url, PHP_URL_SCHEME)), ['http', 'https'], true)) {
|
|||
|
|
throw new InvalidArgumentException('Geçersiz sonuç URL adresi.');
|
|||
|
|
}
|
|||
|
|
if (($title !== null && mb_strlen($title) > 500) || ($displayUrl !== null && mb_strlen($displayUrl) > 500) || ($snippet !== null && mb_strlen($snippet) > 5000)) {
|
|||
|
|
throw new InvalidArgumentException('Sonuç alanı izin verilen uzunluğu aşıyor.');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|