Completed
Push — master ( 3e297a...bce447 )
by David
15s
created

Factory::setAliases()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TheCodingMachine\Funky\Annotations;
5
6
use Doctrine\Common\Annotations\Annotation\Attribute;
7
8
/**
9
 * @Annotation
10
 * @Target({"METHOD"})
11
 * @Attributes({
12
 *   @Attribute("name", type = "string"),
13
 *   @Attribute("nameFromType", type = "bool"),
14
 *   @Attribute("nameFromMethodName", type = "bool"),
15
 *   @Attribute("aliases", type = "array<string>"),
16
 *   @Attribute("tags", type = "array<\TheCodingMachine\Funky\Annotations\Tag>")
17
 * })
18
 */
19
class Factory extends AbstractAnnotation
20
{
21
    /**
22
     * @var string[]
23
     */
24
    private $aliases = [];
25
26
    /**
27
     * @param mixed[] $attributes
28
     */
29
    public function __construct(array $attributes = [])
30
    {
31
        parent::__construct($attributes);
32
        if (isset($attributes['aliases']) && \is_array($attributes['aliases'])) {
33
            $this->setAliases(...$attributes['aliases']);
34
        }
35
    }
36
37
    /**
38
     * Helper method to ensure that the passed aliases are of string type.
39
     *
40
     * @param string[] $aliases
41
     */
42
    private function setAliases(string ...$aliases): void
43
    {
44
        $this->aliases = $aliases;
45
    }
46
    /**
47
     * Returns the list of aliases for the bean instance. Returns an empty array when no alias was set.
48
     *
49
     * @return string[]
50
     */
51
    public function getAliases(): array
52
    {
53
        return $this->aliases;
54
    }
55
}
56