Completed
Push — v0.7 ( 21297d...0d3226 )
by Nate
02:43
created

ReaderContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
c 0
b 0
f 0
dl 0
loc 56
ccs 10
cts 10
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A usesExistingObject() 0 3 1
A getPayload() 0 3 1
A setPayload() 0 5 1
A setUsesExistingObject() 0 5 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
declare(strict_types=1);
7
8
namespace Tebru\Gson\Context;
9
10
/**
11
 * Class JsonReaderContext
12
 *
13
 * Runtime context that can be used during reading
14
 *
15
 * @author Nate Brunette <[email protected]>
16
 */
17
class ReaderContext extends Context
18
{
19
    /**
20
     * True if we're reading into an existing object
21
     *
22
     * @var bool
23
     */
24
    private $usesExistingObject = false;
25
26
    /**
27
     * The initial json_decode'd payload
28
     *
29
     * @var mixed
30
     */
31
    private $payload;
32
33
    /**
34
     * If we're reading into an existing object
35
     *
36
     * @return bool
37
     */
38 4
    public function usesExistingObject(): bool
39
    {
40 4
        return $this->usesExistingObject;
41
    }
42
43
    /**
44
     * When deserializing into an existing object
45
     *
46
     * @param bool $usesExistingObject
47
     * @return ReaderContext
48
     */
49 4
    public function setUsesExistingObject(bool $usesExistingObject): ReaderContext
50
    {
51 4
        $this->usesExistingObject = $usesExistingObject;
52
53 4
        return $this;
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59 1
    public function getPayload()
60
    {
61 1
        return $this->payload;
62
    }
63
64
    /**
65
     * @param mixed $payload
66
     * @return ReaderContext
67
     */
68 4
    public function setPayload($payload): ReaderContext
69
    {
70 4
        $this->payload = $payload;
71
72 4
        return $this;
73
    }
74
}
75