Passed
Pull Request — master (#126)
by David
05:10
created

AddInterfaceOnDao   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 3
A getName() 0 3 1
1
<?php
2
3
4
namespace TheCodingMachine\TDBM\Utils\Annotation;
5
6
/**
7
 * @Annotation
8
 * @Attributes({
9
 *   @Attribute("name", type = "string"),
10
 * })
11
 */
12
final class AddInterfaceOnDao
13
{
14
    /**
15
     * The PHP interface that is implemented by the Dao.
16
     *
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @param array<string, mixed> $values
23
     *
24
     * @throws \BadMethodCallException
25
     */
26
    public function __construct(array $values)
27
    {
28
        if (!isset($values['value']) && !isset($values['name'])) {
29
            throw new \BadMethodCallException('The @AddInterfaceOnDao annotation must be passed an interface to implement. For instance: \'@AddInterfaceOnDao("Foo\\BarInterface")\'');
30
        }
31
        $this->name = $values['value'] ?? $values['name'];
32
    }
33
34
    public function getName(): string
35
    {
36
        return $this->name;
37
    }
38
}
39