Passed
Push — master ( fc5558...29abb9 )
by Marcel
12:23
created

ClientSubscriber::addSaasClientAfterSuccessfullRegistration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
/*
4
 * This file is part of the SaasProviderBundle package.
5
 * (c) Fluxter <http://fluxter.net/>
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Fluxter\SaasProviderBundle\EventSubscriber;
11
12
use Doctrine\ORM\EntityManagerInterface;
13
use Fluxter\SaasProviderBundle\Model\SaasClientUserInterface;
14
use Fluxter\SaasProviderBundle\Service\DynamicSaasClientAccessorService;
15
use Fluxter\SaasProviderBundle\Service\SaasClientService;
16
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpFoundation\Session\SessionInterface;
19
use Symfony\Component\HttpKernel\Event\KernelEvent;
20
use Symfony\Component\HttpKernel\KernelEvents;
21
use Twig\Environment as TwigEnvironment;
0 ignored issues
show
Bug introduced by
The type Twig\Environment was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
class ClientSubscriber implements EventSubscriberInterface
24
{
25
    /** @var EntityManagerInterface */
26
    private $em;
27
28
    /** @var SessionInterface */
29
    private $session;
30
31
    /** @var SaasClientService */
32
    private $clientService;
33
34
    /** @var TwigEnvironment */
35
    private $twig;
36
37
    /** @var DynamicSaasClientAccessorService */
38
    private $dynamicSaasClientAccessorService;
39
40
    public function __construct(
41
        EntityManagerInterface $em, 
42
        SessionInterface $session, 
43
        SaasClientService $clientService, 
44
        TwigEnvironment $twig,
45
        DynamicSaasClientAccessorService $dynamicSaasClientAccessorService)
46
    {
47
        $this->em = $em;
48
        $this->session = $session;
49
        $this->clientService = $clientService;
50
        $this->twig = $twig;
51
        $this->dynamicSaasClientAccessorService = $dynamicSaasClientAccessorService;
52
    }
53
54
    public static function getSubscribedEvents()
55
    {
56
        $events = [
57
            KernelEvents::REQUEST => ['checkSaasClient', 101],
58
        ];
59
60
        return $events;
61
    }
62
    
63
    /**
64
     * Discovers and checks if the current saas client exists by the current domain
65
     * and sets the session variables and updates them if needed.
66
     *
67
     * @return void
68
     */
69
    public function checkSaasClient(KernelEvent $event)
70
    {
71
        $client = $this->clientService->tryGetCurrentClient();
72
        if (null == $client) {
73
            $event->setResponse(new Response('Not found!', 404));
0 ignored issues
show
Bug introduced by
The method setResponse() does not exist on Symfony\Component\HttpKernel\Event\KernelEvent. It seems like you code against a sub-type of Symfony\Component\HttpKernel\Event\KernelEvent such as Symfony\Component\HttpKe...ent\FilterResponseEvent or Symfony\Component\HttpKe...\Event\GetResponseEvent. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
            $event->/** @scrutinizer ignore-call */ 
74
                    setResponse(new Response('Not found!', 404));
Loading history...
74
75
            return;
76
        }
77
78
        $this->twig->addGlobal('saas_client_object', $client);
79
        $this->twig->addGlobal('saas_client', $this->dynamicSaasClientAccessorService);
80
    }
81
}
82