AfterFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 27
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 23 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the MiddlewareBundle
7
 *
8
 * (c) Indra Gunawan <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Indragunawan\MiddlewareBundle\Annotation;
15
16
use Webmozart\Assert\Assert;
17
18
/**
19
 * @Annotation
20
 * @Target({"CLASS"})
21
 *
22
 * @author Indra Gunawan <[email protected]>
23
 */
24
final class AfterFilter
25
{
26
    use Traits\FilterTrait;
27
28 11
    public function __construct(array $values)
29
    {
30 11
        $names = (array) ($values['value'] ?? []);
31 11
        $only = (array) ($values['only'] ?? []);
32 11
        $except = (array) ($values['except'] ?? []);
33
34 11
        Assert::minCount($names, 1);
35 10
        Assert::allStringNotEmpty($names);
36 7
        Assert::allStringNotEmpty($only);
37 5
        Assert::allStringNotEmpty($except);
38
39 3
        unset($values['value'], $values['only'], $values['except']);
40 3
        if (\count($values) > 0) {
41 1
            throw new \InvalidArgumentException(sprintf('The annotation @%s does not have a property named "%s".', \get_class($this), implode('", "', array_keys($values))));
42
        }
43
44 2
        if ($result = \array_intersect($only, $except)) {
45 1
            throw new \InvalidArgumentException(sprintf('You cannot put "%s" in "only" and "except" at the same time.', implode('", "', $result)));
46
        }
47
48 1
        $this->names = $names;
49 1
        $this->only = $only;
50 1
        $this->except = $except;
51 1
    }
52
}
53