Passed
Push — master ( dbdda2...549d3d )
by Rustam
07:15
created

RoutingServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
eloc 7
c 2
b 1
f 0
dl 0
loc 18
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);
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ':', expecting T_DOUBLE_ARROW on line 29 at column 44
Loading history...
30
        $finder = (new Finder())->files()->in($paths)->name('*.php');
31
        $container->set(AnnotationLoader::class, new AnnotationLoader(new ClassLocator($finder)));
32
    }
33
}
34