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

DoctrineApi   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4
ccs 0
cts 21
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createCountRequest() 0 7 1
A createFindRequest() 0 7 1
A createSearchRequest() 0 7 1
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Rpc;
4
5
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
6
7
/**
8
 * Example implementation for API-capable communicator
9
 * following Doctrine arguments layout for objects fetching
10
 *
11
 * @internal
12
 */
13
final class DoctrineApi extends SingleRequestApi
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: create, getClient, getMetadata, patch, remove
Loading history...
14
{
15
    const METHOD_FIND   = 'find';
16
    const METHOD_SEARCH = 'search';
17
    const METHOD_COUNT  = 'count';
18
19
    private static $params = [
20
        'criteria',
21
        'sort',
22
        'limit',
23
        'offset',
24
    ];
25
26
    /** {@inheritdoc} */
27
    protected function createCountRequest(ApiMetadata $metadata, array $criteria)
28
    {
29
        return new RpcRequest(
30
            $metadata->getMethodContainer()->getMethod(self::METHOD_COUNT),
31
            ['criteria' => $criteria]
32
        );
33
    }
34
35
    /** {@inheritdoc} */
36
    protected function createFindRequest(ApiMetadata $metadata, array $identifier)
37
    {
38
        return new RpcRequest(
39
            $metadata->getMethodContainer()->getMethod(self::METHOD_FIND),
40
            $identifier
41
        );
42
    }
43
44
    /** {@inheritdoc} */
45
    protected function createSearchRequest(ApiMetadata $metadata, array $parameters)
46
    {
47
        return new RpcRequest(
48
            $metadata->getMethodContainer()->getMethod(self::METHOD_SEARCH),
49
            array_combine(self::$params, $parameters)
50
        );
51
    }
52
}
53