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

Properties   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 11 2
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\Property;
17
18
/**
19
 * Property aggregation. Can automatically create constant on demand.
20
 *
21
 * @method $this add(Property $element)
22
 */
23
final class Properties extends Aggregator
24
{
25
    /**
26
     * @param array $constants
27
     */
28
    public function __construct(array $constants)
29
    {
30
        parent::__construct([Property::class], $constants);
31
    }
32
33
    /**
34
     * Get named element by it's name.
35
     *
36
     * @param string $name
37
     * @return Property|DeclarationInterface
38
     */
39
    public function get(string $name): Property
40
    {
41
        if (!$this->has($name)) {
42
            //Automatically creating constant
43
            $property = new Property($name);
44
            $this->add($property);
45
46
            return $property;
47
        }
48
49
        return parent::get($name);
50
    }
51
}
52