Passed
Branch development (bc47df)
by Theodoros
05:07
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;
11
use Symfony\Component\HttpFoundation\Request;
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
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