Extractor::getReflectionMethod()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
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