Passed
Push — master ( 02d42a...eb71ce )
by Albin
59s
created

SnappyResponse::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 6
1
<?php
2
3
namespace Knp\Bundle\SnappyBundle\Snappy\Response;
4
5
use Symfony\Component\HttpFoundation\Response as Base;
6
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
7
8
class SnappyResponse extends Base
9
{
10
    public function __construct($content, $fileName, $contentType, $contentDisposition = 'attachment', $status = 200, $headers = [])
11
    {
12
        $contentDispositionDirectives = [ResponseHeaderBag::DISPOSITION_INLINE, ResponseHeaderBag::DISPOSITION_ATTACHMENT];
13
        if (!in_array($contentDisposition, $contentDispositionDirectives)) {
14
            throw new \InvalidArgumentException(sprintf('Expected one of the following directives: "%s", but "%s" given.', implode('", "', $contentDispositionDirectives), $contentDisposition));
15
        }
16
17
        parent::__construct($content, $status, $headers);
18
        $this->headers->add(['Content-Type' => $contentType]);
19
        $this->headers->add(['Content-Disposition' => $this->headers->makeDisposition($contentDisposition, $fileName)]);
20
    }
21
}
22