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

CachedFinder::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 0
cts 10
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 6
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