ResponseFactory::makeResponse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 3
nop 3
1
<?php
2
3
/**
4
 * This file is part of the bugloos/export-bundle project.
5
 * (c) Bugloos <https://bugloos.com/>
6
 * For the full copyright and license information, please view
7
 * the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Bugloos\ExportBundle\Factory;
11
12
use Bugloos\ExportBundle\Exception\InvalidResponseTypeException;
13
use Bugloos\ExportBundle\Response\CsvResponse;
14
use Bugloos\ExportBundle\Response\XlsxResponse;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Mojtaba Gheytasi <[email protected] | [email protected]>
19
 */
20
class ResponseFactory implements ResponseFactoryInterface
21
{
22
    public function makeResponse(string $exportFormat, $content, string $fileName): Response
23
    {
24
        switch ($exportFormat) {
25
            case 'Xlsx':
26
                return new XlsxResponse($content, $fileName);
27
28
            case 'Csv':
29
                return new CsvResponse($content, $fileName);
30
31
            default:
32
                throw new InvalidResponseTypeException();
33
        }
34
    }
35
}
36