Logger   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 17
dl 0
loc 61
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A saveLog() 0 4 1
A getManager() 0 3 1
A __construct() 0 3 1
A log() 0 13 3
A savePendingLogs() 0 7 2
A getDoctrine() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the XiideaEasyAuditBundle package.
5
 *
6
 * (c) Xiidea <http://www.xiidea.net>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Xiidea\EasyAuditBundle\Logger;
13
14
use Doctrine\Persistence\ManagerRegistry;
15
use Doctrine\Persistence\ObjectManager;
16
use Xiidea\EasyAuditBundle\Model\BaseAuditLog as AuditLog;
17
use Xiidea\EasyAuditBundle\Events\DoctrineEvents;
18
19
class Logger implements LoggerInterface
20
{
21
    private $entityDeleteLogs = [];
22
23
    /**
24
     * @var \Doctrine\Persistence\ManagerRegistry
25
     */
26
    private $doctrine;
27
28
    public function __construct(ManagerRegistry $doctrine)
29
    {
30
        $this->doctrine = $doctrine;
31
    }
32
33
    public function log(AuditLog $event = null)
34
    {
35
        if (empty($event)) {
36
            return;
37
        }
38
39
        if (DoctrineEvents::ENTITY_DELETED === $event->getTypeId()) {
40
            $this->entityDeleteLogs[] = $event;
41
42
            return;
43
        }
44
45
        $this->saveLog($event);
46
    }
47
48
    /**
49
     * @return ObjectManager
50
     */
51
    protected function getManager()
52
    {
53
        return $this->getDoctrine()->getManager();
54
    }
55
56
    /**
57
     * @return ManagerRegistry
58
     */
59
    public function getDoctrine()
60
    {
61
        return $this->doctrine;
62
    }
63
64
    /**
65
     * @param AuditLog $event
66
     */
67
    protected function saveLog(AuditLog $event)
68
    {
69
        $this->getManager()->persist($event);
70
        $this->getManager()->flush($event);
0 ignored issues
show
Unused Code introduced by
The call to Doctrine\Persistence\ObjectManager::flush() has too many arguments starting with $event. ( Ignorable by Annotation )

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

70
        $this->getManager()->/** @scrutinizer ignore-call */ flush($event);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
71
    }
72
73
    public function savePendingLogs()
74
    {
75
        foreach ($this->entityDeleteLogs as $log) {
76
            $this->saveLog($log);
77
        }
78
79
        $this->entityDeleteLogs = [];
80
    }
81
}
82