Passed
Push — master ( 2fbd23...3c6f7d )
by Aleksei
01:50
created

RedirectBucket::withLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace roxblnfk\SmartStream\Data;
6
7
use Yiisoft\Http\Header;
8
9
class RedirectBucket extends DataBucket
10
{
11
    protected ?string $location = null;
12
13
    protected const IS_CONVERTABLE = false;
14
15
    public function __construct(string $location, int $code = 302)
16
    {
17
        parent::__construct('');
18
        $this->setLocation($location);
19
        $this->setStatus($code);
20
    }
21
    public function getLocation(): ?string
22
    {
23
        return $this->location;
24
    }
25
    public function withLocation(?string $location): self
26
    {
27
        $clone = clone $this;
28
        $clone->setLocation($location);
29
        return $clone;
30
    }
31
32
    protected function setLocation(?string $location): void
33
    {
34
        $this->location = $location;
35
        $this->setHeader(Header::LOCATION, $this->location);
0 ignored issues
show
Bug introduced by
It seems like $this->location can also be of type null; however, parameter $value of roxblnfk\SmartStream\Data\DataBucket::setHeader() does only seem to accept string, 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

35
        $this->setHeader(Header::LOCATION, /** @scrutinizer ignore-type */ $this->location);
Loading history...
36
    }
37
}
38