Passed
Branch development (0519a2)
by Theodoros
02:02
created

IndexController::productAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
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\Zed\Econda\Communication\Controller;
9
10
use Spryker\Zed\Kernel\Communication\Controller\AbstractController;
0 ignored issues
show
Bug introduced by
The type Spryker\Zed\Kernel\Commu...ller\AbstractController 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 Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request 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...
12
13
/**
14
 * @method \SprykerEco\Zed\Econda\Business\EcondaFacadeInterface getFacade()
15
 */
16
class IndexController extends AbstractController
17
{
18
19
    const CATEGORIES = 'categories';
20
    const PRODUCTS = 'products';
21
22
    /**
23
     * @param \Symfony\Component\HttpFoundation\Request $request
24
     *
25
     * @return \Symfony\Component\HttpFoundation\StreamedResponse
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\StreamedResponse 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...
26
     */
27 View Code Duplication
    public function categoryAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $response = $this->getFacade()->getFileContent(self::CATEGORIES, $this->getLocale($request));
30
31
        return $this->streamedResponse(
32
            function () use ($response) {
33
                echo $response;
34
            },
35
            200,
36
            ["Content-type" => "text/csv", 'Content-Disposition' => 'attachment; filename="categories.csv"']
37
        );
38
    }
39
40
    /**
41
     * @param \Symfony\Component\HttpFoundation\Request $request
42
     *
43
     * @return \Symfony\Component\HttpFoundation\StreamedResponse
44
     */
45 View Code Duplication
    public function productAction(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $response = $this->getFacade()->getFileContent(self::PRODUCTS, $this->getLocale($request));
48
49
        return $this->streamedResponse(
50
            function () use ($response) {
51
                echo $response;
52
            },
53
            200,
54
            ["Content-type" => "text/csv", 'Content-Disposition' => 'attachment; filename="products.csv"']
55
        );
56
    }
57
58
    /**
59
     * @param \Symfony\Component\HttpFoundation\Request $request
60
     *
61
     * @return string
62
     */
63
    protected function getLocale(Request $request)
64
    {
65
        if ($request->query->get('locale') !== null) {
66
            return $request->query->get('locale');
67
        }
68
        return $this->getApplication()['locale'];
69
    }
70
71
}
72