Passed
Pull Request — master (#44)
by Anatoly
34:56
created

MultiResponse::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-client-curl/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-client-curl
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Client\Curl;
15
16
use InvalidArgumentException;
17
use LogicException;
18
use Psr\Http\Message\MessageInterface;
19
use Psr\Http\Message\ResponseInterface;
20
use Psr\Http\Message\StreamInterface;
21
22
use function current;
23
24
/**
25
 * @since 2.0.0
26
 */
27
final class MultiResponse implements ResponseInterface
28
{
29
    /**
30
     * @var non-empty-array<array-key, ResponseInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<array-key, ResponseInterface> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<array-key, ResponseInterface>.
Loading history...
31
     */
32
    private array $responses;
33
34
    /**
35
     * @throws InvalidArgumentException
36
     */
37 1
    public function __construct(ResponseInterface ...$responses)
38
    {
39 1
        if ($responses === []) {
40
            throw new InvalidArgumentException('At least one response is expected.');
41
        }
42
43 1
        $this->responses = $responses;
44
    }
45
46
    /**
47
     * @return non-empty-array<array-key, ResponseInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<array-key, ResponseInterface> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<array-key, ResponseInterface>.
Loading history...
48
     */
49 1
    public function getResponses(): array
50
    {
51 1
        return $this->responses;
52
    }
53
54
    public function getProtocolVersion(): string
55
    {
56
        return current($this->responses)->getProtocolVersion();
57
    }
58
59
    public function withProtocolVersion($version): MessageInterface
60
    {
61
        throw new LogicException('Not implemented.');
62
    }
63
64
    public function getHeaders(): array
65
    {
66
        return current($this->responses)->getHeaders();
67
    }
68
69
    public function hasHeader($name): bool
70
    {
71
        return current($this->responses)->hasHeader($name);
72
    }
73
74
    public function getHeader($name): array
75
    {
76
        return current($this->responses)->getHeader($name);
77
    }
78
79
    public function getHeaderLine($name): string
80
    {
81
        return current($this->responses)->getHeaderLine($name);
82
    }
83
84
    public function withHeader($name, $value): MessageInterface
85
    {
86
        throw new LogicException('Not implemented.');
87
    }
88
89
    public function withAddedHeader($name, $value): MessageInterface
90
    {
91
        throw new LogicException('Not implemented.');
92
    }
93
94
    public function withoutHeader($name): MessageInterface
95
    {
96
        throw new LogicException('Not implemented.');
97
    }
98
99
    public function getBody(): StreamInterface
100
    {
101
        return current($this->responses)->getBody();
102
    }
103
104
    public function withBody(StreamInterface $body): MessageInterface
105
    {
106
        throw new LogicException('Not implemented.');
107
    }
108
109
    public function getStatusCode(): int
110
    {
111
        return current($this->responses)->getStatusCode();
112
    }
113
114
    public function withStatus($code, $reasonPhrase = ''): ResponseInterface
115
    {
116
        throw new LogicException('Not implemented.');
117
    }
118
119
    public function getReasonPhrase(): string
120
    {
121
        return current($this->responses)->getReasonPhrase();
122
    }
123
}
124