JsonPayload::buildParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
1
<?php
2
3
namespace ComradeReader\Collection\Parameters;
4
5
/**
6
 * @package ComradeReader\Collection\Parameters
7
 */
8
class JsonPayload implements ParametersBagInterface
9
{
10
    /**
11
     * @var array $json
12
     */
13
    private $payload;
14
15
    /**
16
     * @param string $jsonPayload
17
     * @return ParametersBagInterface
18
     */
19
    public function set($jsonPayload): ParametersBagInterface
20
    {
21
        $this->payload = json_decode($jsonPayload, true);
0 ignored issues
show
Documentation Bug introduced by
It seems like json_decode($jsonPayload, true) of type * is incompatible with the declared type array of property $payload.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
22
23
        if (json_last_error() !== JSON_ERROR_NONE) {
24
            throw new \InvalidARgumentException('Invalid JSON payload, cannot decode');
25
        }
26
27
        return $this;
28
    }
29
30
    /**
31
     * @param string $url
32
     * @param string $method
33
     * @param array $parameters
34
     *
35
     * @return array
36
     */
37
    public function buildParameters(string $url, string $method, array $parameters)
38
    {
39
        return [
40
            'json' => $this->payload,
41
        ];
42
    }
43
}