These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | class DomainConfiguration implements DomainConfigurationInterface |
||
14 | { |
||
15 | /** @var ContainerInterface */ |
||
16 | protected $container; |
||
17 | |||
18 | /** @var RequestStack */ |
||
19 | private $requestStack; |
||
20 | |||
21 | /** @var bool */ |
||
22 | protected $multiLanguage; |
||
23 | |||
24 | /** @var array */ |
||
25 | protected $requiredLocales; |
||
26 | |||
27 | /** @var string */ |
||
28 | protected $defaultLocale; |
||
29 | |||
30 | /** |
||
31 | * @param ContainerInterface|string $multilanguage |
||
0 ignored issues
–
show
|
|||
32 | */ |
||
33 | View Code Duplication | public function __construct(/*ContainerInterface|RequestStack*/ $requestStack, $multilanguage = null, $defaultLocale = null, $requiredLocales = null) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
34 | { |
||
35 | if ($requestStack instanceof ContainerInterface) { |
||
36 | @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); |
||
37 | |||
38 | $this->container = $requestStack; |
||
39 | $this->multiLanguage = $this->container->getParameter('kunstmaan_admin.multi_language'); |
||
40 | $this->defaultLocale = $this->container->getParameter('kunstmaan_admin.default_locale'); |
||
41 | $this->requiredLocales = explode('|', $this->container->getParameter('kunstmaan_admin.required_locales')); |
||
42 | $this->requestStack = $this->container->get('request_stack'); |
||
43 | |||
44 | return; |
||
45 | } |
||
46 | |||
47 | $this->requestStack = $requestStack; |
||
48 | $this->multiLanguage = $multilanguage; |
||
0 ignored issues
–
show
It seems like
$multilanguage can also be of type object<Symfony\Component...ion\ContainerInterface> or string . However, the property $multiLanguage is declared as type boolean . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
49 | $this->defaultLocale = $defaultLocale; |
||
50 | |||
51 | $this->requiredLocales = explode('|', $requiredLocales); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | public function getHost() |
||
58 | { |
||
59 | $request = $this->getMasterRequest(); |
||
60 | $host = is_null($request) ? '' : $request->getHost(); |
||
61 | |||
62 | return $host; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return array |
||
67 | */ |
||
68 | public function getHosts() |
||
69 | { |
||
70 | return array($this->getHost()); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getDefaultLocale() |
||
77 | { |
||
78 | return $this->defaultLocale; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param string|null $host |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function isMultiLanguage($host = null) |
||
87 | { |
||
88 | return $this->multiLanguage; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @param string|null $host |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function getFrontendLocales($host = null) |
||
97 | { |
||
98 | return $this->requiredLocales; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @param string|null $host |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getBackendLocales($host = null) |
||
107 | { |
||
108 | return $this->requiredLocales; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function isMultiDomainHost() |
||
115 | { |
||
116 | return false; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param string|null $host |
||
121 | */ |
||
122 | public function getRootNode($host = null) |
||
123 | { |
||
124 | return null; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @return array |
||
129 | */ |
||
130 | public function getExtraData() |
||
131 | { |
||
132 | return array(); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getLocalesExtraData() |
||
139 | { |
||
140 | return array(); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return null|\Symfony\Component\HttpFoundation\Request |
||
145 | */ |
||
146 | protected function getMasterRequest() |
||
147 | { |
||
148 | return $this->requestStack->getMasterRequest(); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return array |
||
153 | */ |
||
154 | public function getFullHostConfig() |
||
155 | { |
||
156 | return array(); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @param string|null $host |
||
161 | */ |
||
162 | public function getFullHost($host = null) |
||
163 | { |
||
164 | return null; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @param int $id |
||
169 | */ |
||
170 | public function getFullHostById($id) |
||
171 | { |
||
172 | return null; |
||
173 | } |
||
174 | |||
175 | public function getHostSwitched() |
||
176 | { |
||
177 | return null; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @param string|null $host |
||
182 | */ |
||
183 | public function getHostBaseUrl($host = null) |
||
184 | { |
||
185 | return null; |
||
186 | } |
||
187 | } |
||
188 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.