Completed
Push — develop ( b76c1f...3a993b )
by
unknown
10s
created

Manager::factory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
namespace Solr\Bridge;
11
12
use Solr\Options\ModuleOptions;
13
use Zend\ServiceManager\ServiceLocatorInterface;
14
use SolrClient;
15
16
/**
17
 * Manage connection with the SolrServer
18
 *
19
 * @author Anthonius Munthi <[email protected]>
20
 * @author Miroslav Fedeleš <[email protected]>
21
 * @since   0.26
22
 * @package Solr\Bridge
23
 */
24
class Manager
25
{
26
    const SOLR_DATE_FORMAT  = 'Y-m-d\TH:i:s\Z';
27
28
    /**
29
     * @var ModuleOptions
30
     */
31
    protected $options;
32
    
33
    /**
34
     * @var array
35
     */
36
    protected $clients = [];
37
38
    /**
39
     * Manager constructor.
40
     * @param ModuleOptions $options
41
     */
42
    public function __construct(ModuleOptions $options)
43
    {
44
        $this->options = $options;
45
    }
46
47
    /**
48
     * Get SolrClient with custom path option
49
     *
50
     * @param string $path
51
     * @return SolrClient
52
     */
53
    public function getClient($path = '/solr')
54
    {
55
        $options = $this->options;
56
        $options = [
57
            'secure' => $options->isSecure(),
58
            'hostname' => $options->getHostname(),
59
            'port' => $options->getPort(),
60
            'path' => $path,
61
            'login' => $options->getUsername(),
62
            'password' => $options->getPassword(),
63
            'wt' => 'phps'
64
        ];
65
        $key = md5(implode(':', $options));
66
        
67
        if (!isset($this->clients[$key])) {
68
            $this->clients[$key] = new SolrClient($options);
69
        }
70
71
        return $this->clients[$key];
72
    }
73
74
    /**
75
     * @return ModuleOptions
76
     */
77
    public function getOptions()
78
    {
79
        return $this->options;
80
    }
81
82
    /**
83
     * Create new instance for Solr\Manager
84
     * @param ServiceLocatorInterface $sl
85
     * @return Manager
86
     */
87
    static public function factory(ServiceLocatorInterface $sl)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
88
    {
89
        return new static($sl->get('Solr/Options/Module'));
0 ignored issues
show
Documentation introduced by
$sl->get('Solr/Options/Module') is of type object|array, but the function expects a object<Solr\Options\ModuleOptions>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
    }
91
}