Completed
Push — master ( 6373f2...b930c3 )
by Dmitry
02:29
created

MiddlewareAttribute   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 24
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRuleForOperator() 0 11 2
1
<?php
2
3
namespace hiapi\query\attributes;
4
5
/**
6
 * Class MiddlewareAttribute
7
 *
8
 * Usage:
9
 *
10
 * ```php
11
 * $attribute = new MiddlewareAttribute([
12
 *     new StringAttribute(),
13
 *     new RegexAttribute('^[a-z]+$'),
14
 * ]);
15
 * ```
16
 *
17
 * @author Dmytro Naumenko <[email protected]>
18
 */
19
class MiddlewareAttribute implements AttributeInterface
20
{
21
    /**
22
     * @var array
23
     */
24
    private $middlewareAttribtues;
25
26
    public function __construct(... $attributes)
27
    {
28
        $this->middlewareAttribtues = $attributes;
29
    }
30
31
    public function getRuleForOperator($operator)
32
    {
33
        $rules = [];
34
35
        foreach ($this->middlewareAttribtues as $attribute) {
36
            /** @var AttributeInterface $attribute */
37
            $rules[] = $attribute->getRuleForOperator($operator);
38
        }
39
40
        return $rules;
41
    }
42
}
43