Passed
Branch feature/first-release (43e0cc)
by Andrea Marco
10:48
created

Psr7Message   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 30
ccs 2
cts 6
cp 0.3333
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A calculateSize() 0 3 1
A matches() 0 3 2
1
<?php
2
3
namespace Cerbero\JsonParser\Sources;
4
5
use Psr\Http\Message\MessageInterface;
6
use Psr\Http\Message\RequestInterface;
7
use Traversable;
8
9
/**
10
 * The PSR-7 message source.
11
 *
12
 * @property-read MessageInterface $source
13
 */
14
class Psr7Message extends Source
15
{
16
    /**
17
     * Retrieve the JSON fragments
18
     *
19
     * @return Traversable<int, string>
20
     */
21
    public function getIterator(): Traversable
22
    {
23
        return new Psr7Stream($this->source->getBody(), $this->config);
24
    }
25
26
    /**
27
     * Determine whether the JSON source can be handled
28
     *
29
     * @return bool
30
     */
31 1
    public function matches(): bool
32
    {
33 1
        return $this->source instanceof MessageInterface && !$this->source instanceof RequestInterface;
34
    }
35
36
    /**
37
     * Retrieve the calculated size of the JSON source
38
     *
39
     * @return int|null
40
     */
41
    protected function calculateSize(): ?int
42
    {
43
        return $this->source->getBody()->getSize();
44
    }
45
}
46