Passed
Push — master ( 875f6d...f03ba1 )
by Rustam
07:55
created

RoutingServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 7
c 2
b 1
f 0
dl 0
loc 18
ccs 0
cts 7
cp 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A register() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiistack\Routing;
6
7
use Spiral\Tokenizer\ClassLocator;
8
use Symfony\Component\Finder\Finder;
9
use Yiisoft\Aliases\Aliases;
10
use Yiisoft\Di\Container;
11
use Yiisoft\Di\Support\ServiceProvider;
12
use Yiistack\Annotated\AnnotationLoader;
13
14
class RoutingServiceProvider extends ServiceProvider
15
{
16
    private array $controllersPaths;
17
18
    public function __construct(array $paths = [])
19
    {
20
        $this->controllersPaths = $paths;
21
    }
22
23
    /**
24
     * @psalm-suppress InaccessibleMethod
25
     */
26
    public function register(Container $container): void
27
    {
28
        $aliases = $container->get(Aliases::class);
29
        $paths = array_map(static fn ($path): string => $aliases->get($path), $this->controllersPaths);
30
        $finder = (new Finder())->files()->in($paths)->name('*.php');
31
        $container->set(AnnotationLoader::class, new AnnotationLoader(new ClassLocator($finder)));
32
    }
33
}
34