Completed
Push — master ( f1a8d5...1a6045 )
by Dmitry
03:22
created

RepresentProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 70
ccs 15
cts 16
cp 0.9375
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A representJson() 0 7 1
A getRESTResourcePath() 0 7 1
A getRepresentation() 0 8 2
A addRepresentation() 0 10 2
1
<?php
2
3
namespace TonicForHealth\PagerDutyClient\RepresentProcessor;
4
5
use TonicForHealth\PagerDutyClient\Entity\PagerDutyEntityInterface;
6
use TonicForHealth\PagerDutyClient\RepresentProcessor\Exception\RepresentProcessorException;
7
use TonicForHealth\PagerDutyClient\RepresentProcessor\Representation\RepresentationInterface;
8
use TonicForHealth\PagerDutyClient\RepresentProcessor\Representation\RepresentationJSONInterface;
9
use TonicForHealth\PagerDutyClient\RepresentProcessor\Representation\RepresentationRESTInterface;
10
11
/**
12
 * Class RepresentProcessor.
13
 */
14
class RepresentProcessor implements RepresentProcessorInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $representation = [];
20
21
    /**
22
     * @param RepresentationInterface $representation
23
     * @param string                  $className
24
     * @param string                  $type
25
     */
26 4
    public function addRepresentation(
27
        RepresentationInterface $representation,
28
        $className = null,
29
        $type = self::REPRESENT_TYPE_JSON
30
    ) {
31 4
        if (null === $className) {
32 4
            $className = $representation::getEntityClassName();
33 4
        }
34 4
        $this->representation[$type][$className] = $representation;
35 4
    }
36
37
    /**
38
     * @param PagerDutyEntityInterface $pagerDutyEntity
39
     *
40
     * @return string
41
     *
42
     * @throws RepresentProcessorException
43
     */
44 4
    public function representJson(PagerDutyEntityInterface $pagerDutyEntity)
45
    {
46
        /** @var RepresentationJSONInterface $representation */
47 4
        $representation = $this->getRepresentation(get_class($pagerDutyEntity), self::REPRESENT_TYPE_JSON);
48
49 4
        return $representation->persistRepresentJSON($pagerDutyEntity);
50
    }
51
52
    /**
53
     * @param PagerDutyEntityInterface $pagerDutyEntity
54
     *
55
     * @return string
56
     *
57
     * @throws RepresentProcessorException
58
     */
59 4
    public function getRESTResourcePath(PagerDutyEntityInterface $pagerDutyEntity)
60
    {
61
        /** @var RepresentationRESTInterface $representation */
62 4
        $representation = $this->getRepresentation(get_class($pagerDutyEntity), self::REPRESENT_TYPE_JSON);
63
64 4
        return $representation->getRESTResourcePath($pagerDutyEntity);
0 ignored issues
show
Documentation introduced by
$pagerDutyEntity is of type object<TonicForHealth\Pa...gerDutyEntityInterface>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
65
    }
66
67
    /**
68
     * @param string $className
69
     * @param string $type
70
     *
71
     * @return RepresentationInterface
72
     *
73
     * @throws RepresentProcessorException
74
     */
75 4
    protected function getRepresentation($className, $type)
76
    {
77 4
        if (!isset($this->representation[$type][$className])) {
78
            throw RepresentProcessorException::representationDoesNotExist($className, $type);
79
        }
80
81 4
        return $this->representation[$type][$className];
82
    }
83
}
84