Completed
Push — master ( 6b2337...35aa85 )
by Jasper
14s queued 11s
created

HidesAttributes::setHidden()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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