Passed
Branch development (bc47df)
by Theodoros
05:07
created

IndexController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 45.28 %

Importance

Changes 0
Metric Value
dl 24
loc 53
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A categoryAction() 10 10 1
A productAction() 10 10 1
A getLocale() 0 6 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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