TerminateListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 27
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onKernelTerminate() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\EventListener;
13
14
use ONGR\ElasticsearchBundle\Service\IndexService;
15
use Symfony\Component\DependencyInjection\Container;
16
17
class TerminateListener
18
{
19
    private $container;
20
    private $indexes;
21
22
    /**
23
     * @param Container      $container
24
     * @param IndexService[] $indexes
25
     */
26
    public function __construct(Container $container, array $indexes)
27
    {
28
        $this->container = $container;
29
        $this->indexes = $indexes;
30
    }
31
32
    /**
33
     * Forces commit to the elasticsearch on kernel terminate event
34
     */
35
    public function onKernelTerminate()
36
    {
37
        foreach ($this->indexes as $key => $index) {
38
            /** @var IndexService $index */
39
            $index = $this->container->get($index);
0 ignored issues
show
Documentation introduced by
$index is of type object<ONGR\Elasticsearc...e\Service\IndexService>, 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...
40
            $index->commit();
41
        }
42
    }
43
}
44