Completed
Push — master ( f92c24...681df7 )
by Adam
02:52
created

Store   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 67
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A delete() 0 4 2
A insert() 0 5 3
A uid() 0 5 1
1
<?php 
2
3
namespace BestServedCold\LaravelZendSearch\Lucene;
4
5
use BestServedCold\LaravelZendSearch\Lucene\Store\Insert;
6
use BestServedCold\LaravelZendSearch\Lucene\Store\Delete;
7
8
/**
9
 * Class Store
10
 *
11
 * @package BestServedCold\LaravelZendSearch\Lucene
12
 */
13
class Store
14
{
15
    /**
16
     * @var string
17
     */
18
    private $uid;
19
20
    /**
21
     * @var Delete
22
     */
23
    private $delete;
24
25
    /**
26
     * @var Insert
27
     */
28
    private $insert;
29
30
    /**
31
     * Store constructor.
32
     *
33
     * @param Delete $delete
34
     * @param Insert $insert
35
     */
36 3
    public function __construct(Delete $delete, Insert $insert)
37
    {
38 3
        $this->delete = $delete;
39 3
        $this->insert = $insert;
40 3
    }
41
42
    /**
43
     * Delete
44
     *
45
     * @param  integer $id
46
     * @param  bool    $uid
47
     * @return Delete
48
     */
49 2
    public function delete($id, $uid = false)
50
    {
51 2
        return $this->delete->delete($id, $uid ?: $this->uid);
0 ignored issues
show
Bug introduced by
It seems like $uid ?: $this->uid can also be of type string; however, BestServedCold\LaravelZe...\Store\Delete::delete() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
    }
53
54
    /**
55
     * Insert
56
     *
57
     * @param  $id
58
     * @param  array $fields
59
     * @param  bool  $uid
60
     * @return mixed
61
     */
62 1
    public function insert($id, array $fields, $uid = false, $deleteFirst = true)
63
    {
64 1
        $deleteFirst ? $this->delete($id, $uid) : null;
65 1
        return $this->insert->insert($id, $fields, $uid ?: $this->uid);
66
    }
67
68
    /**
69
     * Uid
70
     *
71
     * @param  $uid
72
     * @return $this
73
     */
74 1
    public function uid($uid)
75
    {
76 1
        $this->uid = $uid;
77 1
        return $this;
78
    }
79
}
80