1212
1313class Psr6CacheItem implements CacheItemInterface
1414{
15- protected string $ key ;
16-
17- /**
18- * @var mixed
19- */
20- protected $ value ;
21-
22- protected ?DateTimeInterface $ expiration ;
23-
2415 /**
2516 * @param string $key
2617 * @param mixed $value
2718 * @param DateTimeInterface|null $expiration
2819 */
29- public function __construct (string $ key , $ value , ? DateTimeInterface $ expiration = null )
30- {
31- $ this -> key = $ key ;
32- $ this -> value = $ value ;
33- $ this -> expiration = $ expiration ;
20+ public function __construct (
21+ private readonly string $ key ,
22+ private mixed $ value ,
23+ private ? DateTimeInterface $ expiration = null
24+ ) {
3425 }
3526
3627 /**
@@ -44,7 +35,7 @@ public function getKey(): string
4435 /**
4536 * @inheritDoc
4637 */
47- public function get ()
38+ public function get (): mixed
4839 {
4940 return $ this ->value ;
5041 }
@@ -60,7 +51,7 @@ public function isHit(): bool
6051 /**
6152 * @inheritDoc
6253 */
63- public function set ($ value ): self
54+ public function set ($ value ): static
6455 {
6556 $ this ->value = $ value ;
6657 return $ this ;
@@ -69,7 +60,7 @@ public function set($value): self
6960 /**
7061 * @inheritDoc
7162 */
72- public function expiresAt ($ expiration ): self
63+ public function expiresAt ($ expiration ): static
7364 {
7465 $ this ->expiration = $ expiration ;
7566 return $ this ;
@@ -78,13 +69,17 @@ public function expiresAt($expiration): self
7869 /**
7970 * @inheritDoc
8071 */
81- public function expiresAfter ($ time ): self
72+ public function expiresAfter ($ time ): static
8273 {
8374 if (is_int ($ time )) {
8475 if ($ time <= 0 ) {
8576 throw new InvalidArgumentException ('$time should be a positive integer, DateInterval, or null. ' );
8677 }
87- $ this ->expiration = (new DateTimeImmutable ())->add (DateInterval::createFromDateString ("{$ time } seconds " ));
78+ $ interval = DateInterval::createFromDateString ("$ time seconds " );
79+ if ($ interval === false ) {
80+ throw new InvalidArgumentException ('Failed to parse DateInterval. ' );
81+ }
82+ $ this ->expiration = (new DateTimeImmutable ())->add ($ interval );
8883 } elseif ($ time instanceof DateInterval) {
8984 $ this ->expiration = (new DateTimeImmutable ())->add ($ time );
9085 } else {
0 commit comments