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

SingleRequestApi   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 50.77 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 33
loc 65
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4
ccs 0
cts 27
cp 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 11 11 2
A find() 11 11 2
A search() 11 11 2
createCountRequest() 0 1 ?
createFindRequest() 0 1 ?
createSearchRequest() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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