TBody   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A withBody() 0 4 1
A getBody() 0 6 2
1
<?php
2
3
namespace kalanis\RemoteRequestPsr\Traits;
4
5
6
use Psr\Http\Message\MessageInterface;
7
use Psr\Http\Message\StreamInterface;
8
use RuntimeException;
9
10
11
/**
12
 * Trait TBody
13
 * @package kalanis\RemoteRequestPsr\Traits
14
 * Note: Contrary the PSR requirements this class does not offer immutability
15
 * That's because you need to change request properties before you set them to RemoteRequest
16
 */
17
trait TBody
18
{
19
    protected ?StreamInterface $body = null;
20
21 6
    public function getBody(): StreamInterface
22
    {
23 6
        if (empty($this->body)) {
24 1
            throw new RuntimeException('You must set the body first!');
25
        }
26 5
        return $this->body;
27
    }
28
29 5
    public function withBody(StreamInterface $body): MessageInterface
30
    {
31 5
        $this->body = $body;
32 5
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type kalanis\RemoteRequestPsr\Traits\TBody which is incompatible with the type-hinted return Psr\Http\Message\MessageInterface.
Loading history...
33
    }
34
}
35