Passed
Push — master ( c062f3...83edb5 )
by Aleksandr
02:32
created

QueryBuilderAttributes   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 26.09%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 58
ccs 6
cts 23
cp 0.2609
rs 10
wmc 14

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isAttributeJoined() 0 3 1
A setAttributeJoined() 0 6 3
A getAttribute() 0 3 1
A setAttributeSelected() 0 6 3
A getAttributes() 0 3 1
A isAttribute() 0 3 1
A isAttributeSelected() 0 3 1
A setAttributes() 0 4 2
A appendAttribute() 0 3 1
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 * @author    Aleksandr Drobotik <[email protected]>
5
 * @copyright 2023 Aleksandr Drobotik
6
 * @license   https://opensource.org/license/mit  The MIT License
7
 */
8
declare(strict_types=1);
9
10
namespace Drobotik\Eav\QueryBuilder;
11
12
use Drobotik\Eav\Enum\_ATTR;
13
14
class QueryBuilderAttributes
15
{
16
    private array $attributes = [];
17
    private array $joins = [];
18
    private array $selected = [];
19
20
    public function setAttributes(array $attributes) : void
21
    {
22
        foreach ($attributes as $attribute)
23
            $this->appendAttribute($attribute);
24
    }
25
26
    public function getAttributes(): array
27
    {
28
        return $this->attributes;
29
    }
30
31 1
    public function appendAttribute(array $attribute): void
32
    {
33 1
        $this->attributes[$attribute[_ATTR::NAME->column()]] = $attribute;
34
    }
35
36 1
    public function getAttribute(string $name) : array
37
    {
38 1
        return $this->attributes[$name];
39
    }
40
41 1
    public function isAttribute(string $name) : bool
42
    {
43 1
        return key_exists($name, $this->attributes);
44
    }
45
46
    public function setAttributeJoined(string $name): void
47
    {
48
        if(!$this->isAttribute($name)) return;
49
        if(!$this->isAttributeJoined($name))
50
        {
51
            $this->joins[] = $name;
52
        }
53
    }
54
55
    public function isAttributeJoined(string $name) : bool
56
    {
57
        return in_array($name, $this->joins);
58
    }
59
60
    public function setAttributeSelected(string $name): void
61
    {
62
        if(!$this->isAttribute($name)) return;
63
        if(!$this->isAttributeJoined($name))
64
        {
65
            $this->selected[] = $name;
66
        }
67
    }
68
69
    public function isAttributeSelected(string $name) : bool
70
    {
71
        return in_array($name, $this->selected);
72
    }
73
}