Completed
Push — master ( 38f1ea...fd6c7c )
by Matze
04:05
created

ChannelStreamHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 8
Bugs 0 Features 5
Metric Value
wmc 7
c 8
b 0
f 5
lcom 1
cbo 2
dl 0
loc 70
ccs 24
cts 24
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setChannel() 0 4 1
A __construct() 0 21 1
B isHandling() 0 22 5
1
<?php
2
3
namespace BrainExe\Core\Logger;
4
5
use Monolog\Handler\StreamHandler;
6
use Monolog\Logger;
7
8
class ChannelStreamHandler extends StreamHandler
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private $channel;
15
16
    /**
17
     * @param string $stream
18
     * @param bool|int $level
19
     * @param string|null $channel
20
     * @param bool $bubble
21
     */
22 10
    public function __construct(
23
        $stream,
24
        $level = Logger::DEBUG,
25
        $channel = null,
26
        $bubble = true
27
    ) {
28 10
        parent::__construct($stream, $level, $bubble);
0 ignored issues
show
Bug introduced by
It seems like $level defined by parameter $level on line 24 can also be of type boolean; however, Monolog\Handler\StreamHandler::__construct() does only seem to accept integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
29
30 10
        $formatter = new Formatter(
31 10
            null,
32 10
            null,
33 10
            false,
34 10
            true
35
        );
36
37 10
        $this->setFormatter(
38
            $formatter
39
        );
40
41 10
        $this->channel = $channel;
42 10
    }
43
44
    /**
45
     * @param string $channel
46
     */
47 7
    public function setChannel(string $channel)
48
    {
49 7
        $this->channel = $channel;
50 7
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 9
    public function isHandling(array $record) : bool
56
    {
57 9
        if (count($record) == 1) {
58 3
            return parent::isHandling($record);
59
        }
60
61 8
        if (!parent::isHandling($record)) {
62 1
            return false;
63
        }
64
65 7
        if (empty($this->channel)) {
66 2
            return empty($record['context']['channel']);
67
        }
68
69 5
        if (empty($record['context']['channel'])) {
70 1
            return false;
71
        }
72
73 4
        $supported = $this->channel === $record['context']['channel'];
74
75 4
        return $supported;
76
    }
77
}
78