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

MultiRequest   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 12.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 20
eloc 22
c 1
b 0
f 0
dl 0
loc 110
ccs 5
cts 40
cp 0.125
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getHeaders() 0 3 1
A getHeaderLine() 0 3 1
A getUri() 0 3 1
A getMethod() 0 3 1
A withoutHeader() 0 3 1
A withUri() 0 3 1
A withProtocolVersion() 0 3 1
A withRequestTarget() 0 3 1
A getBody() 0 3 1
A __construct() 0 7 2
A getRequests() 0 3 1
A getRequestTarget() 0 3 1
A withBody() 0 3 1
A getHeader() 0 3 1
A withAddedHeader() 0 3 1
A withMethod() 0 3 1
A hasHeader() 0 3 1
A getProtocolVersion() 0 3 1
A withHeader() 0 3 1
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\RequestInterface;
20
use Psr\Http\Message\StreamInterface;
21
use Psr\Http\Message\UriInterface;
22
23
use function current;
24
25
/**
26
 * @since 2.0.0
27
 */
28
final class MultiRequest implements RequestInterface
29
{
30
    /**
31
     * @var non-empty-array<array-key, RequestInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<array-key, RequestInterface> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<array-key, RequestInterface>.
Loading history...
32
     */
33
    private array $requests;
34
35
    /**
36
     * @throws InvalidArgumentException
37
     */
38 1
    public function __construct(RequestInterface ...$requests)
39
    {
40 1
        if ($requests === []) {
41
            throw new InvalidArgumentException('At least one request is expected.');
42
        }
43
44 1
        $this->requests = $requests;
45
    }
46
47
    /**
48
     * @return non-empty-array<array-key, RequestInterface>
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<array-key, RequestInterface> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<array-key, RequestInterface>.
Loading history...
49
     */
50 1
    public function getRequests(): array
51
    {
52 1
        return $this->requests;
53
    }
54
55
    public function getProtocolVersion(): string
56
    {
57
        return current($this->requests)->getProtocolVersion();
58
    }
59
60
    public function withProtocolVersion($version): static
61
    {
62
        throw new LogicException('Not implemented.');
63
    }
64
65
    public function getHeaders(): array
66
    {
67
        return current($this->requests)->getHeaders();
68
    }
69
70
    public function hasHeader($name): bool
71
    {
72
        return current($this->requests)->hasHeader($name);
73
    }
74
75
    public function getHeader($name): array
76
    {
77
        return current($this->requests)->getHeader($name);
78
    }
79
80
    public function getHeaderLine($name): string
81
    {
82
        return current($this->requests)->getHeaderLine($name);
83
    }
84
85
    public function withHeader($name, $value): MessageInterface
86
    {
87
        throw new LogicException('Not implemented.');
88
    }
89
90
    public function withAddedHeader($name, $value): MessageInterface
91
    {
92
        throw new LogicException('Not implemented.');
93
    }
94
95
    public function withoutHeader($name): MessageInterface
96
    {
97
        throw new LogicException('Not implemented.');
98
    }
99
100
    public function getBody(): StreamInterface
101
    {
102
        return current($this->requests)->getBody();
103
    }
104
105
    public function withBody(StreamInterface $body): MessageInterface
106
    {
107
        throw new LogicException('Not implemented.');
108
    }
109
110
    public function getRequestTarget(): string
111
    {
112
        return current($this->requests)->getRequestTarget();
113
    }
114
115
    public function withRequestTarget($requestTarget): RequestInterface
116
    {
117
        throw new LogicException('Not implemented.');
118
    }
119
120
    public function getMethod(): string
121
    {
122
        return current($this->requests)->getMethod();
123
    }
124
125
    public function withMethod($method): RequestInterface
126
    {
127
        throw new LogicException('Not implemented.');
128
    }
129
130
    public function getUri(): UriInterface
131
    {
132
        return current($this->requests)->getUri();
133
    }
134
135
    public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
136
    {
137
        throw new LogicException('Not implemented.');
138
    }
139
}
140