XSendFileResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 2
eloc 9
c 3
b 1
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Http;
6
7
class XSendFileResponse extends Response
8
{
9
    public function __construct(
10
        string $filePath,
11
        string $outputFilename,
12
        string $contentType = 'application/octet-stream'
13
    ) {
14
        if (!\is_readable($filePath)) {
15
            throw new \WebServCo\Framework\Exceptions\NotFoundException('File not found.');
16
        }
17
18
        parent::__construct(
19
            '', // content
20
            200, // statusCode
21
            [
22
                'Content-Disposition' => [\sprintf('attachment; filename="%s"', $outputFilename)],
23
                'Content-Type' => [$contentType],
24
                'X-Sendfile' => [$filePath],
25
            ], // headers
26
        );
27
    }
28
}
29