Total Complexity | 6 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 61.11% |
Changes | 0 |
1 | <?php |
||
11 | class Proxy |
||
12 | { |
||
13 | /** |
||
14 | * @var Client |
||
15 | */ |
||
16 | private $client; |
||
17 | |||
18 | /** |
||
19 | * @var Cache |
||
20 | */ |
||
21 | private $cache; |
||
22 | |||
23 | const CACHE_KEY_PREFIX = 'ttskch.esa.proxy'; |
||
24 | |||
25 | /** |
||
26 | * @param Client $client |
||
27 | * @param Cache $cache |
||
28 | */ |
||
29 | 4 | public function __construct(Client $client, Cache $cache) |
|
33 | 4 | } |
|
34 | |||
35 | /** |
||
36 | * @param int $postId |
||
37 | * @param bool $force |
||
38 | * @return array |
||
39 | */ |
||
40 | 4 | public function getPost($postId, $force = false) |
|
41 | { |
||
42 | 4 | $cacheKey = sprintf('%s.post.%d', self::CACHE_KEY_PREFIX, $postId); |
|
43 | |||
44 | 4 | if (!$force && $post = $this->cache->fetch($cacheKey)) { |
|
45 | 1 | return $post; |
|
46 | } |
||
47 | |||
48 | 3 | $post = $this->client->post($postId); |
|
49 | 3 | $this->cache->save($cacheKey, $post); |
|
50 | |||
51 | 3 | return $post; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return array |
||
56 | */ |
||
57 | public function getEmojis() |
||
69 | } |
||
70 | } |
||
71 |