JsonStream   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 14 3
1
<?php
2
3
namespace Shutterstock\Api;
4
5
use GuzzleHttp\Psr7\StreamDecoratorTrait;
6
use JsonSerializable;
7
use Psr\Http\Message\StreamInterface;
8
use RuntimeException;
9
10
class JsonStream implements StreamInterface, JsonSerializable
11
{
12
13
    use StreamDecoratorTrait;
14
15
    public function jsonSerialize()
16
    {
17
        $contents = (string) $this->getContents();
18
        if ($contents === '') {
19
            return null;
20
        }
21
22
        $decodedContents = json_decode($contents, true);
23
        if (json_last_error() !== JSON_ERROR_NONE) {
24
            throw new RuntimeException('Error trying to decode response: ' . json_last_error_msg());
25
        }
26
27
        return $decodedContents;
28
    }
29
}
30