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

RedirectBucket   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLocation() 0 4 1
A __construct() 0 5 1
A getLocation() 0 3 1
A withLocation() 0 5 1
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