Passed
Push — master ( 8d8aff...14bf48 )
by Aleksei
07:24
created

DataBucket::withFormat()   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 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace roxblnfk\SmartStream\Data;
4
5
class DataBucket
6
{
7
    /** @var mixed */
8
    protected $data;
9
    protected ?int $code = null;
10
    /** @var string[] */
11
    protected array $headers = [];
12
    protected ?string $format = null;
13
    protected array $params = [];
14
15
    protected const IS_FORMATABLE = true;
16
17
    public function __construct($data, string $format = null, array $params = [])
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

17
    public function __construct($data, string $format = null, /** @scrutinizer ignore-unused */ array $params = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        $this->data = $data;
20
        $this->format = $format;
21
    }
22
    public function getCode(): ?int
23
    {
24
        return $this->code;
25
    }
26
    public function getHeaders(): array
27
    {
28
        return $this->headers;
29
    }
30
    public function getFormat(): ?string
31
    {
32
        return $this->format;
33
    }
34
    public function getParams(): array
35
    {
36
        return $this->params;
37
    }
38
    public function getData()
39
    {
40
        return $this->data;
41
    }
42
    public function isFormatable(): bool
43
    {
44
        return static::IS_FORMATABLE;
45
    }
46
    public function hasFormat(): bool
47
    {
48
        return static::IS_FORMATABLE && $this->format !== null;
49
    }
50
51
    public function setCode(?int $code = 200): self
52
    {
53
        $this->code = $code;
54
        return $this;
55
    }
56
    public function setHeaders(array $headers = []): self
57
    {
58
        $this->headers = $headers;
59
        return $this;
60
    }
61
    public function addHeaders(array $headers = []): self
62
    {
63
        $this->headers = [...$this->headers, ...$headers];
0 ignored issues
show
Documentation Bug introduced by
It seems like array($this->headers, $headers) of type array<integer,array> is incompatible with the declared type string[] of property $headers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
        return $this;
65
    }
66
    public function setHeader(string $name, string $value): self
67
    {
68
        $this->headers[$name] = $value;
69
        return $this;
70
    }
71
    public function withFormat(?string $format, array $params = null): self
72
    {
73
        $clone = clone $this;
74
        $clone->setFormat($format, $params);
75
        return $clone;
76
    }
77
    public function setFormat(?string $format, array $params = null): self
78
    {
79
        $this->format = $format;
80
        if ($params !== null) {
81
            $this->params = $params;
82
        }
83
        return $this;
84
    }
85
}
86