MessageTrait::getProtocolVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Http;
14
15
use Psr\Http\Message\StreamInterface;
16
17
trait MessageTrait
18
{
19
    protected string $protocolVersion = '1.1';
20
    protected StreamInterface $stream;
21
22
    public function getProtocolVersion(): string
23
    {
24
        return $this->protocolVersion;
25
    }
26
27
    public function withProtocolVersion($version): static
28 8
    {
29
        if (false === \in_array($version, ['1.0', '1.1', '2'], true)) {
30 8
            throw new \InvalidArgumentException('Unsupported HTTP protocol version ' . $version);
31
        }
32
        $instance                  = clone $this;
33 5
        $instance->protocolVersion = $version;
34
        return $instance;
35 5
    }
36 1
37
    public function getBody(): StreamInterface
38
    {
39 4
        return $this->stream ?? create_stream(null);
40 4
    }
41
42 4
    public function withBody(StreamInterface $body): static
43
    {
44
        $instance         = clone $this;
45 43
        $instance->stream = $body;
46
        return $instance;
47 43
    }
48
49
    public function __set($name, $value)
50 15
    {
51
        /* NOOP */
52 15
    }
53
}
54