Category::getParentId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace Audiens\AdForm\Entity;
4
5
use DateTime;
6
use JsonSerializable;
7
8
/**
9
 * Class Category
10
 */
11
class Category implements JsonSerializable
12
{
13
    /** @var int|null */
14
    protected $id;
15
16
    /** @var string|null */
17
    protected $name;
18
19
    /** @var int|null */
20
    protected $dataProviderId;
21
22
    /** @var int|null */
23
    protected $parentId;
24
25
    /** @var DateTime|null */
26
    protected $updatedAt;
27
28
    /** @var DateTime|null */
29
    protected $createdAt;
30
31
    public function getUpdatedAt(): ?DateTime
32
    {
33
        return $this->updatedAt;
34
    }
35
36
    public function getCreatedAt(): ?DateTime
37
    {
38
        return $this->createdAt;
39
    }
40
41
    public function getId(): ?int
42
    {
43
        return $this->id;
44
    }
45
46
    public function getName(): ?string
47
    {
48
        return $this->name;
49
    }
50
51
    public function setName(string $name): Category
52
    {
53
        $this->name = $name;
54
55
        return $this;
56
    }
57
58
    public function getDataProviderId(): ?int
59
    {
60
        return $this->dataProviderId;
61
    }
62
63
    public function setDataProviderId(int $dataProviderId): Category
64
    {
65
        $this->dataProviderId = $dataProviderId;
66
67
        return $this;
68
    }
69
70
    public function getParentId(): ?int
71
    {
72
        return $this->parentId;
73
    }
74
75
    public function setParentId(int $parentId): Category
76
    {
77
        $this->parentId = $parentId;
78
79
        return $this;
80
    }
81
82
    public function jsonSerialize()
83
    {
84
        $json = new \stdClass();
85
86
        // might not be set for a new category
87
        if ($this->id !== null) {
88
            $json->id = $this->id;
89
        }
90
91
        $json->name = $this->name;
92
        $json->dataProviderId = $this->dataProviderId;
93
94
        // might not be set at all
95
        if ($this->parentId !== null) {
96
            $json->parentId = $this->parentId;
97
        }
98
99
        // might not be set for a new category
100
        if ($this->createdAt !== null) {
101
            $json->createdAt = $this->createdAt->format('c');
102
        }
103
104
        // might not be set for a new category
105
        if ($this->updatedAt !== null) {
106
            $json->updatedAt = $this->updatedAt->format('c');
107
        }
108
109
        return $json;
110
    }
111
}
112