Passed
Push — master ( 742975...bd07dc )
by Nils
02:05
created

HealthFoundation::setHttpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Leankoala\HealthFoundation;
4
5
use GuzzleHttp\Client;
6
use Leankoala\HealthFoundation\Check\Check;
7
use Leankoala\HealthFoundation\Check\HttpClientAwareCheck;
8
9
class HealthFoundation
10
{
11
    /**
12
     * @var Check[]
13
     */
14
    private $registeredChecks = [];
15
16
    /**
17
     * @var Client
18
     */
19
    private $httpClient;
20
21
    public function setHttpClient(Client $httpClient)
22
    {
23
        $this->httpClient = $httpClient;
24
    }
25
26
    /**
27
     * Return the current httpClient if set otherwise create one.
28
     *
29
     * @return Client
30
     */
31
    private function getHttpClient()
32
    {
33
        if (!$this->httpClient) {
34
            $this->httpClient = new Client();
35
        }
36
37
        return $this->httpClient;
38
    }
39
40
    public function registerCheck(Check $check, $failOnFail = true)
0 ignored issues
show
Unused Code introduced by
The parameter $failOnFail is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

40
    public function registerCheck(Check $check, /** @scrutinizer ignore-unused */ $failOnFail = true)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        if ($check instanceof HttpClientAwareCheck) {
43
            $check->setHttpClient($this->getHttpClient());
44
        }
45
        $this->registeredChecks[] = $check;
46
    }
47
48
    public function runHealthCheck()
49
    {
50
        $runResult = new RunResult();
51
52
        foreach ($this->registeredChecks as $check) {
53
54
            $checkResult = $check->run();
55
            $runResult->addResult($check, $checkResult);
56
        }
57
58
        return $runResult;
59
    }
60
}
61