Completed
Pull Request — master (#1)
by David
06:59
created

Right   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 28
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 3
A getName() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\GraphQL\Controllers\Annotations;
5
6
/**
7
 * @Annotation
8
 * @Target({"METHOD"})
9
 * @Attributes({
10
 *   @Attribute("name", type = "string"),
11
 * })
12
 */
13
class Right
14
{
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
20
    /**
21
     * @param array $values
22
     *
23
     * @throws \BadMethodCallException
24
     */
25
    public function __construct(array $values)
26
    {
27
        if (!isset($values['value']) && !isset($values['name'])) {
28
            throw new \BadMethodCallException('The @Right annotation must be passed a right name. For instance: "@Right(\'my_right\')"');
29
        }
30
        $this->name = $values['value'] ?? $values['name'];
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getName(): string
37
    {
38
        return $this->name;
39
    }
40
}
41