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

Psr7Message::getIterator()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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