Test Failed
Pull Request — master (#13)
by Rail
02:08
created

RelationStore::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Imanghafoori\Relativity;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Database\Eloquent\Model;
7
8
class RelationStore
9
{
10
    /**
11
     * List of all relations
12
     *
13
     * @var array
14
     */
15
    public $relations = [];
16
17
    /**
18
     * Retrieve all relations.
19
     *
20
     * @param Model $model
21
     *
22
     * @return array
23
     */
24 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...
25
    {
26 1
        return $this->relations;
27
    }
28
29
    /**
30
     * Retrieve a relation.
31
     *
32
     * @param Model $model
33
     * @param string $key
34
     * @param mixed $default
35
     *
36
     * @return mixed
37
     */
38 7
    public function get(Model $model, $key, $default = null)
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 7
        return $this->relations[$key] ?? $default;
41
    }
42
43
    /**
44
     * Set a relation.
45
     *
46
     * @param Model $model
47
     * @param string $key
48
     * @param mixed $value
49
     */
50 8
    public function set(Model $model, $key, $value)
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...
51
    {
52 8
        $this->relations[$key] = $value;
53 8
    }
54
55
    /**
56
     * Retrieve a relation.
57
     *
58
     * @param Model $model
59
     * @param string $key
60
     * @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...
61
     *
62
     * @return mixed
63
     */
64 7
    public function has(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...
65
    {
66 7
        return isset($this->relations[$key]);
67
    }
68
69
    /**
70
     * Remove a relation.
71
     *
72
     * @param Model $model
73
     * @param string $key
74
     */
75 1
    public function unset(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...
76
    {
77 1
        unset($this->relations[$key]);
78 1
    }
79
}
80