Completed
Push — master ( a63d9a...31d450 )
by Jonathan
06:27 queued 05:10
created

src/Plugin/SharedLoggerTrait.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Vectorface\Auth\Plugin;
4
5
use Psr\Log\LoggerTrait as PsrLoggerTrait;
6
7
/**
8
 * Plugins wishing to perform their own logging may do so using this trait.
9
 */
10
trait SharedLoggerTrait {
11
    /**
12
     * Use the PSR logger trait, but make the methods protected so they aren't exposed via the Auth object.
13
     */
14
    use PsrLoggerTrait {
15
        emergency as protected;
16
        alert as protected;
17
        critical as protected;
18
        error as protected;
19
        warning as protected;
20
        notice as protected;
21
        info as protected;
22
        debug as protected;
23
        log as protected;
24
    }
25
26
    /**
27
     * Logs with an arbitrary level, or don't if no logger has been set.
28
     *
29
     * @param mixed $level The log level. A LogLevel::* constant (usually)
30
     * @param string $message The message to log.
31
     * @param array $context Further information about the context of the log message.
32
     */
33 2
    protected function log($level, $message, array $context = array()) {
34 2
        if (isset($this->logger)) {
35 1
            $logger = $this->logger;
0 ignored issues
show
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
        } else {
37 2
            $logger = $this->getAuth()->getLogger();
38
        }
39
40 2
        if ($logger) {
41 1
            $logger->log($level, $message, $context);
42
        }
43 2
    }
44
45
    /**
46
     * Get the Auth class instance
47
     *
48
     * @return Auth
49
     */
50
    abstract protected function getAuth();
51
}
52
53