Issues (105)

src/ServiceProvider/Traits/LoaderTrait.php (1 issue)

Labels
Severity
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
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