Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

NodeSearchBundle/Helper/ElasticSearchUtil.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
     * @var array
18
     *
19
     * @return bool
20
     */
21 1
    public static function useVersion6($hosts = array())
22
    {
23 1
        if (PHP_MAJOR_VERSION < 7) {
24
            return false;
25
        }
26
27 1
        $info = self::getESVersionInfo($hosts);
28
29 1
        if (null !== $info) {
30
            $versionParts = explode('.', $info['version']['number']);
31
            $majorVersion = $versionParts[0];
32
33
            return $majorVersion > 2;
34
        }
35
36 1
        return false;
37
    }
38
39
    /**
40
     * @var array
41
     *
42
     * @return array
43
     */
44 1
    private static function getESVersionInfo($hosts)
45
    {
46
        try {
47 1
            if (null === self::$esClientInfo) {
48 1
                $client = ClientBuilder::create()->setHosts($hosts)->build();
49 1
                self::$esClientInfo = $client->info();
50
            }
51 1
        } catch (NoNodesAvailableException $e) {
52 1
            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...
53
        }
54
55 1
        return self::$esClientInfo;
56
    }
57
}
58