Test Failed
Push — master ( 72bd91...62e8aa )
by Julien
04:22
created

Logger::beforeDispatchLoop()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 4
eloc 14
c 1
b 1
f 1
nc 4
nop 2
dl 0
loc 21
ccs 0
cts 8
cp 0
crap 20
rs 9.7998
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Dispatcher;
13
14
use Phalcon\Events\Event;
15
use Zemit\Dispatcher\AbstractDispatcher;
16
use Zemit\Di\Injectable;
17
18
class Logger extends Injectable
19
{
20
    /**
21
     * Check if the logger is currently enabled or not from the config
22
     */
23
    public function isEnabled(): bool
24
    {
25
        return ($this->config->path('app.logger') || $this->config->path('logger.enable'))
26
            && $this->config->path('logger.dispatcher');
27
    }
28
    
29
    /**
30
     * This action is executed before execute any action in the application
31
     * Keeping a log of the dispatch event
32
     */
33
    public function beforeDispatchLoop(Event $event, AbstractDispatcher $dispatcher): void
1 ignored issue
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

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

33
    public function beforeDispatchLoop(/** @scrutinizer ignore-unused */ Event $event, AbstractDispatcher $dispatcher): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
    {
35
        if ($this->isEnabled()) {
36
            if ($this->config->path('logger.dispatcher')) {
37
                
38
                $session = $this->identity->getSession();
39
                $sessionId = $session ? $session->readAttribute('id') : null;
40
                $userId = $this->identity->getUserId();
41
                $userAsId = $this->identity->getUserAsId();
0 ignored issues
show
Bug introduced by
The method getUserAsId() does not exist on Zemit\Identity. Did you maybe mean getUserAs()? ( Ignorable by Annotation )

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

41
                /** @scrutinizer ignore-call */ 
42
                $userAsId = $this->identity->getUserAsId();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
                
43
                $log = json_encode([
44
                    'type' => 'dispatch',
45
                    'sessionId' => $sessionId,
46
                    'userId' => $userId,
47
                    'userAsId' => $userAsId,
48
                    'meta' => [
49
                        'dispatch' => $dispatcher->toArray(),
50
                    ],
51
                ]);
52
                
53
                $this->logger->info($log);
54
            }
55
        }
56
    }
57
}
58