Passed
Pull Request — master (#65)
by Claudio
07:03
created

AjaxOptionController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 2
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A listAction() 0 8 2
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
    private BaseAjaxOptionController $baseController;
14
15
    public function __construct(BaseAjaxOptionController $baseController)
16
    {
17
        $this->baseController = $baseController;
18
    }
19
20
    /**
21
     * Because of another hardcoded PHP class name in
22
     *
23
     * @see vendor/akeneo/pim-enterprise-dev/src/Akeneo/Pim/Automation/RuleEngine/front/src/fetch/AttributeOptionFetcher.ts
24
     *
25
     * the AttributeOption class can and should not be overridden in Akeneo PIM, we came up with this workaround to
26
     * support the legacy code of the Table attribute.
27
     *
28
     * @param Request $request
29
     *
30
     * @return JsonResponse
31
     */
32
    public function listAction(Request $request)
33
    {
34
        $class = $request->query->get('class');
35
        if ($class === AttributeOption::class) {
36
            $request->query->set('class', TableAttributeOption::class);
37
        }
38
39
        return $this->baseController->listAction($request);
40
    }
41
}
42