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->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
![]() |
|||||
40 | } |
||||
41 | 7 | return $fp; |
|||
42 | } |
||||
43 | } |
||||
44 |