Flock::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Flock;
4
5
use GuzzleHttp\Client as HttpClient;
6
use GuzzleHttp\Exception\ClientException;
7
use NotificationChannels\Flock\Exceptions\CouldNotSendNotification;
8
9
class Flock
10
{
11
    /** @var HttpClient HTTP Client */
12
    protected $http;
13
14
    /**
15
     * @param HttpClient|null $httpClient
16
     */
17
    public function __construct(HttpClient $httpClient = null)
18
    {
19
        $this->http = $httpClient;
20
    }
21
22
    /**
23
     * Get HttpClient.
24
     *
25
     * @return HttpClient
26
     */
27
    protected function httpClient()
28
    {
29
        return $this->http ?: $this->http = new HttpClient();
30
    }
31
32
    /**
33
     * @param $url
34
     * @param $params
35
     *
36
     * @return \Psr\Http\Message\ResponseInterface
37
     * @throws CouldNotSendNotification
38
     */
39
    public function sendMessage($url, $params)
40
    {
41
        return $this->sendRequest($url, $params);
42
    }
43
44
    /**
45
     * @param $endpoint
46
     * @param $params
47
     *
48
     * @return \Psr\Http\Message\ResponseInterface
49
     */
50
    protected function sendRequest($endpoint, $params)
51
    {
52
        try {
53
54
            return $this->httpClient()->post($endpoint, [
55
                'json' => $params,
56
            ]);
57
        } catch (ClientException $exception) {
0 ignored issues
show
Bug introduced by
The class GuzzleHttp\Exception\ClientException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
58
            throw CouldNotSendNotification::flockRespondedWithAnError($exception);
59
        }
60
    }
61
}
62