Completed
Pull Request — master (#14)
by Pavel
04:24
created

CachedFinder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 45
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2
ccs 0
cts 23
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A find() 0 12 2
A getClient() 0 4 1
A getMetadata() 0 4 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Rpc;
4
5
use Bankiru\Api\Doctrine\EntityDataCacheInterface;
6
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
7
use ScayTrase\Api\Rpc\RpcClientInterface;
8
9
final class CachedFinder implements Finder
10
{
11
    /** @var  Finder */
12
    private $delegate;
13
    /** @var  EntityDataCacheInterface */
14
    private $cache;
15
16
    /**
17
     * CachedFinder constructor.
18
     *
19
     * @param Finder                   $delegate
20
     * @param EntityDataCacheInterface $cache
21
     */
22
    public function __construct(Finder $delegate, EntityDataCacheInterface $cache)
23
    {
24
        $this->delegate = $delegate;
25
        $this->cache    = $cache;
26
    }
27
28
    /** {@inheritdoc} */
29
    public function find(array $identifier)
30
    {
31
        $body = $this->cache->get($identifier);
32
        if (null !== $body) {
33
            return $body;
34
        }
35
36
        $body = $this->delegate->find($identifier);
37
        $this->cache->set($body, $identifier);
0 ignored issues
show
Documentation introduced by
$body is of type object<stdClass>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
39
        return $body;
40
    }
41
42
    /** {@inheritdoc} */
43
    public function getClient()
44
    {
45
        return $this->delegate->getClient();
46
    }
47
48
    /** {@inheritdoc} */
49
    public function getMetadata()
50
    {
51
        return $this->delegate->getMetadata();
52
    }
53
}
54