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

RoutingServiceProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

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
ccs 0
cts 2
cp 0
crap 2
rs 10
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