MiddlewareAttribute   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 24
ccs 0
cts 12
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
 * 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