Passed
Pull Request — master (#15)
by Takashi
05:35
created

Proxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getPost() 0 13 2
A getEmojis() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Esa;
6
7
use Polidog\Esa\Api;
8
use Symfony\Contracts\Cache\CacheInterface;
9
use Symfony\Contracts\Cache\ItemInterface;
10
11
/**
12
 * @see https://docs.esa.io/posts/102
13
 */
14
class Proxy
15
{
16
    public const CACHE_KEY_PREFIX = 'esaba.esa.proxy';
17
18
    public function __construct(private Api $api, private CacheInterface $cache)
19
    {
20
    }
21
22
    public function getPost(int $postId, bool $force = false): array
23
    {
24
        $cacheKey = sprintf('%s.post.%d', self::CACHE_KEY_PREFIX, $postId);
25
26
        if ($force) {
27
            $this->cache->delete($cacheKey);
28
        }
29
30
        $post = $this->cache->get($cacheKey, function (ItemInterface $item) use ($postId) {
0 ignored issues
show
Unused Code introduced by
The parameter $item is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
        $post = $this->cache->get($cacheKey, function (/** @scrutinizer ignore-unused */ ItemInterface $item) use ($postId) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
            return $this->api->post($postId);
32
        });
33
34
        return $post;
35
    }
36
37
    public function getEmojis(): array
38
    {
39
        $cacheKey = sprintf('%s.emojis', self::CACHE_KEY_PREFIX);
40
41
        $emojis = $this->cache->get($cacheKey, function (ItemInterface $item) {
0 ignored issues
show
Unused Code introduced by
The parameter $item is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

41
        $emojis = $this->cache->get($cacheKey, function (/** @scrutinizer ignore-unused */ ItemInterface $item) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
            return $this->api->emojis(['include' => 'all'])['emojis'];
43
        });
44
45
        return $emojis;
46
    }
47
}
48