SuggestionsController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
c 2
b 0
f 0
dl 0
loc 24
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 17 2
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\FactFinder\Controller;
9
10
use Generated\Shared\Transfer\FactFinderSdkSuggestRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...kSuggestRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Spryker\Yves\Kernel\Controller\AbstractController;
12
use SprykerEco\Shared\FactFinder\FactFinderConstants;
13
use Symfony\Component\HttpFoundation\Request;
14
15
/**
16
 * @method \SprykerEco\Yves\FactFinder\FactFinderFactory getFactory()
17
 */
18
class SuggestionsController extends AbstractController
19
{
20
    /**
21
     * @param \Symfony\Component\HttpFoundation\Request $request
22
     *
23
     * @return \Symfony\Component\HttpFoundation\JsonResponse
24
     */
25
    public function indexAction(Request $request)
26
    {
27
        $factFinderSuggestRequestTransfer = new FactFinderSdkSuggestRequestTransfer();
28
        $query = $request->query->get('query', '*');
29
30
        $factFinderSuggestRequestTransfer->setQuery($query);
31
        $factFinderSuggestRequestTransfer->setSid($request->cookies->get(FactFinderConstants::COOKIE_SID_NAME));
32
33
        $response = $this->getFactory()
34
            ->getFactFinderClient()
35
            ->getSuggestions($factFinderSuggestRequestTransfer);
36
37
        if (!$response->getSuggestions()) {
38
            return $this->jsonResponse(null, 400);
39
        }
40
41
        return $this->jsonResponse($response->getSuggestions());
42
    }
43
}
44