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\MultiDomainBundle\Controller; |
||
4 | |||
5 | use Kunstmaan\MultiDomainBundle\Helper\DomainConfiguration; |
||
6 | use Symfony\Component\Routing\Annotation\Route; |
||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
8 | use Symfony\Component\HttpFoundation\RedirectResponse; |
||
9 | use Symfony\Component\HttpFoundation\Request; |
||
10 | use Symfony\Component\HttpFoundation\Response; |
||
11 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
12 | use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
||
13 | |||
14 | class SiteSwitchController extends Controller |
||
15 | { |
||
16 | /** |
||
17 | * @Route("/switch-site", name="KunstmaanMultiDomainBundle_switch_site", methods={"GET"}) |
||
18 | * |
||
19 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
20 | * |
||
21 | * @return Response |
||
22 | * |
||
23 | * @throws AccessDeniedException |
||
24 | * @throws NotFoundHttpException |
||
25 | */ |
||
26 | public function switchAction(Request $request) |
||
27 | { |
||
28 | $domainConfiguration = $this->get('kunstmaan_admin.domain_configuration'); |
||
29 | $host = $request->query->get('host'); |
||
30 | $hosts = $domainConfiguration->getFullHostConfig(); |
||
31 | if (!\array_key_exists($host, $hosts)) { |
||
32 | throw $this->createNotFoundException('Invalid host specified'); |
||
33 | } |
||
34 | |||
35 | $currentHost = $domainConfiguration->getHost(); |
||
36 | |||
37 | $session = $request->getSession(); |
||
38 | if ($request->get('from_url_chooser')) { |
||
39 | $session->set(DomainConfiguration::SWITCH_HOST, $host); |
||
40 | } else { |
||
41 | $session->set(DomainConfiguration::OVERRIDE_HOST, $host); |
||
42 | } |
||
43 | |||
44 | /* |
||
45 | * If current host type is different then the host going to, redirect to it's homepage. |
||
46 | * If coming from url chooser, don't redirect to homepage if other host. |
||
47 | */ |
||
48 | if ((($hosts[$host]['type'] !== $hosts[$currentHost]['type']) || (!$request->query->has('route'))) && (!$request->get('from_url_chooser'))) { |
||
49 | $route = 'KunstmaanAdminBundle_homepage'; |
||
50 | $defaultLocale = $this->get('kunstmaan_admin.domain_configuration')->getDefaultLocale(); |
||
51 | } else { |
||
52 | $route = $request->query->get('route'); |
||
53 | $routeParams = $request->query->get('route_params'); |
||
54 | $defaultLocale = $hosts[$host]['default_locale']; |
||
55 | } |
||
56 | |||
57 | $routeParams['_locale'] = $defaultLocale; |
||
0 ignored issues
–
show
|
|||
58 | |||
59 | $response = new RedirectResponse( |
||
60 | $this->get('router')->generate($route, $routeParams) |
||
61 | ); |
||
62 | |||
63 | return $response; |
||
64 | } |
||
65 | } |
||
66 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: