BeforeFilter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 27
ccs 14
cts 16
cp 0.875
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 BeforeFilter
25
{
26
    use Traits\FilterTrait;
27
28 6
    public function __construct(array $values)
29
    {
30 6
        $names = (array) ($values['value'] ?? []);
31 6
        $only = (array) ($values['only'] ?? []);
32 6
        $except = (array) ($values['except'] ?? []);
33
34 6
        Assert::minCount($names, 1);
35 6
        Assert::allStringNotEmpty($names);
36 6
        Assert::allStringNotEmpty($only);
37 6
        Assert::allStringNotEmpty($except);
38
39 6
        unset($values['value'], $values['only'], $values['except']);
40 6
        if (\count($values) > 0) {
41
            throw new \InvalidArgumentException(sprintf('The annotation @%s does not have a property named "%s".', \get_class($this), implode('", "', array_keys($values))));
42
        }
43
44 6
        if ($result = \array_intersect($only, $except)) {
45
            throw new \InvalidArgumentException(sprintf('You cannot put "%s" in "only" and "except" at the same time.', implode('", "', $result)));
46
        }
47
48 6
        $this->names = $names;
49 6
        $this->only = $only;
50 6
        $this->except = $except;
51 6
    }
52
}
53