LoaderTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerLoader() 0 4 1
A createLoader() 0 17 1
1
<?php
2
3
namespace Nip\Router\ServiceProvider\Traits;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\Routing\Loader\DirectoryLoader;
7
use Symfony\Component\Routing\Loader\PhpFileLoader;
8
9
/**
10
 * Trait LoaderTrait
11
 * @package Nip\Router\ServiceProvider\Traits
12
 */
13
trait LoaderTrait
14
{
15 3
    public function registerLoader()
16
    {
17
        $this->getContainer()->share('routing.loader', function () {
0 ignored issues
show
Bug introduced by
It seems like getContainer() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        $this->/** @scrutinizer ignore-call */ 
18
               getContainer()->share('routing.loader', function () {
Loading history...
18 3
            return $this->createLoader();
19 3
        });
20 3
    }
21
22
    /**
23
     * @return \Symfony\Component\Config\Loader\DelegatingLoader
24
     */
25 3
    protected function createLoader()
26
    {
27 3
        $app = $this->getContainer()->get('app');
28
29 3
        $locator = new FileLocator([
30 3
            $app->basePath() . DIRECTORY_SEPARATOR . 'routes',
31 3
            $app->path(),
32 3
            $app->basePath(),
33
        ]);
34
35 3
        $resolver = new \Symfony\Component\Config\Loader\LoaderResolver();
36 3
        $resolver->addLoader(new PhpFileLoader($locator));
37 3
        $resolver->addLoader(new DirectoryLoader($locator));
38
39 3
        $loader = new \Nip\Router\Loader\DelegatingLoader($resolver);
40
41 3
        return $loader;
42
    }
43
}
44