LolHandler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 86.96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 47
ccs 20
cts 23
cp 0.8696
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isHandling() 0 4 1
A __construct() 0 10 3
B handle() 0 21 5
1
<?php
2
3
namespace Monolol\Handlers;
4
5
use Monolog\Handler\AbstractHandler;
6
use Monolog\Handler\HandlerInterface;
7
use Monolol\Lolifier;
8
9
class LolHandler extends AbstractHandler
10
{
11
    private
12
        $lolifier;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $lolifier.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
    
14
    protected
15
        $handler,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $handler.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
16
        $bubble;
17
    
18 5
    public function __construct($handler, Lolifier $lolifier, $bubble = true)
19
    {
20 5
        $this->handler = $handler;
21 5
        $this->lolifier = $lolifier;
22 5
        $this->bubble = $bubble;
23
        
24 5
        if (!$this->handler instanceof HandlerInterface && !is_callable($this->handler)) {
25
            throw new \RuntimeException("The given handler (".json_encode($this->handler).") is not a callable nor a Monolog\Handler\HandlerInterface object");
26
        }
27 5
    }
28
    
29
    public function isHandling(array $record)
30
    {
31
        return $this->lolifier->isHandling($record);
32
    }
33
    
34 5
    public function handle(array $record)
35
    {
36 5
        if (! $this->handler instanceof HandlerInterface) {
37 2
            $this->handler = call_user_func($this->handler, $record, $this);
38 2
            if (! $this->handler instanceof HandlerInterface) {
39 1
                throw new \RuntimeException("The factory callable should return a HandlerInterface");
40
            }
41 1
        }
42
        
43 4
        $record = $this->lolifier->lolify($record);
44
        
45 4
        if ($this->processors) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->processors of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
46 1
            foreach ($this->processors as $processor) {
47 1
                $record = call_user_func($processor, $record);
48 1
            }
49 1
        }
50
        
51 4
        $this->handler->handle($record);
52
        
53 4
        return false === $this->bubble;
54
    }
55
}
56