GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Slack::debug()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php namespace RuleCom\Notifier\Channels;
2
3
use GuzzleHttp\Client;
4
use Monolog\Handler\StreamHandler;
5
use Monolog\Logger;
6
7
class Slack implements Channel
8
{
9
    /**
10
     * @var Client
11
     */
12
    private $client;
13
14
    /**
15
     * @var string
16
     */
17
    private $endpoint;
18
19
    /**
20
     * @var string
21
     */
22
    private $channel;
23
24
    /**
25
     * @var string
26
     */
27
    private $message;
28
29
    /**
30
     * @var Logger
31
     */
32
    private $logger;
33
34
    /**
35
     * @var string
36
     */
37
    private $logPath;
38
39
    /**
40
     * @var bool
41
     */
42
    private $debug = false;
43
44
    public function __construct(Client $client, Logger $logger = null)
45
    {
46
        $this->client = $client;
47
        $this->logger = $logger;
48
    }
49
50
    public function debug($logPath)
51
    {
52
        $this->debug = true;
53
        $this->logPath = $logPath;
54
        return $this;
55
    }
56
57
    /**
58
     * @param string $endpoint
59
     * @return $this
60
     */
61
    public function endpoint($endpoint)
62
    {
63
        $this->endpoint = $endpoint;
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $channel
69
     * @return $this
70
     */
71
    public function channel($channel)
72
    {
73
        $this->channel = $channel;
74
        return $this;
75
    }
76
77
    /**
78
     * @param string $message
79
     * @return $this
80
     */
81
    public function message($message)
82
    {
83
        $this->message = $message;
84
        return $this;
85
    }
86
87
    /**
88
     * Dispatch notification message
89
     */
90
    public function dispatch()
91
    {
92
        if ($this->debug) {
93
            return $this->fakeDispatch();
94
        }
95
96
        $this->client->post($this->endpoint, [
97
            'json' => [
98
                'channel' => $this->channel,
99
                'text' => $this->message
100
            ]
101
        ]);
102
    }
103
104
    /**
105
     * Fakes dispatch by logging instead
106
     */
107
    private function fakeDispatch()
108
    {
109
        $this->logger->pushHandler(new StreamHandler($this->logPath));
110
        $this->logger->addInfo('Slack:', ['endpoint' => $this->endpoint, 'message' => $this->message]);
111
    }
112
}
113