Passed
Push — master ( 01e76a...f881c5 )
by Leo
01:36
created

MonologHandler::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace leocata\M1\InternalFunctionality;
4
5
use Monolog\Logger;
6
use Monolog\Handler\AbstractProcessingHandler;
7
use leocata\M1\Methods\SendMessage;
8
use leocata\M1\Api;
9
10
/**
11
 * Extends monolog to handle
12
 */
13
class MonologHandler extends AbstractProcessingHandler
14
{
15
    /**
16
     * Holds Api object
17
     * @var Api
18
     */
19
    private $mobApi = null;
20
21
    /**
22
     * Which chat id the message should be sent to
23
     * @var int
24
     */
25
    private $sessionid = 0;
26
27
    /**
28
     * MonologHandler constructor.
29
     *
30
     * @param Api $mobApi
31
     * @param string $sessionid
32
     * @param int $level
33
     * @param bool $bubble
34
     */
35
    public function __construct(Api $mobApi, string $sessionid, $level = Logger::DEBUG, $bubble = true)
36
    {
37
        $this->mobApi = $mobApi;
38
        $this->sessionid = $sessionid;
0 ignored issues
show
Documentation Bug introduced by
The property $sessionid was declared of type integer, but $sessionid is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
39
        parent::__construct($level, $bubble);
40
    }
41
42
    /**
43
     * @param array $record
44
     * @return $this
45
     */
46
    public function write(array $record)
47
    {
48
        $sendMessage = new SendMessage();
49
        $sendMessage->content = $record['formatted'];
50
        $sendMessage->sessionid = $this->sessionid;
51
52
        $this->mobApi->performApiRequest($sendMessage);
53
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type leocata\M1\InternalFunctionality\MonologHandler which is incompatible with the return type mandated by Monolog\Handler\AbstractProcessingHandler::write() of void.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
54
    }
55
}
56