Skip to content

Commit

Permalink
fix: allow null in archive timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin committed Feb 6, 2025
1 parent 74c5e9b commit c4a4b8b
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion library/PostObject/Date/CachedTimestampResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(
*
* @return int
*/
public function resolve(): int
public function resolve(): ?int
{
$cacheKey = "{$this->postObject->getBlogId()}_{$this->postObject->getId()}";

Expand Down
10 changes: 7 additions & 3 deletions library/PostObject/Date/TimestampResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,33 @@ public function __construct(
*
* @return int
*/
public function resolve(): int
public function resolve(): ?int
{
$archiveDateSetting = $this->archiveDateSetting->resolve();

if (in_array($archiveDateSetting, $this->defaultTimestamps)) {
return $this->getDefaultTimestamp($archiveDateSetting);
}

if ($archiveDateSetting === 'none') {
return null;
}

return $this->getDateMetaValue($archiveDateSetting);
}

/**
* Get the date meta value.
*/
private function getDateMetaValue(string $archiveDateSetting): int
private function getDateMetaValue(string $archiveDateSetting): ?int
{
$metaValue = $this->wpService->getPostMeta($this->postObject->getId(), $archiveDateSetting, true);

if ($metaValue) {
return strtotime($metaValue);
}

return 0;
return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/PostObject/Date/TimestampResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface TimestampResolverInterface
*
* @return int
*/
public function resolve(): int;
public function resolve(): ?int;
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/IconResolvingPostObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->timestampResolver->resolve();
}
Expand Down
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/PostObjectFromOtherBlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
2 changes: 1 addition & 1 deletion library/PostObject/Decorators/PostObjectFromWpPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return $this->postObject->getArchiveDateTimestamp();
}
Expand Down
4 changes: 2 additions & 2 deletions library/PostObject/PostObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public function getModifiedTime(bool $gmt = false): int
/**
* @inheritDoc
*/
public function getArchiveDateTimestamp(): int
public function getArchiveDateTimestamp(): ?int
{
return 0;
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions library/PostObject/PostObject.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ public function testGetBlogIdReturns1()
/**
* @testdox getArchiveDateTimestamp() returns 0
*/
public function testGetArchiveDateTimestampReturns0()
public function testGetArchiveDateTimestampReturnsNull()
{
$this->assertEquals(0, $this->instance->getArchiveDateTimestamp());
$this->assertEquals(null, $this->instance->getArchiveDateTimestamp());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/PostObject/PostObjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getModifiedTime(bool $gmt = false): int;
*
* @return int
*/
public function getArchiveDateTimestamp(): int;
public function getArchiveDateTimestamp(): ?int;

/**
* Get the post object date format.
Expand Down

0 comments on commit c4a4b8b

Please sign in to comment.