bankiru /
doctrine-api-client
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Bankiru\Api\Doctrine\Rpc; |
||
| 4 | |||
| 5 | use Bankiru\Api\Doctrine\Exception\ApiCallException; |
||
| 6 | use ScayTrase\Api\Rpc\RpcRequestInterface; |
||
| 7 | |||
| 8 | /** @internal */ |
||
| 9 | abstract class SingleRequestApi implements CrudsApiInterface |
||
| 10 | { |
||
| 11 | /** {@inheritdoc} */ |
||
| 12 | View Code Duplication | public function count(array $criteria = []) |
|
|
0 ignored issues
–
show
|
|||
| 13 | { |
||
| 14 | $request = $this->createCountRequest($criteria); |
||
| 15 | $response = $this->getClient()->invoke($request)->getResponse($request); |
||
| 16 | |||
| 17 | if (!$response->isSuccessful()) { |
||
| 18 | throw ApiCallException::callFailed($response); |
||
| 19 | } |
||
| 20 | |||
| 21 | return (int)$response->getBody(); |
||
| 22 | } |
||
| 23 | |||
| 24 | /** {@inheritdoc} */ |
||
| 25 | View Code Duplication | public function find(array $identifier) |
|
|
0 ignored issues
–
show
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...
|
|||
| 26 | { |
||
| 27 | $request = $this->createFindRequest($identifier); |
||
| 28 | $response = $this->getClient()->invoke([$request])->getResponse($request); |
||
| 29 | |||
| 30 | if (!$response->isSuccessful()) { |
||
| 31 | throw ApiCallException::callFailed($response); |
||
| 32 | } |
||
| 33 | |||
| 34 | return $response->getBody(); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** {@inheritdoc} */ |
||
| 38 | public function search(array $criteria = [], array $orderBy = null, $limit = null, $offset = null) |
||
| 39 | { |
||
| 40 | $request = $this->createSearchRequest($criteria, $orderBy, $limit, $offset); |
||
| 41 | $response = $this->getClient()->invoke($request)->getResponse($request); |
||
| 42 | |||
| 43 | if (!$response->isSuccessful()) { |
||
| 44 | throw ApiCallException::callFailed($response); |
||
| 45 | } |
||
| 46 | |||
| 47 | return new \ArrayIterator($response->getBody()); |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param array $criteria |
||
| 52 | * |
||
| 53 | * @return RpcRequestInterface |
||
| 54 | */ |
||
| 55 | abstract protected function createCountRequest(array $criteria = []); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $identifier |
||
| 59 | * |
||
| 60 | * @return RpcRequestInterface |
||
| 61 | */ |
||
| 62 | abstract protected function createFindRequest(array $identifier); |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param array $criteria |
||
| 66 | * @param array|null $orderBy |
||
| 67 | * @param int|null $limit |
||
| 68 | * @param int|null $offset |
||
| 69 | * |
||
| 70 | * @return RpcRequestInterface |
||
| 71 | */ |
||
| 72 | abstract protected function createSearchRequest( |
||
| 73 | array $criteria = [], |
||
| 74 | array $orderBy = null, |
||
| 75 | $limit = null, |
||
| 76 | $offset = null |
||
| 77 | ); |
||
| 78 | } |
||
| 79 |
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.