Passed
Branch feature/first-release (f081ea)
by Andrea Marco
10:18
created

LaravelClientResponse::calculateSize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\JsonParser\Sources;
4
5
use Illuminate\Http\Client\Response;
6
use Traversable;
7
8
/**
9
 * The Laravel client response source.
10
 *
11
 * @property-read Response $source
12
 */
13
class LaravelClientResponse extends Source
14
{
15
    /**
16
     * Retrieve the JSON fragments
17
     *
18
     * @return Traversable<int, string>
19
     */
20 1
    public function getIterator(): Traversable
21
    {
22 1
        return new Psr7Message($this->source->toPsrResponse(), $this->config);
23
    }
24
25
    /**
26
     * Determine whether the JSON source can be handled
27
     *
28
     * @return bool
29
     */
30 2
    public function matches(): bool
31
    {
32 2
        return $this->source instanceof Response;
33
    }
34
35
    /**
36
     * Retrieve the calculated size of the JSON source
37
     *
38
     * @return int|null
39
     */
40 1
    protected function calculateSize(): ?int
41
    {
42 1
        return $this->source->toPsrResponse()->getBody()->getSize();
43
    }
44
}
45