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

DoctrineApi::createCountRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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