Files
branch-usage-checker/app/Dto/PackagistApiPackagePayload.php
Ismo Vuorinen 728388b473 refactor(dto): replace spatie/data-transfer-object with plain readonly class (#46)
The spatie/data-transfer-object package is abandoned. Replace it with a
native PHP 8.4 final readonly class using a static factory method,
removing the dependency entirely.
2026-02-24 21:36:21 +02:00

34 lines
901 B
PHP

<?php
namespace App\Dto;
final readonly class PackagistApiPackagePayload
{
public function __construct(
public string $name = '',
public string $description = '',
public string $time = '',
public array $versions = [],
public string $type = '',
public string $repository = '',
public string $language = '',
) {
}
/** Create from the raw Packagist API response array. */
public static function fromResponse(array $data): self
{
$pkg = $data['package'] ?? [];
return new self(
name: $pkg['name'] ?? '',
description: $pkg['description'] ?? '',
time: $pkg['time'] ?? '',
versions: $pkg['versions'] ?? [],
type: $pkg['type'] ?? '',
repository: $pkg['repository'] ?? '',
language: $pkg['language'] ?? '',
);
}
}