Skip to content

Commit 082c9c1

Browse files
authored
fix: allow null in archive timestamp (#1318)
1 parent 74c5e9b commit 082c9c1

13 files changed

+21
-17
lines changed

library/PostObject/Date/CachedTimestampResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
*
2929
* @return int
3030
*/
31-
public function resolve(): int
31+
public function resolve(): ?int
3232
{
3333
$cacheKey = "{$this->postObject->getBlogId()}_{$this->postObject->getId()}";
3434

library/PostObject/Date/TimestampResolver.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,33 @@ public function __construct(
3131
*
3232
* @return int
3333
*/
34-
public function resolve(): int
34+
public function resolve(): ?int
3535
{
3636
$archiveDateSetting = $this->archiveDateSetting->resolve();
3737

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

42+
if ($archiveDateSetting === 'none') {
43+
return null;
44+
}
45+
4246
return $this->getDateMetaValue($archiveDateSetting);
4347
}
4448

4549
/**
4650
* Get the date meta value.
4751
*/
48-
private function getDateMetaValue(string $archiveDateSetting): int
52+
private function getDateMetaValue(string $archiveDateSetting): ?int
4953
{
5054
$metaValue = $this->wpService->getPostMeta($this->postObject->getId(), $archiveDateSetting, true);
5155

5256
if ($metaValue) {
5357
return strtotime($metaValue);
5458
}
5559

56-
return 0;
60+
return null;
5761
}
5862

5963
/**

library/PostObject/Date/TimestampResolverInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ interface TimestampResolverInterface
99
*
1010
* @return int
1111
*/
12-
public function resolve(): int;
12+
public function resolve(): ?int;
1313
}

library/PostObject/Decorators/BackwardsCompatiblePostObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function getModifiedTime(bool $gmt = false): int
135135
/**
136136
* @inheritDoc
137137
*/
138-
public function getArchiveDateTimestamp(): int
138+
public function getArchiveDateTimestamp(): ?int
139139
{
140140
return $this->postObject->getArchiveDateTimestamp();
141141
}

library/PostObject/Decorators/IconResolvingPostObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getModifiedTime(bool $gmt = false): int
9393
/**
9494
* @inheritDoc
9595
*/
96-
public function getArchiveDateTimestamp(): int
96+
public function getArchiveDateTimestamp(): ?int
9797
{
9898
return $this->postObject->getArchiveDateTimestamp();
9999
}

library/PostObject/Decorators/PostObjectArchiveDateFormat.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
103103
/**
104104
* @inheritDoc
105105
*/
106-
public function getArchiveDateTimestamp(): int
106+
public function getArchiveDateTimestamp(): ?int
107107
{
108108
return $this->postObject->getArchiveDateTimestamp();
109109
}

library/PostObject/Decorators/PostObjectArchiveDateTimestamp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getModifiedTime(bool $gmt = false): int
103103
/**
104104
* @inheritDoc
105105
*/
106-
public function getArchiveDateTimestamp(): int
106+
public function getArchiveDateTimestamp(): ?int
107107
{
108108
return $this->timestampResolver->resolve();
109109
}

library/PostObject/Decorators/PostObjectFromOtherBlog.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function getModifiedTime(bool $gmt = false): int
126126
/**
127127
* @inheritDoc
128128
*/
129-
public function getArchiveDateTimestamp(): int
129+
public function getArchiveDateTimestamp(): ?int
130130
{
131131
return $this->postObject->getArchiveDateTimestamp();
132132
}

library/PostObject/Decorators/PostObjectFromWpPost.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function getModifiedTime(bool $gmt = false): int
9898
/**
9999
* @inheritDoc
100100
*/
101-
public function getArchiveDateTimestamp(): int
101+
public function getArchiveDateTimestamp(): ?int
102102
{
103103
return $this->postObject->getArchiveDateTimestamp();
104104
}

library/PostObject/Decorators/PostObjectWithSeoRedirect.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function getModifiedTime(bool $gmt = false): int
107107
/**
108108
* @inheritDoc
109109
*/
110-
public function getArchiveDateTimestamp(): int
110+
public function getArchiveDateTimestamp(): ?int
111111
{
112112
return $this->postObject->getArchiveDateTimestamp();
113113
}

library/PostObject/PostObject.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ public function getModifiedTime(bool $gmt = false): int
9393
/**
9494
* @inheritDoc
9595
*/
96-
public function getArchiveDateTimestamp(): int
96+
public function getArchiveDateTimestamp(): ?int
9797
{
98-
return 0;
98+
return null;
9999
}
100100

101101
/**

library/PostObject/PostObject.test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ public function testGetBlogIdReturns1()
7979
/**
8080
* @testdox getArchiveDateTimestamp() returns 0
8181
*/
82-
public function testGetArchiveDateTimestampReturns0()
82+
public function testGetArchiveDateTimestampReturnsNull()
8383
{
84-
$this->assertEquals(0, $this->instance->getArchiveDateTimestamp());
84+
$this->assertEquals(null, $this->instance->getArchiveDateTimestamp());
8585
}
8686

8787
/**

library/PostObject/PostObjectInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function getModifiedTime(bool $gmt = false): int;
7878
*
7979
* @return int
8080
*/
81-
public function getArchiveDateTimestamp(): int;
81+
public function getArchiveDateTimestamp(): ?int;
8282

8383
/**
8484
* Get the post object date format.

0 commit comments

Comments
 (0)