1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer;
6
7use JMS\Serializer\Exception\LogicException;
8
9class DeserializationContext extends Context
10{
11    /**
12     * @var int
13     */
14    private $depth = 0;
15
16    public static function create(): self
17    {
18        return new self();
19    }
20
21    public function getDirection(): int
22    {
23        return GraphNavigatorInterface::DIRECTION_DESERIALIZATION;
24    }
25
26    public function getDepth(): int
27    {
28        return $this->depth;
29    }
30
31    public function increaseDepth(): void
32    {
33        $this->depth += 1;
34    }
35
36    public function decreaseDepth(): void
37    {
38        if ($this->depth <= 0) {
39            throw new LogicException('Depth cannot be smaller than zero.');
40        }
41
42        $this->depth -= 1;
43    }
44}
45