SnappyResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
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