RequiredPermissions   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPermissions() 0 5 1
A isSeveralSupported() 0 4 1
A apply() 0 6 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