Excel::makeFileNameExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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\Services;
11
12
use Bugloos\ExportBundle\Contracts\ExporterInterface;
13
use Bugloos\ExportBundle\Factory\ResponseFactory;
14
use Bugloos\ExportBundle\Writer;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Mojtaba Gheytasi <[email protected] | [email protected]>
19
 */
20
class Excel implements ExporterInterface
21
{
22
    public const XLSX = 'Xlsx';
23
24
    public const CSV = 'Csv';
25
26
    public function download(
27
        $exportClass,
28
        string $fileName,
29
        string $writerType = null,
30
        array $headers = []
31
    ): Response {
32
33
        $output = (new Writer())->export($exportClass, $writerType);
0 ignored issues
show
Bug introduced by
It seems like $writerType can also be of type null; however, parameter $writerType of Bugloos\ExportBundle\Writer::export() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $output = (new Writer())->export($exportClass, /** @scrutinizer ignore-type */ $writerType);
Loading history...
34
35
        $fileName = $fileName.'.'.$this->makeFileNameExtension($writerType);
36
37
        return (new ResponseFactory())->makeResponse($writerType, $output, $fileName);
0 ignored issues
show
Bug introduced by
It seems like $writerType can also be of type null; however, parameter $exportFormat of Bugloos\ExportBundle\Fac...Factory::makeResponse() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return (new ResponseFactory())->makeResponse(/** @scrutinizer ignore-type */ $writerType, $output, $fileName);
Loading history...
38
    }
39
40
    public function makeFileNameExtension($writerType): string
41
    {
42
        return lcfirst($writerType);
43
    }
44
}
45