Passed
Push — master ( 3d41b9...946dd7 )
by Nate
51s queued 24s
created

JsonDecodeException::getPayload()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
declare(strict_types=1);
8
9
namespace Tebru\Gson\Exception;
10
11
/**
12
 * Class JsonDecodeException
13
 *
14
 * Thrown when there is an issue decoding the json string
15
 *
16
 * @author Nate Brunette <[email protected]>
17
 */
18
class JsonDecodeException extends JsonParseException
19
{
20
    /**
21
     * The json payload that failed to decode
22
     *
23
     * @var mixed
24
     */
25
    private $payload;
26
27
    /**
28
     * Constructor
29
     *
30
     * @param string $lastErrorMessage The json error message
31
     * @param int $code The json error code
32
     * @param mixed $payload The payload that failed to decode
33
     */
34 1
    public function __construct(string $lastErrorMessage, int $code, $payload)
35
    {
36 1
        $message = \sprintf('Could not decode json, the error message was: "%s"', $lastErrorMessage);
37
38 1
        parent::__construct($message, $code);
39
40 1
        $this->payload = $payload;
41 1
    }
42
43
    /**
44
     * Get the json payload that failed to decode
45
     *
46
     * @return mixed
47
     */
48 1
    public function getPayload()
49
    {
50 1
        return $this->payload;
51
    }
52
}
53