MiddlewareAttribute::getRuleForOperator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 8
cp 0
c 0
b 0
f 0
rs 9.9
cc 2
nc 2
nop 1
crap 6
1
<?php
2
/**
3
 * HiAPI Yii2 base project for building API
4
 *
5
 * @link      https://github.com/hiqdev/hiapi
6
 * @package   hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiapi\query\attributes;
12
13
/**
14
 * Class MiddlewareAttribute.
15
 *
16
 * Usage:
17
 *
18
 * ```php
19
 * $attribute = new MiddlewareAttribute([
20
 *     new StringAttribute(),
21
 *     new RegexAttribute('^[a-z]+$'),
22
 * ]);
23
 * ```
24
 *
25
 * @author Dmytro Naumenko <[email protected]>
26
 */
27
class MiddlewareAttribute implements AttributeInterface
28
{
29
    /**
30
     * @var array
31
     */
32
    private $middlewareAttribtues;
33
34
    public function __construct(...$attributes)
35
    {
36
        $this->middlewareAttribtues = $attributes;
37
    }
38
39
    public function getRuleForOperator($operator)
40
    {
41
        $rules = [];
42
43
        foreach ($this->middlewareAttribtues as $attribute) {
44
            /** @var AttributeInterface $attribute */
45
            $rules[] = $attribute->getRuleForOperator($operator);
46
        }
47
48
        return $rules;
49
    }
50
}
51