Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
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
use Doctrine\Common\Annotations\AnnotationReader;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\Routing\Annotation\Route;
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
     */
26
    public function __construct($command, $controller, ContainerInterface $container)
27
    {
28
        $this->command = new $command();
29
        $this->command->setContainer($container);
30
        $this->controller = $controller;
31
    }
32
33
    /**
34
     * @return ContainerAwareCommand
35
     */
36
    public function getCommand()
37
    {
38
        return $this->command;
39
    }
40
41
    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...
42
    {
43
        $annotationReader = new AnnotationReader();
44
        $reflectionMethod = new \ReflectionMethod($this->controller, 'widgetAction');
45
        $methodAnnotations = $annotationReader->getMethodAnnotations($reflectionMethod);
46
        foreach ($methodAnnotations as $annotation) {
47
            if ($annotation instanceof Route) {
48
                if (empty($annotation)) {
49
                    throw new \Exception('The name is not configured in the annotation');
50
                }
51
52
                return $annotation->getName();
53
            }
54
        }
55
56
        throw new \Exception('There is no route annotation');
57
    }
58
}
59