Completed
Push — master ( 770316...74fc07 )
by Jeroen
09:08 queued 02:44
created

DashboardWidget::getCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Kunstmaan\DashboardBundle\Widget;
4
5
use Doctrine\Common\Annotations\AnnotationReader;
6
use Symfony\Component\Routing\Annotation\Route;
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
class DashboardWidget
11
{
12
    /**
13
     * @var ContainerAwareCommand
14
     */
15
    private $command;
16
17
    /**
18
     * @var string
19
     */
20
    private $controller;
21
22
    /**
23
     * @param string                                                    $command
24
     * @param string                                                    $controller
25
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
26
     */
27
    public function __construct($command, $controller, ContainerInterface $container)
28
    {
29
        $this->command = new $command();
30
        $this->command->setContainer($container);
31
        $this->controller = $controller;
32
    }
33
34
    /**
35
     * @return ContainerAwareCommand
36
     */
37
    public function getCommand()
38
    {
39
        return $this->command;
40
    }
41
42
    public function resolvedController()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44
        $annotationReader = new AnnotationReader();
45
        $reflectionMethod = new \ReflectionMethod($this->controller, 'widgetAction');
46
        $methodAnnotations = $annotationReader->getMethodAnnotations($reflectionMethod);
47
        foreach ($methodAnnotations as $annotation) {
48
            if ($annotation instanceof Route) {
49
                if (empty($annotation)) {
50
                    throw new \Exception('The name is not configured in the annotation');
51
                }
52
                /* @var \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route $annotation */
53
                return $annotation->getName();
54
            }
55
        }
56
57
        throw new \Exception('There is no route annotation');
58
    }
59
}
60