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

SingleRequestApi::search()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 11
loc 11
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
crap 6
1
<?php
2
3
namespace Bankiru\Api\Doctrine\Rpc;
4
5
use Bankiru\Api\Doctrine\Exception\ApiCallException;
6
use Bankiru\Api\Doctrine\Mapping\ApiMetadata;
7
use ScayTrase\Api\Rpc\RpcClientInterface;
8
use ScayTrase\Api\Rpc\RpcRequestInterface;
9
10
/** @internal */
11
abstract class SingleRequestApi implements Counter, Searcher, Finder
12
{
13
    /** {@inheritdoc} */
14 View Code Duplication
    public function count(RpcClientInterface $client, ApiMetadata $metadata, array $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        $request  = $this->createCountRequest($metadata, $parameters);
17
        $response = $client->invoke($request)->getResponse($request);
18
19
        if (!$response->isSuccessful()) {
20
            throw ApiCallException::callFailed($response);
21
        }
22
23
        return (int)$response->getBody();
24
    }
25
26
    /** {@inheritdoc} */
27 View Code Duplication
    public function find(RpcClientInterface $client, ApiMetadata $metadata, array $identifier)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $request  = $this->createFindRequest($metadata, $identifier);
30
        $response = $client->invoke([$request])->getResponse($request);
31
32
        if (!$response->isSuccessful()) {
33
            throw ApiCallException::callFailed($response);
34
        }
35
36
        return $response->getBody();
37
    }
38
39
    /** {@inheritdoc} */
40 View Code Duplication
    public function search(RpcClientInterface $client, ApiMetadata $metadata, array $parameters)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $request  = $this->createSearchRequest($metadata, $parameters);
43
        $response = $client->invoke($request)->getResponse($request);
44
45
        if (!$response->isSuccessful()) {
46
            throw ApiCallException::callFailed($response);
47
        }
48
49
        return new \ArrayIterator($response->getBody());
50
    }
51
52
    /**
53
     * @param ApiMetadata $metadata
54
     * @param array       $criteria
55
     *
56
     * @return RpcRequestInterface
57
     */
58
    abstract protected function createCountRequest(ApiMetadata $metadata, array $criteria);
59
60
    /**
61
     * @param ApiMetadata $metadata
62
     * @param array       $identifier
63
     *
64
     * @return RpcRequestInterface
65
     */
66
    abstract protected function createFindRequest(ApiMetadata $metadata, array $identifier);
67
68
    /**
69
     * @param ApiMetadata $metadata
70
     * @param array       $parameters
71
     *
72
     * @return RpcRequestInterface
73
     */
74
    abstract protected function createSearchRequest(ApiMetadata $metadata, array $parameters);
75
}
76