Passed
Push — master ( 6679c1...b58406 )
by Svilen
02:46
created

Solr   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 20 3
1
<?php
2
namespace Health\Checks\Servers;
3
4
use Health\Checks\BaseCheck;
5
use Health\Checks\HealthCheckInterface;
6
use Solarium\Client;
7
use Solarium\Exception\ExceptionInterface;
8
9
class Solr extends BaseCheck implements HealthCheckInterface
10
{
11
12
    /**
13
     *
14
     * {@inheritdoc}
15
     * @see \Health\Checks\HealthCheckInterface::call()
16
     */
17
    public function call()
18
    {
19
        $builder = $this->getBuilder();
20
21
        $options = $this->getParam('options', null);
22
23
        try {
24
            $client = new Client($options);
25
        } catch (\Exception $e) {
26
            $builder->down()->withData("error", "Solr Client Error - " . $e->getMessage());
27
        }
28
29
        try {
30
            $ping = $client->createPing();
31
            $client->ping($ping);
32
        } catch (ExceptionInterface $e) {
33
            $builder->down()->withData("error", "Could not open connection to server - " . $e->getMessage());
34
        }
35
36
        return $builder->build();
37
    }
38
}
39