Controller   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A executeAction() 0 11 2
1
<?php
2
3
namespace Pim\Bundle\CustomEntityBundle\Controller;
4
5
use Pim\Bundle\CustomEntityBundle\Action\ActionFactory;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10
/**
11
 * Controller for custom entities
12
 *
13
 * @author    Antoine Guigan <[email protected]>
14
 * @copyright 2013 Akeneo SAS (http://www.akeneo.com)
15
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
16
 */
17
class Controller
18
{
19
    /**
20
     * @var ActionFactory
21
     */
22
    protected $actionFactory;
23
24
    /**
25
     * @var Request
26
     */
27
    protected $request;
28
29
    /**
30
     * @param ActionFactory $actionFactory
31
     * @param Request       $request
32
     */
33
    public function __construct(ActionFactory $actionFactory, Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
34
    {
35
        $this->actionFactory = $actionFactory;
36
        $this->request = $request;
37
    }
38
39
    /**
40
     * Default action
41
     *
42
     * @param string $customEntityName
43
     * @param string $actionType
44
     *
45
     * @return Response
46
     * @throws NotFoundHttpException
47
     */
48
    public function executeAction($customEntityName, $actionType)
49
    {
50
        $action = $this->actionFactory->getAction($customEntityName, $actionType);
51
        if (!$action) {
52
            throw new NotFoundHttpException(
53
                sprintf('No action found for type "%s"', $actionType)
54
            );
55
        }
56
57
        return $action->execute($this->request);
58
    }
59
}
60