Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SecurityCheckResult | |
100.00% |
23 / 23 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| fromArray | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Integrations\Domain\Contract; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Result data transfer object for security inspection of IP, domain or link. |
| 13 | */ |
| 14 | final readonly class SecurityCheckResult |
| 15 | { |
| 16 | /** |
| 17 | * @param string $type Type of inspected entity ('ip', 'domain', 'url', 'spf_dkim'). |
| 18 | * @param string $target Target value (e.g. IP address, domain name, full URL). |
| 19 | * @param bool $isSafe Whether the target is considered clean and safe. |
| 20 | * @param string $status Normalized status ('safe', 'suspicious', 'dangerous', 'unknown'). |
| 21 | * @param string $summary Human-readable one-line summary message. |
| 22 | * @param string $provider Provider identifier (e.g. 'abuseipdb', 'google_safe_browsing'). |
| 23 | * @param array<string, mixed>$details Detailed technical metrics and engine breakdown. |
| 24 | * @param int $cachedTtl Recommended cache time-to-live in seconds. |
| 25 | */ |
| 26 | public function __construct( |
| 27 | public string $type, |
| 28 | public string $target, |
| 29 | public bool $isSafe, |
| 30 | public string $status, |
| 31 | public string $summary, |
| 32 | public string $provider, |
| 33 | public array $details = [], |
| 34 | public int $cachedTtl = 86400, |
| 35 | public ?int $threatScore = null |
| 36 | ) { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Serializes result to associative array for JSON storage or API responses. |
| 41 | * |
| 42 | * @return array<string, mixed> |
| 43 | */ |
| 44 | public function toArray(): array |
| 45 | { |
| 46 | return [ |
| 47 | 'type' => $this->type, |
| 48 | 'target' => $this->target, |
| 49 | 'is_safe' => $this->isSafe, |
| 50 | 'status' => $this->status, |
| 51 | 'summary' => $this->summary, |
| 52 | 'provider' => $this->provider, |
| 53 | 'details' => $this->details, |
| 54 | 'cached_ttl' => $this->cachedTtl, |
| 55 | 'threat_score' => $this->threatScore, |
| 56 | ]; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Reconstructs result object from serialized cache array. |
| 61 | * |
| 62 | * @param array<string, mixed> $data Serialized array data. |
| 63 | * @return self |
| 64 | */ |
| 65 | public static function fromArray(array $data): self |
| 66 | { |
| 67 | return new self( |
| 68 | type: (string) ($data['type'] ?? 'unknown'), |
| 69 | target: (string) ($data['target'] ?? ''), |
| 70 | isSafe: (bool) ($data['is_safe'] ?? false), |
| 71 | status: (string) ($data['status'] ?? 'unknown'), |
| 72 | summary: (string) ($data['summary'] ?? ''), |
| 73 | provider: (string) ($data['provider'] ?? 'unknown'), |
| 74 | details: (array) ($data['details'] ?? []), |
| 75 | cachedTtl: (int) ($data['cached_ttl'] ?? 86400), |
| 76 | threatScore: isset($data['threat_score']) ? (int) $data['threat_score'] : null |
| 77 | ); |
| 78 | } |
| 79 | } |