HidesAttributes::getHidden()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Swis\JsonApi\Client\Concerns;
6
7
trait HidesAttributes
8
{
9
    /**
10
     * The attributes that should be hidden for serialization.
11
     *
12
     * @var array
13
     */
14
    protected $hidden = [];
15
16
    /**
17
     * The attributes that should be visible in serialization.
18
     *
19
     * @var array
20
     */
21
    protected $visible = [];
22
23
    /**
24
     * Get the hidden attributes for the model.
25
     *
26
     * @return array
27
     */
28 188
    public function getHidden()
29
    {
30 188
        return $this->hidden;
31
    }
32
33
    /**
34
     * Set the hidden attributes for the model.
35
     *
36
     *
37
     * @return $this
38
     */
39 4
    public function setHidden(array $hidden)
40
    {
41 4
        $this->hidden = $hidden;
42
43 4
        return $this;
44
    }
45
46
    /**
47
     * Get the visible attributes for the model.
48
     *
49
     * @return array
50
     */
51 188
    public function getVisible()
52
    {
53 188
        return $this->visible;
54
    }
55
56
    /**
57
     * Set the visible attributes for the model.
58
     *
59
     *
60
     * @return $this
61
     */
62 8
    public function setVisible(array $visible)
63
    {
64 8
        $this->visible = $visible;
65
66 8
        return $this;
67
    }
68
69
    /**
70
     * Make the given, typically hidden, attributes visible.
71
     *
72
     * @param  array|string|null  $attributes
73
     * @return $this
74
     */
75 4
    public function makeVisible($attributes)
76
    {
77 4
        $attributes = is_array($attributes) ? $attributes : func_get_args();
78
79 4
        $this->hidden = array_diff($this->hidden, $attributes);
80
81 4
        if (! empty($this->visible)) {
82 4
            $this->visible = array_merge($this->visible, $attributes);
83
        }
84
85 4
        return $this;
86
    }
87
88
    /**
89
     * Make the given, typically visible, attributes hidden.
90
     *
91
     * @param  array|string|null  $attributes
92
     * @return $this
93
     */
94 4
    public function makeHidden($attributes)
95
    {
96 4
        $this->hidden = array_merge(
97 4
            $this->hidden, is_array($attributes) ? $attributes : func_get_args()
98 2
        );
99
100 4
        return $this;
101
    }
102
}
103