GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0b01a7...3b0906 )
by Odiseo
08:33
created

CsvResponse::getFilename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Odiseo\SyliusReportPlugin\Response;
4
5
use Symfony\Component\HttpFoundation\Response;
6
7
class CsvResponse extends Response
8
{
9
    protected $data;
10
    protected $filename = 'export.csv';
11
12
    public function __construct($data = array(), $status = 200, $headers = array())
13
    {
14
        parent::__construct('', $status, $headers);
15
        $this->setData($data);
16
    }
17
18
    public function setData(array $data)
19
    {
20
        $output = fopen('php://temp', 'r+');
21
        foreach ($data as $row) {
22
            fputcsv($output, $row);
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type false; however, parameter $handle of fputcsv() does only seem to accept resource, 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

22
            fputcsv(/** @scrutinizer ignore-type */ $output, $row);
Loading history...
23
        }
24
        rewind($output);
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type false; however, parameter $handle of rewind() does only seem to accept resource, 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

24
        rewind(/** @scrutinizer ignore-type */ $output);
Loading history...
25
        $this->data = '';
26
        while ($line = fgets($output)) {
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type false; however, parameter $handle of fgets() does only seem to accept resource, 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

26
        while ($line = fgets(/** @scrutinizer ignore-type */ $output)) {
Loading history...
27
            $this->data .= $line;
28
        }
29
        $this->data .= fgets($output);
30
        return $this->update();
31
    }
32
33
    public function getFilename()
34
    {
35
        return $this->filename;
36
    }
37
38
    public function setFilename($filename)
39
    {
40
        $this->filename = $filename;
41
        return $this->update();
42
    }
43
44
    protected function update()
45
    {
46
        $this->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $this->filename));
47
        if (!$this->headers->has('Content-Type')) {
48
            $this->headers->set('Content-Type', 'text/csv');
49
        }
50
51
        return $this->setContent($this->data);
52
    }
53
}