AcquiaSearchClient::factory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Acquia\Search;
4
5
use Acquia\Rest\ServiceManagerAware;
6
use Guzzle\Common\Collection;
7
use PSolr\Client\SolrClient;
8
9
class AcquiaSearchClient extends SolrClient implements ServiceManagerAware
10
{
11
    /**
12
     * {@inheritdoc}
13
     *
14
     * Sets the HMAC authentication plugin, sets the base_path to point to the
15
     * correct index.
16
     */
17 27
    public static function factory($config = array())
18
    {
19
        // We just use this for validation. The configs are set in the parent's
20
        // factory methid.
21 27
        Collection::fromConfig($config, array(), array('index_id', 'derived_key'));
22 21
        $solr = parent::factory($config);
23
24
        // Get the configs relevant to Acquia Search.
25 21
        $indexId = $solr->getConfig('index_id');
0 ignored issues
show
Documentation introduced by
'index_id' is of type string, but the function expects a boolean.

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...
26 21
        $derivedKey = $solr->getConfig('derived_key');
0 ignored issues
show
Documentation introduced by
'derived_key' is of type string, but the function expects a boolean.

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...
27
28
        // Set the base bath to point to the configured index.
29 21
        $solr->getConfig()->set('base_path', '/solr/' . $indexId);
30
31
        // Attach the Acquia Search HMAC Authentication plugin to the client.
32 21
        $signature = new Signature($derivedKey);
33 21
        $plugin = new AcquiaSearchAuthPlugin($indexId, $signature);
34 21
        $solr->addSubscriber($plugin);
35
36 21
        return $solr;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 3
    public function getBuilderParams()
43
    {
44
        return array(
45 3
            'base_url' => $this->getConfig('base_url'),
0 ignored issues
show
Documentation introduced by
'base_url' is of type string, but the function expects a boolean.

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...
46 3
            'index_id' => $this->getConfig('index_id'),
0 ignored issues
show
Documentation introduced by
'index_id' is of type string, but the function expects a boolean.

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...
47 3
            'derived_key' => $this->getConfig('derived_key'),
0 ignored issues
show
Documentation introduced by
'derived_key' is of type string, but the function expects a boolean.

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...
48 3
        );
49
    }
50
}
51