ResourceState::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use BEAR\Resource\AbstractUri;
8
use BEAR\Resource\ResourceObject;
9
10
/** @psalm-suppress MissingConstructor */
11
final class ResourceState
12
{
13
    /** @var int  */
14
    public $code = 200;
15
16
    /** @var AbstractUri */
17
    public $uri;
18
19
    /** @var array<string, string> */
20
    public $headers = [];
21
22
    /** @var mixed  */
23
    public $body;
24
25
    /** @var ?string */
26
    public $view;
27
28
    public static function create(ResourceObject $ro, mixed $body, string|null $view): self
29
    {
30
        $state = new self();
31
        $state->code = $ro->code;
32
        $state->uri = $ro->uri;
33
        $state->headers = $ro->headers;
34
        $state->view = $view;
35
        $state->body = $body;
36
37
        return $state;
38
    }
39
40
    public function visit(ResourceObject $ro): void
41
    {
42
        $ro->uri = $this->uri;
43
        $ro->code = $this->code;
44
        $ro->headers = $this->headers;
45
        $ro->body = $this->body;
46
        $ro->view = $this->view;
47
    }
48
}
49