From c697f8edca1fa9f9cd2509265962e49c0d59e348 Mon Sep 17 00:00:00 2001 From: Taylor Vance Date: Wed, 18 Dec 2024 08:27:53 -0600 Subject: [PATCH] More explicit nullable types for PHP 8.4 --- src/Stash/Interfaces/ItemInterface.php | 8 ++++---- src/Stash/Interfaces/PoolInterface.php | 2 +- src/Stash/Item.php | 12 ++++++------ src/Stash/Pool.php | 4 ++-- src/Stash/Utilities.php | 2 +- tests/Stash/Test/Driver/AbstractDriverTestCase.php | 2 +- tests/Stash/Test/Stubs/PoolGetDriverStub.php | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Stash/Interfaces/ItemInterface.php b/src/Stash/Interfaces/ItemInterface.php index 2ef1475a..602aab7e 100644 --- a/src/Stash/Interfaces/ItemInterface.php +++ b/src/Stash/Interfaces/ItemInterface.php @@ -33,7 +33,7 @@ public function setPool(PoolInterface $driver): void; * @param array $key * @param string|null $namespace */ - public function setKey(array $key, string $namespace = null): void; + public function setKey(array $key, ?string $namespace = null): void; /** * This disables any IO operations by this object, effectively preventing @@ -91,7 +91,7 @@ public function isMiss(): bool; * @param null $ttl * @return bool */ - public function lock(int $ttl = null): bool; + public function lock(?int $ttl = null): bool; /** * Takes and stores data for later retrieval. This data can be any php data, @@ -110,7 +110,7 @@ public function set(mixed $value): static; * @param int|\DateInterval|null $ttl * @return \Stash\Item|bool */ - public function extend(int|\DateInterval $ttl = null): \Stash\Item|bool; + public function extend(int|\DateInterval|null $ttl = null): \Stash\Item|bool; /** * Return true if caching is disabled @@ -163,7 +163,7 @@ public function expiresAt(\DateTimeInterface|null $expiration): static; * @param int|\DateInterval|\DateTimeInterface|null $ttl An integer, date interval, or date * @return self */ - public function setTTL(int|\DateInterval|\DateTimeInterface $ttl = null): static; + public function setTTL(int|\DateInterval|\DateTimeInterface|null $ttl = null): static; /** * Set the cache invalidation method for this item. diff --git a/src/Stash/Interfaces/PoolInterface.php b/src/Stash/Interfaces/PoolInterface.php index 37ff3c9c..e765d675 100644 --- a/src/Stash/Interfaces/PoolInterface.php +++ b/src/Stash/Interfaces/PoolInterface.php @@ -117,7 +117,7 @@ public function getDriver(): DriverInterface; * @return bool * @throws \InvalidArgumentException Namespaces must be alphanumeric */ - public function setNamespace(string $namespace = null): bool; + public function setNamespace(?string $namespace = null): bool; /** * Returns the current namespace, or false if no namespace was set. diff --git a/src/Stash/Item.php b/src/Stash/Item.php index 15f6d820..c134c5c6 100644 --- a/src/Stash/Item.php +++ b/src/Stash/Item.php @@ -173,7 +173,7 @@ public function setPool(PoolInterface $pool): void * @param array $key the key to set for this cache item * @param string $namespace the namespace for this cache item */ - public function setKey(array $key, string $namespace = null): void + public function setKey(array $key, ?string $namespace = null): void { $this->namespace = $namespace; @@ -360,7 +360,7 @@ public function isMiss(): bool * @param int $ttl time to live * @return bool */ - public function lock(int $ttl = null): bool + public function lock(?int $ttl = null): bool { if ($this->isDisabled()) { return true; @@ -407,7 +407,7 @@ public function set(mixed $value): static * @param int|\DateInterval|\DateTimeInterface|null $ttl time to live * @return \Stash\Item */ - public function setTTL(int|\DateInterval|\DateTimeInterface $ttl = null): static + public function setTTL(int|\DateInterval|\DateTimeInterface|null $ttl = null): static { if (is_numeric($ttl) || ($ttl instanceof \DateInterval)) { return $this->expiresAfter($ttl); @@ -427,7 +427,7 @@ public function setTTL(int|\DateInterval|\DateTimeInterface $ttl = null): static * @throws \Stash\Exception\InvalidArgumentException * @return \Stash\Item */ - public function expiresAt(int|\DateInterval|\DateTimeInterface $expiration = null): static + public function expiresAt(int|\DateInterval|\DateTimeInterface|null $expiration = null): static { if (!is_null($expiration) && !($expiration instanceof \DateTimeInterface)) { # For compatbility with PHP 5.4 we also allow inheriting from the DateTime object. @@ -526,10 +526,10 @@ protected function executeSet(mixed $data, int|\DateTimeInterface|null $time): b /** * {@inheritdoc} * - * @param int|\DateInterval $ttl time to live + * @param int|\DateInterval|null $ttl time to live * @return \Stash\Item|false */ - public function extend(int|\DateInterval $ttl = null): \Stash\Item|bool + public function extend(int|\DateInterval|null $ttl = null): \Stash\Item|bool { if ($this->isDisabled()) { return false; diff --git a/src/Stash/Pool.php b/src/Stash/Pool.php index 0cd7e982..223e12ac 100644 --- a/src/Stash/Pool.php +++ b/src/Stash/Pool.php @@ -92,7 +92,7 @@ class Pool implements PoolInterface * * @param DriverInterface $driver */ - public function __construct(DriverInterface $driver = null) + public function __construct(?DriverInterface $driver = null) { if (isset($driver)) { $this->setDriver($driver); @@ -296,7 +296,7 @@ public function getDriver(): DriverInterface /** * {@inheritdoc} */ - public function setNamespace(string $namespace = null): bool + public function setNamespace(?string $namespace = null): bool { if (is_null($namespace)) { $this->namespace = null; diff --git a/src/Stash/Utilities.php b/src/Stash/Utilities.php index dc8ed961..c868bff0 100644 --- a/src/Stash/Utilities.php +++ b/src/Stash/Utilities.php @@ -100,7 +100,7 @@ public static function decode($data, $method) * @param DriverInterface $driver * @return string Path for Stash files */ - public static function getBaseDirectory(DriverInterface $driver = null) + public static function getBaseDirectory(?DriverInterface $driver = null) { $tmp = rtrim(sys_get_temp_dir(), '/\\') . '/'; diff --git a/tests/Stash/Test/Driver/AbstractDriverTestCase.php b/tests/Stash/Test/Driver/AbstractDriverTestCase.php index 53ca8d98..197ff09c 100644 --- a/tests/Stash/Test/Driver/AbstractDriverTestCase.php +++ b/tests/Stash/Test/Driver/AbstractDriverTestCase.php @@ -66,7 +66,7 @@ protected function setUp() : void } } - protected function getFreshDriver(array $options = null) + protected function getFreshDriver(?array $options = null) { $driverClass = $this->driverClass; diff --git a/tests/Stash/Test/Stubs/PoolGetDriverStub.php b/tests/Stash/Test/Stubs/PoolGetDriverStub.php index 2db3828a..c74949dd 100644 --- a/tests/Stash/Test/Stubs/PoolGetDriverStub.php +++ b/tests/Stash/Test/Stubs/PoolGetDriverStub.php @@ -60,7 +60,7 @@ public function purge(): bool return false; } - public function setNamespace(string $namespace = null): bool + public function setNamespace(?string $namespace = null): bool { return false; }