Skip to content

Commit

Permalink
Upgrade to simple cache 3 (#4)
Browse files Browse the repository at this point in the history
* Updated PHP requirement to >=8.0 and removed mindplay/simple-cache dev-dependency

* Updated to PHPUnit ^9.5 and migrated configuration

* Updated simple-cache to ^2||^3

* Updated DatabaseCache::get signature

* Updated DatabaseCache::set signature

* Updated DatabaseCache::delete signature

* Updated DatabaseCache::clear signature

* Updated DatabaseCache::getMultiple signature

* Updated DatabaseCache::setMultiple signature

* Updated DatabaseCache::deleteMultiple signature

* Updated DatabaseCache::has signature

* Consolidated abstract test classes

* Removed interaction with `skippedTests` since it has been removed

* Changed `testSetMultipleInvalidTtl` to expect `TypeError`. Added strict typing to `DatabaseCache` and `DatabaseCacheIntegrationTest`

* Updated remaining tests that were broken by the added type hints

* Removed Scrutinizer integration

* Removed composer.lock to avoid locking packages that require PHP >=8.1
  • Loading branch information
vortrixs committed Aug 24, 2022
1 parent ba6749e commit d0c85d0
Show file tree
Hide file tree
Showing 4 changed files with 616 additions and 796 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require": {
"php": ">= 8.0",
"psr/simple-cache": "^1",
"psr/simple-cache": "^2||^3",
"ext-pdo": "*"
},
"require-dev": {
Expand Down
20 changes: 11 additions & 9 deletions src/DatabaseCache.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Kodus\Cache;

use DateInterval;
Expand Down Expand Up @@ -53,7 +55,7 @@ public function __construct(PDO $pdo, string $table_name, int $default_ttl)
$this->default_ttl = $default_ttl;
}

public function get($key, $default = null)
public function get(string $key, mixed $default = null): mixed
{
$this->validateKey($key);

Expand All @@ -80,7 +82,7 @@ public function get($key, $default = null)
return $value;
}

public function set($key, $value, $ttl = null)
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
{
$this->validateKey($key);

Expand All @@ -91,7 +93,7 @@ public function set($key, $value, $ttl = null)
return true;
}

public function delete($key)
public function delete(string $key): bool
{
$this->validateKey($key);

Expand All @@ -100,14 +102,14 @@ public function delete($key)
return true;
}

public function clear()
public function clear(): bool
{
$this->adapter->truncate();

return true;
}

public function getMultiple($keys, $default = null)
public function getMultiple(iterable $keys, mixed $default = null): iterable
{
if (! is_array($keys)) {
if ($keys instanceof Traversable) {
Expand Down Expand Up @@ -142,7 +144,7 @@ public function getMultiple($keys, $default = null)
return $values;
}

public function setMultiple($values, $ttl = null)
public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool
{
if (! is_array($values) && ! $values instanceof Traversable) {
throw new InvalidArgumentException("keys must be either of type array or Traversable");
Expand All @@ -163,7 +165,7 @@ public function setMultiple($values, $ttl = null)
return true;
}

public function deleteMultiple($keys)
public function deleteMultiple(iterable $keys): bool
{
if (! is_array($keys)) {
if ($keys instanceof Traversable) {
Expand All @@ -184,7 +186,7 @@ public function deleteMultiple($keys)
return true;
}

public function has($key)
public function has(string $key): bool
{
return $this->get($key, $this) !== $this;
}
Expand Down Expand Up @@ -253,7 +255,7 @@ private function expirationFromTTL($ttl): int
if (is_int($ttl)) {
return $this->getTime() + $ttl;
} elseif ($ttl instanceof DateInterval) {
return date_create_from_format("U", $this->getTime())->add($ttl)->getTimestamp();
return date_create_from_format("U", (string) $this->getTime())->add($ttl)->getTimestamp();
} elseif ($ttl === null) {
return $this->getTime() + $this->default_ttl;
} else {
Expand Down
Loading

0 comments on commit d0c85d0

Please sign in to comment.