Completed
Push — master ( d6e5bd...91fdab )
by Sander
13:05
created

DashboardBundle/Widget/DashboardWidget.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\DashboardBundle\Widget;
4
5
6
use Doctrine\Common\Annotations\AnnotationReader;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
10
11
class DashboardWidget
12
{
13
14
    /**
15
     * @var ContainerAwareCommand $collector
16
     */
17
    private $command;
18
19
    /**
20
     * @var string $controller
21
     */
22
    private $controller;
23
24
    /**
25
     * @param string $command
26
     * @param string $controller
27
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
28
     */
29
    public function __construct($command, $controller, ContainerInterface $container)
30
    {
31
        $this->command = new $command();
32
        $this->command->setContainer($container);
33
        $this->controller = $controller;
34
    }
35
36
    /**
37
     * @return ContainerAwareCommand
38
     */
39
    public function getCommand()
40
    {
41
        return $this->command;
42
    }
43
44
    public function resolvedController()
0 ignored issues
show
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...
45
    {
46
        $annotationReader = new AnnotationReader();
47
        $reflectionMethod = new \ReflectionMethod($this->controller, 'widgetAction');
48
        $methodAnnotations = $annotationReader->getMethodAnnotations($reflectionMethod);
49
        foreach ($methodAnnotations as $annotation) {
50
            if ($annotation instanceof Route) {
51
                if (empty($annotation)) {
52
                    throw new \Exception("The name is not configured in the annotation");
53
                }
54
                /** @var \Sensio\Bundle\FrameworkExtraBundle\Configuration\Route $annotation */
55
                return $annotation->getName();
56
            }
57
        }
58
        throw new \Exception("There is no route annotation");
59
    }
60
}
61