Passed
Pull Request — master (#65)
by Antonio
18:12 queued 12:21
created

AjaxOptionController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Flagbit\Bundle\TableAttributeBundle\Controller;
4
5
use Akeneo\Pim\Structure\Component\Model\AttributeOption;
6
use Akeneo\Platform\Bundle\UIBundle\Controller\AjaxOptionController as BaseAjaxOptionController;
7
use Flagbit\Bundle\TableAttributeBundle\Entity\AttributeOption as TableAttributeOption;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class AjaxOptionController
12
{
13
    /**
14
     * @var BaseAjaxOptionController
15
     */
16
    private $baseController;
17
18
    public function __construct(BaseAjaxOptionController $baseController)
19
    {
20
        $this->baseController = $baseController;
21
    }
22
23
    /**
24
     * Because of another hardcoded PHP class name in
25
     *
26
     * @see vendor/akeneo/pim-enterprise-dev/src/Akeneo/Pim/Automation/RuleEngine/front/src/fetch/AttributeOptionFetcher.ts
27
     *
28
     * the AttributeOption class can and should not be overridden in Akeneo PIM, we came up with this workaround to
29
     * support the legacy code of the Table attribute.
30
     *
31
     * @param Request $request
32
     *
33
     * @return JsonResponse
34
     */
35
    public function listAction(Request $request)
36
    {
37
        $class = $request->query->get('class');
38
        if ($class === AttributeOption::class) {
39
            $request->query->set('class', TableAttributeOption::class);
40
        }
41
42
        return $this->baseController->listAction($request);
43
    }
44
}
45