Files
2026-08-29 15:53:53 +03:00

25 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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.');
}
}
}