ApiActionTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 66
ccs 0
cts 28
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setRestApiClient() 0 4 1
A getRestApiClient() 0 11 2
A setSerializer() 0 4 1
A getSerializer() 0 11 2
1
<?php
2
3
namespace Majora\Framework\Domain\Action\Api;
4
5
use Majora\Framework\Api\Client\RestApiClient;
6
use Symfony\Component\Serializer\SerializerInterface;
7
8
/**
9
 * Base trait for api actions
10
 */
11
trait ApiActionTrait
12
{
13
    /**
14
     * @var RestApiClient
15
     */
16
    private $restClient;
17
18
    /**
19
     * @var SerializerInterface
20
     */
21
    private $serializer;
22
23
    /**
24
     * define rest client.
25
     *
26
     * @param RestApiClient $restClient
27
     */
28
    public function setRestApiClient(RestApiClient $restClient)
29
    {
30
        $this->restClient = $restClient;
31
    }
32
33
    /**
34
     * returns api client if defined
35
     *
36
     * @return RestApiClient
37
     */
38
    protected function getRestApiClient()
39
    {
40
        if (!$this->restClient) {
41
            throw new \BadMethodCallException(sprintf(
42
                'Method %s() cannot be used while rest api client is not configured.',
43
                __METHOD__
44
            ));
45
        }
46
47
        return $this->restClient;
48
    }
49
50
    /**
51
     * define serializer.
52
     *
53
     * @param SerializerInterface $serializer
54
     */
55
    public function setSerializer(SerializerInterface $serializer)
56
    {
57
        $this->serializer = $serializer;
58
    }
59
60
    /**
61
     * returns serializer if defined
62
     *
63
     * @return SerializerInterface
64
     */
65
    protected function getSerializer()
66
    {
67
        if (!$this->serializer) {
68
            throw new \BadMethodCallException(sprintf(
69
                'Method %s() cannot be used while serializer is not configured.',
70
                __METHOD__
71
            ));
72
        }
73
74
        return $this->serializer;
75
    }
76
}
77