MediaBuilder::setRange()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Responders;
12
13
use GuzzleHttp\Psr7\Stream;
14
use GuzzleHttp\Psr7\LimitStream;
15
use Psr\Http\Message\StreamInterface;
16
17
class MediaBuilder extends ResponseBuilder
18
{
19
    private ?int $start;
20
    private ?int $end;
21
    private ?int $length;
22
23 5
    public function setRange($start, $end, $length)
24
    {
25 5
        $this->start = $start;
26 5
        $this->end = $end;
27 5
        $this->length = $length;
28
    }
29
30 12
    public function setContentType(string $contentType): void
31
    {
32 12
        $this->contentType = $contentType;
33
    }
34
35 10
    public function getBody(): StreamInterface
36
    {
37 10
        $fp = new Stream(fopen($this->template, 'r'));
38 10
        if (isset($this->start) && $this->start>0) {
39 3
            return new LimitStream($fp, $this->length, $this->start);
0 ignored issues
show
Bug introduced by
It seems like $this->length can also be of type null; however, parameter $limit of GuzzleHttp\Psr7\LimitStream::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            return new LimitStream($fp, /** @scrutinizer ignore-type */ $this->length, $this->start);
Loading history...
Bug introduced by
It seems like $this->start can also be of type null; however, parameter $offset of GuzzleHttp\Psr7\LimitStream::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
            return new LimitStream($fp, $this->length, /** @scrutinizer ignore-type */ $this->start);
Loading history...
40
        }
41 7
        return $fp;
42
    }
43
}
44