Passed
Push — master ( b5f2aa...83de64 )
by Anthony
03:40 queued 10s
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
            $route = $request->get("_route");
40
41
            if (in_array($route, ["_profiler", "_profiler_search_bar", "_wdt", "ribsadmin_userlogs", "ribsadmin_userlogs_show"])) {
42
                return;
43
            }
44
45
            if ($user) {
46
                $user_log = new UserLogs();
47
                $user_log->setMethod($request->getMethod());
48
                $user_log->setUser($user);
49
                $user_log->setUrl($request->get("_route"));
50
                $user_log->setRequestParameters($request->request->all());
51
                $this->em->persist($user_log);
52
                $this->em->flush();
53
            }
54
        }
55
    }
56
}
57