Passed
Pull Request — master (#1554)
by
unknown
02:54
created

DeserializationContext   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 8
eloc 13
dl 0
loc 51
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A increaseDepth() 0 3 1
A getDepth() 0 3 1
A getDirection() 0 3 1
A decreaseDepth() 0 7 2
A create() 0 3 1
A getRequireAllRequiredProperties() 0 3 1
A setRequireAllRequiredProperties() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer;
6
7
use JMS\Serializer\Exception\LogicException;
8
9
class DeserializationContext extends Context
10
{
11
    /**
12
     * @var int
13 5
     */
14
    private $depth = 0;
15 5
16
    /**
17
     * @var bool
18 1
     */
19
    private $requireAllRequiredProperties = false;
20 1
21
    public static function create(): self
22
    {
23 6
        return new self();
24
    }
25 6
26
    public function getDirection(): int
27
    {
28 80
        return GraphNavigatorInterface::DIRECTION_DESERIALIZATION;
29
    }
30 80
31 80
    public function getDepth(): int
32
    {
33 77
        return $this->depth;
34
    }
35 77
36
    public function increaseDepth(): void
37
    {
38
        $this->depth += 1;
39 77
    }
40 77
41
    public function decreaseDepth(): void
42
    {
43
        if ($this->depth <= 0) {
44
            throw new LogicException('Depth cannot be smaller than zero.');
45
        }
46
47
        $this->depth -= 1;
48
    }
49
50
    public function setRequireAllRequiredProperties(bool $require): self
51
    {
52
        $this->requireAllRequiredProperties = $require;
53
54
        return $this;
55
    }
56
57
    public function getRequireAllRequiredProperties(): bool
58
    {
59
        return $this->requireAllRequiredProperties;
60
    }
61
}
62