Completed
Push — master ( f459d5...0fcc77 )
by Hannes
03:16
created

SymfonyResponse   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 66.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 30
ccs 6
cts 9
cp 0.6667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fileDownload() 0 21 3
1
<?php
2
namespace Madewithlove\Export\Http;
3
4
use Psr\Http\Message\StreamInterface;
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
7
use Symfony\Component\HttpFoundation\StreamedResponse;
8
9
trait SymfonyResponse
10
{
11
    /**
12
     * @param string $content
13
     * @param string $filename
14
     *
15
     * @return \Symfony\Component\HttpFoundation\Response
16
     */
17 3
    private function fileDownload($content, $filename)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
18
    {
19 3
        if ($content instanceof StreamInterface) {
20
            $response = new StreamedResponse();
21
22
            $response->setCallback(function () use ($content) {
23
                $content->rewind();
24
25
                while (! $content->eof()) {
26
                    echo $content->read(8192);
27
                }
28
            });
29
        } else {
30 3
            $response = new Response($content);
31
        }
32
33 3
        $disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
34 3
        $response->headers->set('Content-Disposition', $disposition);
35
36 3
        return $response;
37
    }
38
}
39