HidesAttributes   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 122
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getHidden() 0 4 1
A setHidden() 0 6 1
A addHidden() 0 6 2
A getVisible() 0 4 1
A setVisible() 0 6 1
A addVisible() 0 6 2
A makeVisible() 0 10 2
A makeHidden() 0 10 1
1
<?php
2
3
namespace Arrilot\BitrixModels\Models\Traits;
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
     * @return $this
36
     */
37
    public function setHidden(array $hidden)
38
    {
39
        $this->hidden = $hidden;
40
        
41
        return $this;
42
    }
43
    
44
    /**
45
     * Add hidden attributes for the model.
46
     *
47
     * @param  array|string|null  $attributes
48
     * @return void
49
     */
50
    public function addHidden($attributes = null)
51
    {
52
        $this->hidden = array_merge(
53
            $this->hidden, is_array($attributes) ? $attributes : func_get_args()
54
        );
55
    }
56
    
57
    /**
58
     * Get the visible attributes for the model.
59
     *
60
     * @return array
61
     */
62
    public function getVisible()
63
    {
64
        return $this->visible;
65
    }
66
    
67
    /**
68
     * Set the visible attributes for the model.
69
     *
70
     * @param  array  $visible
71
     * @return $this
72
     */
73
    public function setVisible(array $visible)
74
    {
75
        $this->visible = $visible;
76
        
77
        return $this;
78
    }
79
    
80
    /**
81
     * Add visible attributes for the model.
82
     *
83
     * @param  array|string|null  $attributes
84
     * @return void
85
     */
86
    public function addVisible($attributes = null)
87
    {
88
        $this->visible = array_merge(
89
            $this->visible, is_array($attributes) ? $attributes : func_get_args()
90
        );
91
    }
92
    
93
    /**
94
     * Make the given, typically hidden, attributes visible.
95
     *
96
     * @param  array|string  $attributes
97
     * @return $this
98
     */
99
    public function makeVisible($attributes)
100
    {
101
        $this->hidden = array_diff($this->hidden, (array) $attributes);
102
        
103
        if (! empty($this->visible)) {
104
            $this->addVisible($attributes);
105
        }
106
        
107
        return $this;
108
    }
109
    
110
    /**
111
     * Make the given, typically visible, attributes hidden.
112
     *
113
     * @param  array|string  $attributes
114
     * @return $this
115
     */
116
    public function makeHidden($attributes)
117
    {
118
        $attributes = (array) $attributes;
119
        
120
        $this->visible = array_diff($this->visible, $attributes);
121
        
122
        $this->hidden = array_unique(array_merge($this->hidden, $attributes));
123
        
124
        return $this;
125
    }
126
}
127