Extractor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 45
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractAnnotations() 0 17 4
A getReflectionMethod() 0 8 2
1
<?php
2
/**
3
 * This file contains functionality relating to API documentation
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
namespace BZIon\ApiDoc;
10
11
use Nelmio\ApiDocBundle\Extractor\ApiDocExtractor;
12
use Symfony\Component\HttpFoundation\ParameterBag;
13
use Symfony\Component\Routing\Route;
14
15
/**
16
 * A class that finds the ApiDoc annotations in our controllers
17
 */
18
class Extractor extends ApiDocExtractor
19
{
20
    /**
21
     * Returns an array of data where each data is an array with the following keys:
22
     *  - annotation
23
     *  - resource
24
     *
25
     * @param array  $routes array of Route-objects for which the annotations should be extracted
26
     * @param string $view
27
     *
28
     * @return array
29
     */
30
    public function extractAnnotations(array $routes, $view = 'default')
31
    {
32
        foreach ($routes as &$route) {
33
            if (!$route instanceof Route) {
34
                throw new \InvalidArgumentException(sprintf('All elements of $routes must be instances of Route. "%s" given', gettype($route)));
35
            }
36
37
            if (!$route->getDefault('_defaultHandler')) {
38
                $route = clone $route;
39
40
                $parameters = new ParameterBag($route->getDefaults());
41
                $route->setDefault('_controller', \Controller::getController($parameters)->getAction());
42
            }
43
        }
44
45
        return parent::extractAnnotations($routes);
46
    }
47
48
    /**
49
     * Returns the ReflectionMethod for the given controller string.
50
     *
51
     * @param  \ReflectionMethod|string $controller
52
     * @return \ReflectionMethod|null
53
     */
54
    public function getReflectionMethod($controller)
55
    {
56
        if ($controller instanceof \ReflectionMethod) {
57
            return $controller;
58
        } else {
59
            return parent::getReflectionMethod($controller);
60
        }
61
    }
62
}
63