Completed
Push — master ( e8377f...e76f82 )
by Adam
02:57
created

Store::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
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
    public function __construct(Delete $delete, Insert $insert, Index $index)
19
    {
20
        parent::__construct($delete, $insert, $index);
21
    }
22
23
    /**
24
     * @param Model $model
25
     */
26
    public function insertModel(Model $model, $deleteFirst = true)
27
    {
28
        return $this->insert(
29
            $model->id,
30
            $this->filterFields($model),
31
            $this->filterParameters($model),
32
            $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...
33
            $deleteFirst
34
        );
35
    }
36
37
    /**
38
     * @param Model $model
39
     */
40
    public function deleteModel(Model $model)
41
    {
42
        $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...
43
    }
44
45
    /**
46
     * @param Model $model
47
     * @return array
48
     */
49
    private function filterFields($model)
50
    {
51
        return $this->filterKeysFromArray($model->attributesToArray(), $model::getSearchFields());
52
    }
53
54
    /**
55
     * @param Model $model
56
     * @return array
57
     */
58
    private function filterParameters($model)
59
    {
60
        if (!empty($model::getSearchParameters())) {
61
            return $this->filterKeysFromArray($model->attributesToArray(), $model::getSearchParameters());
62
        }
63
64
        return [ ];
65
    }
66
67
    /**
68
     * @param  array $haystack
69
     * @param  array $needle
70
     * @return array
71
     * @todo   refactor this out of here.
72
     */
73
    private function filterKeysFromArray(array $haystack, array $needle)
74
    {
75
        return array_intersect_key($haystack, array_flip($needle));
76
    }
77
}
78