Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
ExportCsvHandler | |
100.00% |
9 / 9 |
|
100.00% |
2 / 2 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
generateCsv | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\Reporting\Handler; |
25 | |
26 | use App\Domain\Reporting\Generator\Csv\CollectivityGenerator; |
27 | use App\Domain\Reporting\Generator\Csv\ContractorGenerator; |
28 | use App\Domain\Reporting\Generator\Csv\MesurementGenerator; |
29 | use App\Domain\Reporting\Generator\Csv\TreatmentGenerator; |
30 | use Symfony\Component\HttpFoundation\BinaryFileResponse; |
31 | |
32 | class ExportCsvHandler |
33 | { |
34 | public const COLLECTIVITY_TYPE = 'collectivity'; |
35 | public const CONTRACTOR_TYPE = 'contractor'; |
36 | public const TREATMENT_TYPE = 'treatment'; |
37 | public const MESUREMENT_TYPE = 'mesurement'; |
38 | |
39 | /** |
40 | * @var CollectivityGenerator |
41 | */ |
42 | private $collectivityGenerator; |
43 | |
44 | /** |
45 | * @var ContractorGenerator |
46 | */ |
47 | private $contractorGenerator; |
48 | |
49 | /** |
50 | * @var TreatmentGenerator |
51 | */ |
52 | private $treatmentGenerator; |
53 | |
54 | /** |
55 | * @var MesurementGenerator |
56 | */ |
57 | private $mesurementGenerator; |
58 | |
59 | public function __construct( |
60 | CollectivityGenerator $collectivityGenerator, |
61 | ContractorGenerator $contractorGenerator, |
62 | TreatmentGenerator $treatmentGenerator, |
63 | MesurementGenerator $mesurementGenerator, |
64 | ) { |
65 | $this->collectivityGenerator = $collectivityGenerator; |
66 | $this->contractorGenerator = $contractorGenerator; |
67 | $this->treatmentGenerator = $treatmentGenerator; |
68 | $this->mesurementGenerator = $mesurementGenerator; |
69 | } |
70 | |
71 | public function generateCsv(string $type): BinaryFileResponse |
72 | { |
73 | switch ($type) { |
74 | case self::COLLECTIVITY_TYPE: |
75 | return $this->collectivityGenerator->generateResponse(self::COLLECTIVITY_TYPE); |
76 | break; |
77 | case self::CONTRACTOR_TYPE: |
78 | return $this->contractorGenerator->generateResponse(self::CONTRACTOR_TYPE); |
79 | break; |
80 | case self::TREATMENT_TYPE: |
81 | return $this->treatmentGenerator->generateResponse(self::TREATMENT_TYPE); |
82 | break; |
83 | case self::MESUREMENT_TYPE: |
84 | return $this->mesurementGenerator->generateResponse(self::MESUREMENT_TYPE); |
85 | break; |
86 | default: |
87 | throw new \LogicException('The type ' . $type . ' is not support for csv export'); |
88 | } |
89 | } |
90 | } |