RequiredPermissions::setPermissions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
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 Paysera\Bundle\ApiBundle\Annotation;
5
6
use Paysera\Bundle\ApiBundle\Entity\RestRequestOptions;
7
use Paysera\Bundle\ApiBundle\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 96
    public function __construct(array $options)
21
    {
22 96
        $this->setPermissions($options['permissions']);
23 96
    }
24
25
    /**
26
     * @param array $permissions
27
     * @return $this
28
     */
29 96
    private function setPermissions(array $permissions): self
30
    {
31 96
        $this->permissions = $permissions;
32 96
        return $this;
33
    }
34
35 96
    public function isSeveralSupported(): bool
36
    {
37 96
        return true;
38
    }
39
40 96
    public function apply(RestRequestOptions $options, ReflectionMethodWrapper $reflectionMethod)
41
    {
42 96
        $options->setRequiredPermissions(
43 96
            array_unique(array_merge($options->getRequiredPermissions(), $this->permissions))
44
        );
45 96
    }
46
}
47