RequiredPermissions::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Maba\Bundle\RestBundle\Annotation;
5
6
use Maba\Bundle\RestBundle\Entity\RestRequestOptions;
7
use Maba\Bundle\RestBundle\Service\Annotation\ReflectionMethodWrapper;
8
9
/**
10
 * @Annotation
11
 * @Target({"CLASS", "METHOD"})
12
 */
13
class RequiredPermissions implements RestAnnotationInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    private $permissions;
19
20 81
    public function __construct(array $options)
21
    {
22 81
        $this->setPermissions($options['permissions']);
23 81
    }
24
25
    /**
26
     * @param array $permissions
27
     * @return $this
28
     */
29 81
    private function setPermissions(array $permissions): self
30
    {
31 81
        $this->permissions = $permissions;
32 81
        return $this;
33
    }
34
35 81
    public function isSeveralSupported(): bool
36
    {
37 81
        return true;
38
    }
39
40 81
    public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
41
    {
42 81
        $options->setRequiredPermissions(
43 81
            array_unique(array_merge($options->getRequiredPermissions(), $this->permissions))
44
        );
45 81
    }
46
}
47