Completed
Push — master ( dcbe42...49c9b4 )
by Joe
03:56
created

HasHiddenAttributes   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 22
c 1
b 0
f 0
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHiddenAttributes() 0 7 2
A bootHiddenAttributes() 0 5 1
A isHidden() 0 3 1
A mergeHiddenAttributes() 0 11 2
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Concerns;
4
5
use function PhpWinTools\WmiScripting\Support\get_ancestor_property;
6
7
trait HasHiddenAttributes
8
{
9
    protected $hidden_booted = false;
10
11
    protected $trait_hidden_attributes = [
12
        'trait_hidden_attributes',
13
        'trait_name_replacements',
14
15
        'attribute_name_replacements',
16
        'unmapped_attributes',
17
18
        'hidden_attributes',
19
        'merge_parent_hidden_attributes',
20
21
        'attribute_casting',
22
        'merge_parent_casting',
23
    ];
24
25
    public function mergeHiddenAttributes(array $hidden_attributes, bool $merge_hidden = true)
26
    {
27
        $hidden_attributes = $merge_hidden
28
            ? array_merge(get_ancestor_property(get_called_class(), 'hidden_attributes'), $hidden_attributes)
29
            : $hidden_attributes;
30
31
        $this->trait_hidden_attributes = array_merge($this->trait_hidden_attributes, $hidden_attributes);
32
33
        $this->bootHiddenAttributes();
34
35
        return $this;
36
    }
37
38
    public function getHiddenAttributes()
39
    {
40
        if (!$this->hidden_booted) {
41
            $this->bootHiddenAttributes();
42
        }
43
44
        return $this->trait_hidden_attributes;
45
    }
46
47
    public function isHidden($key): bool
48
    {
49
        return array_key_exists($key, $this->getHiddenAttributes());
50
    }
51
52
    protected function bootHiddenAttributes()
53
    {
54
        $this->trait_hidden_attributes = array_combine($this->trait_hidden_attributes, $this->trait_hidden_attributes);
55
56
        $this->hidden_booted = true;
57
    }
58
}
59