Completed
Branch traitrefactor (c265e2)
by Joe
02:41
created

HasHiddenAttributes::bootHiddenAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpWinTools\WmiScripting\Concerns;
4
5
trait HasHiddenAttributes
6
{
7
    protected $hidden_booted = false;
8
9
    protected $trait_hidden_attributes = [
10
        'trait_hidden_attributes',
11
        'trait_name_replacements',
12
13
        'attribute_name_replacements',
14
        'unmapped_attributes',
15
16
        'hidden_attributes',
17
        'merge_parent_hidden_attributes',
18
19
        'attribute_casting',
20
        'merge_parent_casting',
21
    ];
22
23
    public function mergeHiddenAttributes(array $hidden_attributes, bool $merge_hidden = true)
24
    {
25
        $hidden_attributes = $merge_hidden
26
            ? array_merge($this->getAncestorProperty('hidden_attributes'), $hidden_attributes)
0 ignored issues
show
Bug introduced by
It seems like getAncestorProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            ? array_merge($this->/** @scrutinizer ignore-call */ getAncestorProperty('hidden_attributes'), $hidden_attributes)
Loading history...
27
            : $hidden_attributes;
28
29
        $this->trait_hidden_attributes = array_merge($this->trait_hidden_attributes, $hidden_attributes);
30
31
        $this->bootHiddenAttributes();
32
33
        return $this;
34
    }
35
36
    public function getHiddenAttributes()
37
    {
38
        if (!$this->hidden_booted) {
39
            $this->bootHiddenAttributes();
40
        }
41
42
        return $this->trait_hidden_attributes;
43
    }
44
45
    public function isHidden($key): bool
46
    {
47
        return array_key_exists($key, $this->getHiddenAttributes());
48
    }
49
50
    protected function bootHiddenAttributes()
51
    {
52
        $this->trait_hidden_attributes = array_combine($this->trait_hidden_attributes, $this->trait_hidden_attributes);
53
54
        $this->hidden_booted = true;
55
    }
56
}
57