ApiMediator::launch()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
c 3
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Api Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AeSdk\Api\Traits\Mediator;
11
12
use Ticaje\Contract\Patterns\Interfaces\Decorator\DecoratorInterface;
13
14
use Ticaje\AeSdk\Infrastructure\Interfaces\DtoInterface;
15
16
use Ticaje\AeSdk\Api\Interfaces\ApiResponderInterface;
17
18
/**
19
 * Trait ApiMediator
20
 * @package Ticaje\AeSdk\Api\Traits\Mediator
21
 */
22
trait ApiMediator
23
{
24
    /**
25
     * @param DtoInterface $generalRequest
26
     * @param array $serviceRequest
27
     * @param $method
28
     * @return DecoratorInterface
29
     */
30
    protected function launch(DtoInterface $generalRequest, array $serviceRequest, $method)
31
    {
32
        $requester = $this->instantiateRequester($method);
33
        $requester->setData($serviceRequest);
34
        $responder = $this->instantiateResponder($method);
35
        $params = $this->build($requester, $generalRequest);
0 ignored issues
show
Bug introduced by
It seems like build() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        /** @scrutinizer ignore-call */ 
36
        $params = $this->build($requester, $generalRequest);
Loading history...
36
        $response = $this->client->request('GET', "router/rest?{$params}", $generalRequest->getHeaders(), []);
0 ignored issues
show
Bug introduced by
The method getHeaders() does not exist on Ticaje\AeSdk\Infrastruct...Interfaces\DtoInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Ticaje\AeSdk\Infrastruct...est\RequestDtoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        $response = $this->client->request('GET', "router/rest?{$params}", $generalRequest->/** @scrutinizer ignore-call */ getHeaders(), []);
Loading history...
37
        return $responder->process($response);
38
    }
39
40
    /**
41
     * @param $method
42
     * @return mixed
43
     */
44
    private function instantiateRequester($method)
45
    {
46
        $instance = $this->pool->get(static::REQUEST_SERVICE_MAPPER[$method]);
0 ignored issues
show
Bug introduced by
The constant Ticaje\AeSdk\Api\Traits\...:REQUEST_SERVICE_MAPPER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
47
        return $instance;
48
    }
49
50
    /**
51
     * @param $method
52
     * @return ApiResponderInterface
53
     */
54
    private function instantiateResponder($method)
55
    {
56
        /** @var ApiResponderInterface $instance */
57
        $instance = $this->pool->get(static::RESPONSE_SERVICE_MAPPER[$method]);
0 ignored issues
show
Bug introduced by
The constant Ticaje\AeSdk\Api\Traits\...RESPONSE_SERVICE_MAPPER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
        return $instance;
59
    }
60
}
61