Completed
Push — master ( 4bb011...4b99be )
by Guillaume
13:23
created

RenderManager   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 4
dl 0
loc 117
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
B render() 0 20 6
A getSupport() 0 8 4
A addRenderService() 0 6 1
A getRenderService() 0 4 1
A getApi() 0 4 1
A setApi() 0 6 1
A getVersion() 0 4 1
A setVersion() 0 6 1
1
<?php
2
3
namespace Starkerxp\CampaignBundle\Render;
4
5
use Starkerxp\CampaignBundle\Render\Exception\ApiNotDefinedException;
6
use Starkerxp\CampaignBundle\Render\Exception\VersionNotDefinedException;
7
8
class RenderManager extends AbstractRender
9
{
10
    /**
11
     * @var array
12
     */
13
    private $renderService = [];
14
15
    /**
16
     * @var string
17
     */
18
    private $api;
19
20
    /**
21
     * @var string
22
     */
23
    private $version;
24
25
    /**
26
     * @throws ApiNotDefinedException
27
     * @throws VersionNotDefinedException
28
     *
29
     * @return string
30
     */
31
    public function render()
32
    {
33
        if (!isset($this->api)) {
34
            throw new ApiNotDefinedException();
35
        }
36
        if (!isset($this->version)) {
37
            throw new VersionNotDefinedException();
38
        }
39
        $content = $this->getContenu();
40
        $listesApi = array_unique(array_merge([], !is_array($this->api) ? [$this->api] : $this->api));
41
        foreach ($listesApi as $api) {
42
            if ($renderService = $this->getSupport($api, $this->version)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $renderService is correct as $this->getSupport($api, $this->version) (which targets Starkerxp\CampaignBundle...erManager::getSupport()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
43
                $renderService->setData($this->getData());
44
                $renderService->setContenu($content);
45
                $content = $renderService->render();
46
            }
47
        }
48
49
        return $content;
50
    }
51
52
    /**
53
     * @param string $api
54
     * @param string $version
55
     */
56
    public function getSupport($api, $version)
57
    {
58
        foreach ($this->renderService as $service) {
59
            if ($service instanceof RenderInterface && $service->getSupport($api, $version)) {
60
                return $service;
61
            }
62
        }
63
    }
64
65
    /**
66
     * @param RenderInterface $service
67
     *
68
     * @return $this
69
     */
70
    public function addRenderService(RenderInterface $service)
71
    {
72
        $this->renderService[] = $service;
73
74
        return $this;
75
    }
76
77
    /**
78
     * @return array
79
     */
80
    public function getRenderService()
81
    {
82
        return $this->renderService;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getApi()
89
    {
90
        return $this->api;
91
    }
92
93
    /**
94
     * @param string $api
95
     *
96
     * @return RenderManager
97
     */
98
    public function setApi($api)
99
    {
100
        $this->api = strtolower($api);
101
102
        return $this;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getVersion()
109
    {
110
        return $this->version;
111
    }
112
113
    /**
114
     * @param string $version
115
     *
116
     * @return RenderManager
117
     */
118
    public function setVersion($version)
119
    {
120
        $this->version = strtolower($version);
121
122
        return $this;
123
    }
124
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
125