Skip to content

Commit

Permalink
Merge pull request #428 from taylorvance/main
Browse files Browse the repository at this point in the history
More explicit nullable types for PHP 8.4
  • Loading branch information
tedivm authored Dec 18, 2024
2 parents 6f66c55 + c697f8e commit 18256af
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/Stash/Interfaces/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Stash/Interfaces/PoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions src/Stash/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Stash/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Stash/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/\\') . '/';

Expand Down
2 changes: 1 addition & 1 deletion tests/Stash/Test/Driver/AbstractDriverTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected function setUp() : void
}
}

protected function getFreshDriver(array $options = null)
protected function getFreshDriver(?array $options = null)
{
$driverClass = $this->driverClass;

Expand Down
2 changes: 1 addition & 1 deletion tests/Stash/Test/Stubs/PoolGetDriverStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 18256af

Please sign in to comment.