Passed
Pull Request — master (#831)
by Maxim
06:01
created

GroupRegistry::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 0
c 0
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Router;
6
7
use Spiral\Core\FactoryInterface;
8
9
/**
10
 * Manages the presets for various route groups.
11
 */
12
final class GroupRegistry implements \IteratorAggregate
13
{
14
    private string $defaultGroup = 'web';
15
16
    /** @var array<non-empty-string, RouteGroup> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<non-empty-string, RouteGroup> at position 2 could not be parsed: Unknown type name 'non-empty-string' at position 2 in array<non-empty-string, RouteGroup>.
Loading history...
17
    private array $groups = [];
18
19 276
    public function __construct(
20
        private readonly FactoryInterface $factory
21
    ) {
22
    }
23
24 276
    public function getGroup(string $name): RouteGroup
25
    {
26 276
        if (!isset($this->groups[$name])) {
27 276
            $this->groups[$name] = $this->factory->make(RouteGroup::class, ['name' => $name]);
28
        }
29
30 276
        return $this->groups[$name];
31
    }
32
33 1
    public function setDefaultGroup(string $group): self
34
    {
35 1
        $this->defaultGroup = $group;
36
37 1
        return $this;
38
    }
39
40 275
    public function getDefaultGroup(): string
41
    {
42 275
        return $this->defaultGroup;
43
    }
44
45
    /**
46
     * @return \ArrayIterator<array-key, RouteGroup>
47
     */
48 3
    public function getIterator(): \Traversable
49
    {
50 3
        return new \ArrayIterator($this->groups);
51
    }
52
}
53