ResourceState   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 36
rs 10
c 3
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 10 1
A visit() 0 7 1
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