Passed
Push — master ( 5545f1...83deac )
by Kirill
03:22
created

Methods::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Reactor\Aggregator;
13
14
use Spiral\Reactor\Aggregator;
15
use Spiral\Reactor\DeclarationInterface;
16
use Spiral\Reactor\Partial\Method;
17
18
/**
19
 * Method aggregation. Can automatically create constant on demand.
20
 *
21
 * @method Method add(Method $element)
22
 */
23
final class Methods extends Aggregator
24
{
25
    /**
26
     * @param array $constants
27
     */
28
    public function __construct(array $constants)
29
    {
30
        parent::__construct([Method::class], $constants);
31
    }
32
33
    /**
34
     * Get named element by it's name.
35
     *
36
     * @param string $name
37
     * @return Method|DeclarationInterface
38
     */
39
    public function get(string $name): Method
40
    {
41
        if (!$this->has($name)) {
42
            //Automatically creating constant
43
            $method = new Method($name);
44
            $this->add($method);
45
46
            return $method;
47
        }
48
49
        return parent::get($name);
50
    }
51
}
52