Passed
Branch master (ddcd57)
by Adam
03:09 queued 34s
created

Store   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 55
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A insertModel() 0 11 1
A deleteModel() 0 4 1
A filterFields() 0 4 1
A filterKeysFromArray() 0 4 1
1
<?php
2
3
namespace BestServedCold\LaravelZendSearch\Laravel;
4
5
use BestServedCold\LaravelZendSearch\Lucene\Store as LuceneStore;
6
use Illuminate\Database\Eloquent\Model;
7
use BestServedCold\LaravelZendSearch\Lucene\Store\Delete;
8
use BestServedCold\LaravelZendSearch\Lucene\Store\Insert;
9
10
/**
11
 * Class Store
12
 * @package BestServedCold\LaravelZendSearch\Laravel
13
 */
14
final class Store extends LuceneStore
15
{
16
    use EloquentTrait;
17
18
    private $index;
19
20 9
    public function __construct(Delete $delete, Insert $insert, Index $index)
21
    {
22 9
        parent::__construct($delete, $insert);
23 9
        $this->index = $index;
24 9
    }
25
26
    /**
27
     * @param Model $model
28
     */
29 1
    public function insertModel(Model $model, $deleteFirst = true)
30
    {
31 1
        $this->index->open();
32 1
        $this->model($model);
33 1
        return $this->insert(
34 1
            $model->id,
35 1
            $this->filterFields($model),
36 1
            $this->uid,
0 ignored issues
show
Bug introduced by
The property uid cannot be accessed from this context as it is declared private in class BestServedCold\LaravelZendSearch\Lucene\Store.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation introduced by
$this->uid 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...
37
            $deleteFirst
38 1
        );
39
    }
40
41
    /**
42
     * @param Model $model
43
     */
44 1
    public function deleteModel(Model $model)
45
    {
46 1
        $this->delete($model->id, $this->uid);
0 ignored issues
show
Bug introduced by
The property uid cannot be accessed from this context as it is declared private in class BestServedCold\LaravelZendSearch\Lucene\Store.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Documentation introduced by
$this->uid 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 1
    }
48
49
    /**
50
     * @param Model $model
51
     * @return array
52
     */
53 1
    private function filterFields($model)
54
    {
55 1
        return $this->filterKeysFromArray($model->attributesToArray(), $model::getSearchFields());
56
    }
57
58
    /**
59
     * @param  array $haystack
60
     * @param  array $needle
61
     * @return array
62
     * @todo   refactor this out of here.
63
     */
64 1
    private function filterKeysFromArray(array $haystack, array $needle)
65
    {
66 1
        return array_intersect_key($haystack, array_flip($needle));
67
    }
68
}
69