Completed
Pull Request — 3.6 (#1940)
by Sander
24:32 queued 12:51
created

ElasticSearchUtil::getESVersionInfo()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 13
rs 9.4285
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
        $info = self::getESVersionInfo();
22
23
        if (null !== $info) {
24
            $versionParts = explode('.', $info['version']['number']);
25
            $majorVersion = $versionParts[0];
26
27
            return ($majorVersion > 2 && PHP_MAJOR_VERSION === 7 && !class_exists('\Elastica\Tool\CrossIndex'));
28
        }
29
30
        return false;
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    private static function getESVersionInfo()
37
    {
38
        try {
39
            if (null === self::$esClientInfo) {
40
                $client = ClientBuilder::create()->build();
41
                self::$esClientInfo = $client->info();
42
            }
43
        } catch (NoNodesAvailableException $e) {
44
            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...
45
        }
46
47
        return self::$esClientInfo;
48
    }
49
}
50