Completed
Push — master ( 7762ce...618a95 )
by Hannes
02:39
created

Annotation::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\readmetester;
6
7
/**
8
 * Annotation value object
9
 */
10
class Annotation
11
{
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
17
    /**
18
     * @var string[]
19
     */
20
    private $arguments;
21
22
    public function __construct(string $name, string ...$arguments)
23
    {
24
        $this->name = $name;
25
        $this->arguments = $arguments;
26
    }
27
28
    /**
29
     * Get annotation name
30
     */
31
    public function getName(): string
32
    {
33
        return $this->name;
34
    }
35
36
    /**
37
     * Check if annotation name matches name in a case insensitive manner
38
     */
39
    public function isNamed(string $name): bool
40
    {
41
        return !strcasecmp($name, $this->getName());
42
    }
43
44
    /**
45
     * @return string[]
46
     */
47
    public function getArguments(): array
48
    {
49
        return $this->arguments;
50
    }
51
52
    /**
53
     * @param integer $index Optional index of argument to read
54
     */
55
    public function getArgument(int $index = 0): string
56
    {
57
        if (!isset($this->arguments[$index])) {
58
            throw new \LogicException("Annotation @{$this->getName()} missing argument $index");
59
        }
60
61
        return $this->arguments[$index];
62
    }
63
}
64