Completed
Push — master ( d72a06...ba0ad0 )
by GBProd
04:38
created

PutIndexSettingsHandler::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 18
ccs 10
cts 11
cp 0.9091
rs 9.4285
cc 3
eloc 10
nc 2
nop 2
crap 3.0067
1
<?php
2
3
namespace GBProd\ElasticsearchExtraBundle\Handler;
4
5
use Elasticsearch\Client;
6
use GBProd\ElasticsearchExtraBundle\Repository\ClientRepository;
7
use GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository;
8
9
/**
10
 * Handler to put index settings command
11
 *
12
 * @author gbprod <[email protected]>
13
 */
14
class PutIndexSettingsHandler
15
{
16
    /**
17
     * @var IndexConfigurationRepository
18
     */
19
    private $configurationRepository;
20
21
    /**
22
     * @param IndexConfigurationRepository $configurationRepository
23
     */
24
    public function __construct(IndexConfigurationRepository $configurationRepository)
25
    {
26 1
        $this->configurationRepository = $configurationRepository;
27 1
    }
28
29
    /**
30
     * Handle index creation command
31
     *
32
     * @param Client $client
33
     * @param string $index
34
     */
35
    public function handle($client, $index)
36
    {
37 1
        $config = $this->configurationRepository->get($client, $index);
0 ignored issues
show
Documentation introduced by
$client is of type object<Elasticsearch\Client>, but the function expects a string.

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...
Unused Code introduced by
The call to IndexConfigurationRepository::get() has too many arguments starting with $index.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
38
39 1
        if (null === $client || null === $config) {
40
            throw new \InvalidArgumentException();
41
        }
42
43 1
        $client
44 1
            ->indices()
45 1
            ->putSettings([
46 1
                'index' => $index,
47
                'body'  => [
48 1
                    'settings' => $this->extractSettings($config),
49 1
                ],
50 1
            ])
51
        ;
52 1
    }
53
54
    private function extractSettings($config)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
55
    {
56 1
        if (isset($config['settings'])) {
57 1
            return $config['settings'];
58
        }
59
60
        return [];
61
    }
62
}
63