Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Contracts/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class Version
*/
public function __construct(
private readonly string $commitSha,
private readonly \DateTimeImmutable $commitDate,
private readonly ?\DateTimeImmutable $commitDate,
private readonly string $pkgVersion,
) {
}
Expand All @@ -25,7 +25,7 @@ public function getCommitSha(): string
return $this->commitSha;
}

public function getCommitDate(): \DateTimeImmutable
public function getCommitDate(): ?\DateTimeImmutable
{
return $this->commitDate;
}
Expand All @@ -44,9 +44,14 @@ public function getPkgVersion(): string
*/
public static function fromArray(array $data): Version
{
$commitDate = null;
if ('unknown' !== $data['commitDate']) {
$commitDate = new \DateTimeImmutable($data['commitDate']);
}

return new self(
$data['commitSha'],
new \DateTimeImmutable($data['commitDate']),
$commitDate,
$data['pkgVersion'],
);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/Contracts/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ public function testFromArray(): void
self::assertEquals(new \DateTimeImmutable('2025-11-15 10:03:15.000000'), $version->getCommitDate());
self::assertSame('1.26.0', $version->getPkgVersion());
}

public function testFromArrayWithUnknownCommitDate(): void
{
$version = Version::fromArray([
'commitSha' => 'ea70a7d1c90b4d87c1c3319e9bf280dc790f7f5e',
'commitDate' => 'unknown',
'pkgVersion' => '1.26.0',
]);

self::assertSame('ea70a7d1c90b4d87c1c3319e9bf280dc790f7f5e', $version->getCommitSha());
self::assertNull($version->getCommitDate());
self::assertSame('1.26.0', $version->getPkgVersion());
}
}