Completed
Push — 5.0 ( 02915c...8caff9 )
by Ruud
76:11 queued 44:23
created

ElasticSearchUtil   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A useVersion6() 0 17 4
A getESVersionInfo() 0 13 3
1
<?php
2
3
namespace Kunstmaan\NodeSearchBundle\Helper;
4
5
use Elasticsearch\ClientBuilder;
6
use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
7
8
/**
9
 * Class ElasticSearchUtil
10
 */
11
final class ElasticSearchUtil
12
{
13
    /** @var array */
14
    private static $esClientInfo;
15
16
    /**
17
     * @return bool
18
     */
19
    public static function useVersion6()
20
    {
21
        if (PHP_MAJOR_VERSION < 7 || !class_exists('\Elastica\Tool\CrossIndex')) {
22
            return false;
23
        }
24
25
        $info = self::getESVersionInfo();
26
27
        if (null !== $info) {
28
            $versionParts = explode('.', $info['version']['number']);
29
            $majorVersion = $versionParts[0];
30
31
            return ($majorVersion > 2);
32
        }
33
34
        return false;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    private static function getESVersionInfo()
41
    {
42
        try {
43
            if (null === self::$esClientInfo) {
44
                $client = ClientBuilder::create()->build();
45
                self::$esClientInfo = $client->info();
46
            }
47
        } catch (NoNodesAvailableException $e) {
48
            self::$esClientInfo = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $esClientInfo.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
        }
50
51
        return self::$esClientInfo;
52
    }
53
}
54