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 | public function __construct(private ManagerRegistry $doctrine) |
||
24 | { |
||
25 | } |
||
26 | |||
27 | #[\Override] |
||
28 | public function log(AuditLog $event = null) |
||
29 | { |
||
30 | if (empty($event)) { |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | if (DoctrineEvents::ENTITY_DELETED === $event->getTypeId()) { |
||
35 | $this->entityDeleteLogs[] = $event; |
||
36 | |||
37 | return; |
||
38 | } |
||
39 | |||
40 | $this->saveLog($event); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return ObjectManager |
||
45 | */ |
||
46 | protected function getManager() |
||
47 | { |
||
48 | return $this->getDoctrine()->getManager(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return ManagerRegistry |
||
53 | */ |
||
54 | public function getDoctrine() |
||
55 | { |
||
56 | return $this->doctrine; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param AuditLog $event |
||
61 | */ |
||
62 | protected function saveLog(AuditLog $event) |
||
63 | { |
||
64 | $this->getManager()->persist($event); |
||
65 | $this->getManager()->flush($event); |
||
0 ignored issues
–
show
|
|||
66 | } |
||
67 | |||
68 | public function savePendingLogs() |
||
69 | { |
||
70 | foreach ($this->entityDeleteLogs as $log) { |
||
71 | $this->saveLog($log); |
||
72 | } |
||
73 | |||
74 | $this->entityDeleteLogs = []; |
||
75 | } |
||
76 | } |
||
77 |
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.