Test Failed
Pull Request — master (#13)
by Rail
04:55
created

RelationStore::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Imanghafoori\Relativity;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Arr;
8
9
class RelationStore
10
{
11
    /**
12
     * List of all relations
13
     *
14
     * @var array
15
     */
16
    public $relations = [];
17
18
    /**
19
     * Retrieve all relations.
20
     *
21
     * @param Model $model
22
     *
23
     * @return array
24
     */
25 1
    public function all(Model $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27 1
        return $this->relations;
28
    }
29
30
    /**
31
     * Retrieve key
32
     *
33
     * @param Model $model
34
     * @param string $key
35
     *
36
     * @return string
37
     */
38 9
    public function getKey(Model $model, $key)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40 9
    	return $key;
41
    }
42
43
    /**
44
     * Retrieve a relation.
45
     *
46
     * @param Model $model
47
     * @param string $key
48
     * @param mixed $default
49
     *
50
     * @return mixed
51
     */
52 7
    public function get(Model $model, $key, $default = null)
53
    {
54 7
        return Arr::get($this->relations, $this->getKey($model, $key), $default);
55
    }
56
57
    /**
58
     * Set a relation.
59
     *
60
     * @param Model $model
61
     * @param string $key
62
     * @param mixed $value
63
     */
64 8
    public function set(Model $model, $key, $value)
65
    {
66 8
        Arr::set($this->relations, $this->getKey($model, $key), $value);
67 8
    }
68
69
    /**
70
     * Retrieve a relation.
71
     *
72
     * @param Model $model
73
     * @param string $key
74
     * @param mixed $default
0 ignored issues
show
Bug introduced by
There is no parameter named $default. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
75
     *
76
     * @return mixed
77
     */
78 7
    public function has(Model $model, $key)
79
    {
80 7
        return Arr::has($this->relations, $this->getKey($model, $key));
81
    }
82
83
    /**
84
     * Remove a relation.
85
     *
86
     * @param Model $model
87
     * @param string $key
88
     */
89 1
    public function unset(Model $model, $key)
90
    {
91 1
        Arr::forget($this->relations, $this->getKey($model, $key));
92 1
    }
93
}
94