mirror of
https://github.com/ivuorinen/branch-usage-checker.git
synced 2026-02-25 20:52:37 +00:00
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.
This commit is contained in:
@@ -48,7 +48,7 @@ class CheckCommand extends Command
|
||||
$this->filter = now()->subMonths($months)->day(1)->toDateString();
|
||||
|
||||
try {
|
||||
$pkg = new PackagistApiPackagePayload($payload->json());
|
||||
$pkg = PackagistApiPackagePayload::fromResponse($payload->json());
|
||||
$this->info('Found the package. Type: ' . $pkg->type);
|
||||
|
||||
$versions = collect($pkg->versions ?? [])
|
||||
|
||||
@@ -2,22 +2,32 @@
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
use Spatie\DataTransferObject\Attributes\MapFrom;
|
||||
|
||||
class PackagistApiPackagePayload extends \Spatie\DataTransferObject\DataTransferObject
|
||||
final readonly class PackagistApiPackagePayload
|
||||
{
|
||||
#[MapFrom('package.name')]
|
||||
public string $name = '';
|
||||
#[MapFrom('package.description')]
|
||||
public string $description = '';
|
||||
#[MapFrom('package.time')]
|
||||
public string $time = '';
|
||||
#[MapFrom('package.versions')]
|
||||
public array $versions = [];
|
||||
#[MapFrom('package.type')]
|
||||
public string $type = '';
|
||||
#[MapFrom('package.repository')]
|
||||
public string $repository = '';
|
||||
#[MapFrom('package.language')]
|
||||
public string $language = '';
|
||||
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'] ?? '',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user