Passed
Pull Request — 1.x (#99)
by Akihito
10:41
created

ResourceState::visit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
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
    /**
29
     * @param mixed $body
30
     */
31
    public static function create(ResourceObject $ro, $body, ?string $view): self
32
    {
33
        $state = new self();
34
        $state->code = $ro->code;
35
        $state->uri = $ro->uri;
36
        $state->headers = $ro->headers;
37
        $state->view = $view;
38
        $state->body = $body;
39
40
        return $state;
41
    }
42
43
    public function visit(ResourceObject $ro): void
44
    {
45
        $ro->uri = $this->uri;
46
        $ro->code = $this->code;
47
        $ro->headers = $this->headers;
48
        $ro->body = $this->body;
49
        $ro->view = $this->view;
50
    }
51
}
52