RouteCollectionFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
dl 0
loc 27
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 14 3
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Http\Business\Route;
15
16
use Micro\Plugin\Http\Business\Locator\RouteLocatorFactoryInterface;
17
18
/**
19
 * @author Stanislau Komar <[email protected]>
20
 */
21
class RouteCollectionFactory implements RouteCollectionFactoryInterface
22
{
23
    private RouteCollectionInterface|null $routeCollection;
24
25
    public function __construct(
26
        private readonly RouteLocatorFactoryInterface $routeLocatorFactory
27
    ) {
28 6
        $this->routeCollection = null;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    public function create(): RouteCollectionInterface
35
    {
36 6
        if ($this->routeCollection) {
37
            return $this->routeCollection;
38
        }
39
40 6
        $collection = new RouteCollection();
41
42 6
        $locator = $this->routeLocatorFactory->create();
43 6
        foreach ($locator->locate() as $route) {
44 6
            $collection->addRoute($route);
45
        }
46
47 6
        return $this->routeCollection = $collection;
48
    }
49
}
50