Passed
Pull Request — 1.x (#334)
by Akihito
11:25
created

ResourceCompleteContext   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 15
c 1
b 0
f 1
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\SemanticLog;
6
7
use BEAR\Resource\ResourceObject;
8
use Koriym\SemanticLogger\AbstractContext;
9
10
final class ResourceCompleteContext extends AbstractContext
11
{
12
    /** @psalm-suppress InvalidClassConstantType */
13
    public const TYPE = 'bear_resource_complete';
14
15
    /** @psalm-suppress InvalidClassConstantType */
16
    public const SCHEMA_URL = 'https://bearsunday.github.io/BEAR.Resource/schemas/bear-resource-complete.json';
17
18
    public readonly string $uri;
19
    public readonly int $code;
20
21
    /** @var array<string, mixed> */
22
    public readonly array $headers;
23
    public readonly mixed $body;
24
    public readonly mixed $view;
25
26
    public function __construct(
27
        ResourceObject $resource,
28
        public readonly string $method,
29
    ) {
30
        // Trigger rendering to get view
31
        $resourceString = (string) $resource;
32
        unset($resourceString);
33
34
        $this->uri = (string) $resource->uri;
0 ignored issues
show
Bug introduced by
The property uri is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
35
        $this->code = $resource->code;
0 ignored issues
show
Bug introduced by
The property code is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
36
        $this->headers = $resource->headers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $resource->headers of type BEAR\Resource\Headers is incompatible with the declared type array<string,mixed> 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...
Bug introduced by
The property headers is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
37
        $this->body = $resource->body;
0 ignored issues
show
Bug introduced by
The property body is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
38
        $this->view = $resource->view;
0 ignored issues
show
Bug introduced by
The property view is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
39
    }
40
}
41