Skip to content

Commit 80fef00

Browse files
Merge pull request #6 from Jarlskov/issue/3-implement-psr-16
Require psr/simple-cache and have NullCache implement it, thanks @Jarlskov
2 parents bc676f5 + bc89ec1 commit 80fef00

File tree

5 files changed

+77
-42
lines changed

5 files changed

+77
-42
lines changed

composer.json

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.6"
13+
"php": ">=5.6",
14+
"psr/simple-cache": "^1.0"
1415
},
1516
"require-dev": {
1617
"phpunit/phpunit": "^5.0"
1718
},
19+
"provide": {
20+
"psr/simple-cache-implementation": "1.0"
21+
},
1822
"autoload": {
1923
"psr-4": {
2024
"DvK\\Vat\\": "src/"

src/Rates/Caches/NullCache.php

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,88 @@
22

33
namespace DvK\Vat\Rates\Caches;
44

5-
use DvK\Vat\Rates\Interfaces\Cache;
6-
7-
class NullCache implements Cache {
5+
use Psr\SimpleCache\CacheInterface;
86

7+
class NullCache implements CacheInterface
8+
{
99
/**
1010
* @param string $key
11+
* @param (optional) mixed $default
1112
*
1213
* @return mixed
1314
*/
14-
public function get($key)
15+
public function get($key, $default = null)
1516
{
16-
return null;
17+
return $default;
1718
}
1819

1920
/**
2021
* @param string $key
2122
* @param mixed $value
22-
* @param int $expiration
23+
* @param null|int|DateInterval $ttl
2324
*
24-
* @return mixed
25+
* @return bool
26+
*/
27+
public function set($key, $value, $expiration = null)
28+
{
29+
return true;
30+
}
31+
32+
/**
33+
* @return bool
34+
*/
35+
public function delete($key)
36+
{
37+
return true;
38+
}
39+
40+
/**
41+
* @return bool
42+
*/
43+
public function clear()
44+
{
45+
return true;
46+
}
47+
48+
/**
49+
* @param iterable $keys
50+
* @param mixed $default
51+
*
52+
* @return iterable
2553
*/
26-
public function put($key, $value, $expiration)
54+
public function getMultiple($keys, $default = null)
2755
{
28-
return null;
56+
return $default;
2957
}
3058

31-
}
59+
/**
60+
* @param iterable $values
61+
* @param null|int|DateInterval $ttl
62+
*
63+
* @return bool
64+
*/
65+
public function setMultiple($values, $ttl = null)
66+
{
67+
return true;
68+
}
69+
70+
/**
71+
* @param iterable $keys
72+
*
73+
* @return bool
74+
*/
75+
public function deleteMultiple($keys)
76+
{
77+
return true;
78+
}
79+
80+
/**
81+
* @param string $key
82+
*
83+
* @return bool
84+
*/
85+
public function has($key)
86+
{
87+
return false;
88+
}
89+
}

src/Rates/Interfaces/Cache.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Rates/Rates.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use DvK\Vat\Rates\Caches\NullCache;
66
use DvK\Vat\Rates\Clients\JsonVat;
7-
use DvK\Vat\Rates\Interfaces\Cache;
87
use DvK\Vat\Rates\Interfaces\Client;
98
use DvK\Vat\Rates\Exceptions\Exception;
9+
use Psr\SimpleCache\CacheInterface;
1010

1111
class Rates
1212
{
@@ -32,7 +32,7 @@ class Rates
3232
* @param Client $client (optional)
3333
* @param Cache $cache (optional)
3434
*/
35-
public function __construct( Client $client = null, Cache $cache = null )
35+
public function __construct( Client $client = null, CacheInterface $cache = null )
3636
{
3737
$this->client = $client;
3838
$this->cache = $cache ? $cache : new NullCache();
@@ -49,7 +49,7 @@ protected function load()
4949
$map = $this->fetch();
5050

5151
// store in cache
52-
$this->cache->put('vat-rates', $map, 86400);
52+
$this->cache->set('vat-rates', $map, 86400);
5353
}
5454

5555
return $map;

tests/RatesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function test_ratesAreStoredInCache() {
116116

117117
$cacheMock
118118
->expects(self::once())
119-
->method('put');
119+
->method('set');
120120

121121
$rates = new Rates( $clientMock, $cacheMock );
122122
}

0 commit comments

Comments
 (0)