BoxcarHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 34
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A write() 0 6 2
1
<?php
2
3
namespace Zortje\MonologBoxcarHandler;
4
5
use Monolog\Logger;
6
use Monolog\Handler\AbstractProcessingHandler;
7
use Zortje\BoxcarNotifications\Boxcar;
8
use Zortje\BoxcarNotifications\Notification;
9
10
/**
11
 * Class BoxcarHandler
12
 *
13
 * @package Zortje\MonologBoxcarHandler
14
 */
15
class BoxcarHandler extends AbstractProcessingHandler
16
{
17
18
    /**
19
     * @var Boxcar
20
     */
21
    private $boxcar;
22
23
    /**
24
     * Send push notifications to Boxcar for iOS
25
     *
26
     * @param Boxcar   $boxcar A initialized Boxcar object
27
     * @param bool|int $level  The minimum logging level at which this handler will be triggered
28
     * @param bool     $bubble Whether the messages that are handled can bubble up the stack or not
29
     */
30
    public function __construct(Boxcar $boxcar, $level = Logger::DEBUG, $bubble = true)
31
    {
32
        $this->boxcar = $boxcar;
33
34
        parent::__construct($level, $bubble);
0 ignored issues
show
Bug introduced by
It seems like $level defined by parameter $level on line 30 can also be of type boolean; however, Monolog\Handler\AbstractHandler::__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...
35
    }
36
37
    /**
38
     * If title is provided we use that for the notification title, otherwise the record level name
39
     *
40
     * @inheritdoc
41
     */
42
    protected function write(array $record)
43
    {
44
        $title = !empty($record['context']['title']) ? $record['context']['title'] : $record['level_name'];
45
46
        $this->boxcar->push(new Notification($title, $record['message']));
47
    }
48
}
49