Completed
Push — master ( 40c204...d2298a )
by Guilh
15:44 queued 12:52
created

DirectoryRouteLoader   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 93.33%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 38
ccs 14
cts 15
cp 0.9333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 17 3
A __construct() 0 4 1
A supports() 0 4 3
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\RestBundle\Routing\Loader;
13
14
use Symfony\Component\Config\Loader\Loader;
15
use Symfony\Component\Finder\Finder;
16
use Symfony\Component\Routing\RouteCollection;
17
18
/**
19
 * Parse annotated controller classes from all files of a directory.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class DirectoryRouteLoader extends Loader
24
{
25
    private $processor;
26
27 12
    public function __construct(RestRouteProcessor $processor)
28
    {
29 12
        $this->processor = $processor;
30 12
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function load($resource, $type = null)
36
    {
37 1
        if (!is_dir($resource)) {
38
            throw new \InvalidArgumentException(sprintf('Given resource of type "%s" is no directory.', $resource));
39
        }
40
41 1
        $collection = new RouteCollection();
42
43 1
        $finder = new Finder();
44
45 1
        foreach ($finder->in($resource)->name('*.php')->files() as $file) {
46 1
            $imported = $this->processor->importResource($this, ClassUtils::findClassInFile($file), array(), null, null, 'rest');
47 1
            $collection->addCollection($imported);
48 1
        }
49
50 1
        return $collection;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 5
    public function supports($resource, $type = null)
57
    {
58 5
        return 'rest' === $type && is_string($resource) && is_dir($resource);
59
    }
60
}
61