ResponseUtilsTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateImageResponse() 0 3 1
A generateBinaryResponse() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Shlinkio\Shlink\Common\Response;
6
7
use Fig\Http\Message\StatusCodeInterface as StatusCode;
8
use finfo;
9
use Laminas\Diactoros\Response;
10
use Laminas\Diactoros\Stream;
11
use Laminas\Stdlib\ArrayUtils;
12
use Psr\Http\Message\ResponseInterface;
13
14
use const FILEINFO_MIME;
15
16
trait ResponseUtilsTrait
17
{
18
    /**
19
     * @deprecated Use generateBinaryResponse method instead
20
     */
21 2
    private function generateImageResponse(string $imagePath): ResponseInterface
22
    {
23 2
        return $this->generateBinaryResponse($imagePath);
24
    }
25
26 3
    private function generateBinaryResponse(string $path, array $extraHeaders = []): ResponseInterface
27
    {
28 3
        $body = new Stream($path);
29 3
        return new Response($body, StatusCode::STATUS_OK, ArrayUtils::merge([
30 3
            'Content-Type' => (new finfo(FILEINFO_MIME))->file($path),
31 3
            'Content-Length' => (string) $body->getSize(),
32
        ], $extraHeaders));
33
    }
34
}
35