Completed
Push — master ( 28b967...335197 )
by Sander
31:46 queued 10:53
created

DomainConfiguration::getHost()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Helper;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Symfony\Component\HttpFoundation\RequestStack;
7
8
/**
9
 * Class DomainConfiguration
10
 *
11
 * Default (single domain) configuration handling
12
 *
13
 * @package Kunstmaan\AdminBundle\Helper
14
 */
15
class DomainConfiguration implements DomainConfigurationInterface
16
{
17
    /** @var ContainerInterface */
18
    protected $container;
19
20
    /** @var bool */
21
    protected $multiLanguage;
22
23
    /** @var array */
24
    protected $requiredLocales;
25
26
    /** @var string */
27
    protected $defaultLocale;
28
29
    /**
30
     * @param ContainerInterface|string $multilanguage
31
     */
32
    public function __construct(/*ContainerInterface|string*/ $multilanguage, $defaultLocale = null, $requiredLocales = null)
33
    {
34
        if ($multilanguage instanceof ContainerInterface) {
35
            @trigger_error('Container injection and the usage of the container is deprecated in KunstmaanNodeBundle 5.1 and will be removed in KunstmaanNodeBundle 6.0.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
36
37
            $this->container = $multilanguage;
38
            $this->multiLanguage = $this->container->getParameter(
39
                'multilanguage'
40
            );
41
            $this->defaultLocale = $this->container->getParameter(
42
                'defaultlocale'
43
            );
44
            $this->requiredLocales = explode(
45
                '|',
46
                $this->container->getParameter('requiredlocales')
47
            );
48
49
            return;
50
        }
51
52
        $this->multiLanguage = $multilanguage;
0 ignored issues
show
Documentation Bug introduced by
The property $multiLanguage was declared of type boolean, but $multilanguage is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
53
        $this->defaultLocale = $defaultLocale;
54
55
        $this->requiredLocales = explode('|', $requiredLocales);
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getHost()
62
    {
63
        $request = $this->getMasterRequest();
64
        $host = is_null($request) ? '' : $request->getHost();
65
66
        return $host;
67
    }
68
69
    /**
70
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use string[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
71
     */
72
    public function getHosts()
73
    {
74
        return array($this->getHost());
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getDefaultLocale()
81
    {
82
        return $this->defaultLocale;
83
    }
84
85
    /**
86
     * @param string|null $host
87
     *
88
     * @return bool
89
     */
90
    public function isMultiLanguage($host = null)
91
    {
92
        return $this->multiLanguage;
93
    }
94
95
    /**
96
     * @param string|null $host
97
     *
98
     * @return array
99
     */
100
    public function getFrontendLocales($host = null)
101
    {
102
        return $this->requiredLocales;
103
    }
104
105
    /**
106
     * @param string|null $host
107
     *
108
     * @return array
109
     */
110
    public function getBackendLocales($host = null)
111
    {
112
        return $this->requiredLocales;
113
    }
114
115
    /**
116
     * @return bool
117
     */
118
    public function isMultiDomainHost()
119
    {
120
        return false;
121
    }
122
123
    /**
124
     * @param string|null $host
125
     *
126
     * @return null
127
     */
128
    public function getRootNode($host = null)
129
    {
130
        return null;
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getExtraData()
137
    {
138
        return array();
139
    }
140
141
    /**
142
     * @return array
143
     */
144
    public function getLocalesExtraData()
145
    {
146
        return array();
147
    }
148
149
    /**
150
     * @return null|\Symfony\Component\HttpFoundation\Request
151
     */
152
    protected function getMasterRequest()
153
    {
154
        /** @var RequestStack $requestStack */
155
        $requestStack = $this->container->get('request_stack');
156
157
        return $requestStack->getMasterRequest();
158
    }
159
160
    /**
161
     * @return array
162
     */
163
    public function getFullHostConfig()
164
    {
165
        return array();
166
    }
167
168
    /**
169
     * @param string|null $host
170
     *
171
     * @return null
172
     */
173
    public function getFullHost($host = null)
174
    {
175
        return null;
176
    }
177
178
    /**
179
     * @param int $id
180
     *
181
     * @return null
182
     */
183
    public function getFullHostById($id)
184
    {
185
        return null;
186
    }
187
188
    /**
189
     * @return null
190
     */
191
    public function getHostSwitched()
192
    {
193
        return null;
194
    }
195
196
    /**
197
     * @param string|null $host
198
     *
199
     * @return null
200
     */
201
    public function getHostBaseUrl($host = null)
202
    {
203
        return null;
204
    }
205
206
}
207