Completed
Push — 1.x ( e5fddc...35ac6e )
by Akihito
25s queued 17s
created

HttpResourceObject::__get()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 10
nc 5
nop 1
dl 0
loc 22
rs 9.6111
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A HttpResourceObject::__toString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource;
6
7
use function strtoupper;
8
9
/**
10
 * @method HttpResourceObject get(AbstractUri|string $uri, array $params = [])
11
 * @method HttpResourceObject head(AbstractUri|string $uri, array $params = [])
12
 * @method HttpResourceObject put(AbstractUri|string $uri, array $params = [])
13
 * @method HttpResourceObject post(AbstractUri|string $uri, array $params = [])
14
 * @method HttpResourceObject patch(AbstractUri|string $uri, array $params = [])
15
 * @method HttpResourceObject delete(AbstractUri|string $uri, array $params = [])
16
 * @property-read string                $code
17
 * @property-read array<string, string> $headers
18
 * @property-read array<string, string> $body
19
 * @property-read string                $view
20
 */
21
final class HttpResourceObject extends ResourceObject implements InvokeRequestInterface
22
{
23
    public function __construct(
24
        private HttpRequestInterface $httpRequest,
25
    ) {
26
    }
27
28
    /** @SuppressWarnings(PHPMD.CamelCaseMethodName) */
29
    public function _invokeRequest(InvokerInterface $invoker, AbstractRequest $request): ResourceObject
30
    {
31
        unset($invoker);
32
33
        return $this->request($request);
34
    }
35
36
    public function request(AbstractRequest $request): ResourceObject
37
    {
38
        $uri = $request->resourceObject->uri;
39
        $method = strtoupper($uri->method);
40
        [
41
            'code' => $this->code,
0 ignored issues
show
Bug introduced by
The property code is declared read-only in BEAR\Resource\HttpResourceObject.
Loading history...
42
            'headers' => $this->headers,
0 ignored issues
show
Bug introduced by
The property headers is declared read-only in BEAR\Resource\HttpResourceObject.
Loading history...
43
            'body' => $this->body,
0 ignored issues
show
Bug introduced by
The property body is declared read-only in BEAR\Resource\HttpResourceObject.
Loading history...
44
            'view' => $this->view,
0 ignored issues
show
Bug introduced by
The property view is declared read-only in BEAR\Resource\HttpResourceObject.
Loading history...
45
        ] =  $this->httpRequest->request($method, (string) $uri, $uri->query);
46
47
        return $this;
48
    }
49
50
    public function __toString(): string
51
    {
52
        return $this->view;
53
    }
54
}
55