Passed
Push — master ( 332155...966852 )
by Siim
12:13
created

ApiLoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: siim
5
 * Date: 3.03.19
6
 * Time: 20:42
7
 */
8
9
namespace Sf4\Api\Routing;
10
11
use Symfony\Component\Config\Loader\Loader;
12
use Symfony\Component\Routing\RouteCollection;
13
14
class ApiLoader extends Loader
15
{
16
    const TYPE = 'sf4_api';
17
18
    /** @var bool $isLoaded */
19
    protected $isLoaded = false;
20
21
    /**
22
     * @param mixed $resource
23
     * @param null $type
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $type is correct as it would always require null to be passed?
Loading history...
24
     * @return RouteCollection|null
25
     */
26
    public function load($resource, $type = null)
27
    {
28
        if (true === $this->isLoaded) {
29
            return null;
30
        }
31
32
        $routes = new RouteCollection();
33
34
        $resource = '@Sf4ApiBundle/Resources/config/routing.yaml';
35
        $type = 'yaml';
36
37
        $importedRoutes = $this->import($resource, $type);
38
        $routes->addCollection($importedRoutes);
0 ignored issues
show
Bug introduced by
It seems like $importedRoutes can also be of type null; however, parameter $collection of Symfony\Component\Routin...ection::addCollection() does only seem to accept Symfony\Component\Routing\RouteCollection, maybe add an additional type check? ( Ignorable by Annotation )

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

38
        $routes->addCollection(/** @scrutinizer ignore-type */ $importedRoutes);
Loading history...
39
40
        $this->isLoaded = true;
41
42
        return $routes;
43
    }
44
45
    /**
46
     * @param mixed $resource
47
     * @param null $type
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $type is correct as it would always require null to be passed?
Loading history...
48
     * @return bool
49
     */
50
    public function supports($resource, $type = null)
51
    {
52
        return static::TYPE === $type;
53
    }
54
}
55