Passed
Push — master ( 865369...be2445 )
by Anthony
08:20
created

UserLog::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Service;
4
5
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface 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...
6
use PiouPiou\RibsAdminBundle\Entity\UserLogs;
7
use Symfony\Component\HttpKernel\Event\RequestEvent;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKernel\Event\RequestEvent 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...
8
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
9
10
class UserLog
11
{
12
    /**
13
     * @var TokenStorageInterface
14
     */
15
    private $token_storage;
16
17
    /**
18
     * @var EntityManagerInterface a
19
     */
20
    private $em;
21
22
    public function __construct(TokenStorageInterface $token_storage, EntityManagerInterface $em)
23
    {
24
        $this->token_storage = $token_storage;
25
        $this->em = $em;
26
    }
27
28
    /**
29
     * @param RequestEvent $request_event
30
     */
31
    public function onKernelRequest(RequestEvent $request_event)
32
    {
33
        if ($request_event->isMasterRequest()) {
34
            $user = null;
35
            if ($this->token_storage->getToken() && is_object($this->token_storage->getToken()->getUser()) && $this->token_storage->getToken()->getUser()->getUser()) {
36
                $user = $this->token_storage->getToken()->getUser()->getUser();
37
            }
38
            $request = $request_event->getRequest();
39
40
            if ($user) {
41
                $user_log = new UserLogs();
42
                $user_log->setMethod($request->getMethod());
43
                $user_log->setUser($user);
44
                $user_log->setUrl($request->get("_route"));
45
                $user_log->setRequestParameters($request->request->all());
46
                $this->em->persist($user_log);
47
                $this->em->flush();
48
            }
49
        }
50
    }
51
}
52