TrackController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setFactFinderSid() 0 4 1
A indexAction() 0 16 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\FactFinderSdkTrackingRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...TrackingRequestTransfer 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 TrackController extends AbstractController
19
{
20
    /**
21
     * @param \Symfony\Component\HttpFoundation\Request $request
22
     *
23
     * @return array
24
     */
25
    public function indexAction(Request $request)
26
    {
27
        $factFinderTrackingRequestTransfer = new FactFinderSdkTrackingRequestTransfer();
28
        $factFinderTrackingRequestTransfer->fromArray($request->query->all());
29
30
        $this->setFactFinderSid($request, $factFinderTrackingRequestTransfer);
31
32
        $factFinderTrackingResponseTransfer = $this->getFactory()
33
            ->getFactFinderClient()
34
            ->track($factFinderTrackingRequestTransfer);
35
36
        if (!$factFinderTrackingResponseTransfer->getResult()) {
37
            return $this->jsonResponse(null, 400);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->jsonResponse(null, 400) returns the type Symfony\Component\HttpFoundation\JsonResponse which is incompatible with the documented return type array.
Loading history...
38
        }
39
40
        return $this->jsonResponse();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->jsonResponse() returns the type Symfony\Component\HttpFoundation\JsonResponse which is incompatible with the documented return type array.
Loading history...
41
    }
42
43
    /**
44
     * @param \Symfony\Component\HttpFoundation\Request $request
45
     * @param \Generated\Shared\Transfer\FactFinderSdkTrackingRequestTransfer $factFinderTrackingResponseTransfer
46
     *
47
     * @return void
48
     */
49
    protected function setFactFinderSid(Request $request, FactFinderSdkTrackingRequestTransfer $factFinderTrackingResponseTransfer)
50
    {
51
        $sessionId = $request->cookies->get(FactFinderConstants::COOKIE_SID_NAME);
52
        $factFinderTrackingResponseTransfer->setSid($sessionId);
53
    }
54
}
55