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

ResourceCompleteContext   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 16
c 1
b 0
f 1
dl 0
loc 30
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
use function strtoupper;
11
12
/** @deprecated Use BEAR\Resource\SemanticLog\Profile\Compact\CompleteContext instead */
13
final class ResourceCompleteContext extends AbstractContext
14
{
15
    /** @psalm-suppress InvalidClassConstantType */
16
    public const TYPE = 'bear_resource_complete';
17
18
    /** @psalm-suppress InvalidClassConstantType */
19
    public const SCHEMA_URL = 'https://bearsunday.github.io/BEAR.Resource/schemas/bear-resource-complete.json';
20
21
    public readonly string $uri;
22
    public readonly string $method;
23
    public readonly int $code;
24
25
    /** @var array<string, string> */
26
    public readonly array $headers;
27
    public readonly mixed $body;
28
    public readonly string $view;
29
30
    public function __construct(ResourceObject $resource, string $method)
31
    {
32
        // Trigger rendering to get view
33
        $resourceString = (string) $resource;
34
        unset($resourceString);
35
36
        $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...
37
        $this->method = strtoupper($method);
0 ignored issues
show
Bug introduced by
The property method is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
38
        $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...
39
        $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,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...
Bug introduced by
The property headers is declared read-only in BEAR\Resource\SemanticLog\ResourceCompleteContext.
Loading history...
40
        $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...
41
        /** @psalm-suppress PossiblyNullPropertyAssignmentValue */
42
        $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...
43
    }
44
}
45