Completed
Push — feature/middleware ( e85030...d864e0 )
by Derek Stephen
05:41
created

Unicorn   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 170
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 0
dl 0
loc 170
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A setId() 0 4 1
A getName() 0 4 1
A setName() 0 4 1
A getDob() 0 4 1
A setDob() 0 4 1
A getFood() 0 4 1
A setFood() 0 4 1
A getCanFly() 0 4 1
A setCanFly() 0 4 1
A getDrink() 0 4 1
A setDrink() 0 4 1
A toArray() 0 13 2
A jsonSerialize() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BoneMvc\Module\Unicorn\Entity;
6
7
use DateTime;
8
use Doctrine\ORM\Mapping as ORM;
9
use JsonSerializable;
10
11
/**
12
 * @ORM\Entity(repositoryClass="\BoneMvc\Module\Unicorn\Repository\UnicornRepository")
13
 */
14
class Unicorn
15
{
16
    /**
17
     * @var int $id
18
     * @ORM\Id
19
     * @ORM\Column(type="integer")
20
     * @ORM\GeneratedValue
21
     */
22
    private $id;
23
24
    /**
25
     * @var string $name
26
     * @ORM\Column(type="string", length=30, nullable=false)
27
     */
28
    private $name;
29
30
    /**
31
     * @var DateTime $dob
32
     * @ORM\Column(type="date", nullable=true)
33
     */
34
    private $dob;
35
36
    /**
37
     * @var int $food
38
     * @ORM\Column(type="integer", length=1, nullable=true)
39
     */
40
    private $food;
41
42
    /**
43
     * @var bool $canFly
44
     * @ORM\Column(type="boolean", nullable=false)
45
     */
46
    private $canFly;
47
48
    /**
49
     * @var int $drink
50
     * @ORM\Column(type="integer", length=1, nullable=true)
51
     */
52
    private $drink;
53
54
    /**
55
     * @return int
56
     */
57
    public function getId(): ?int
58
    {
59
        return $this->id;
60
    }
61
62
    /**
63
     * @param int $id
64
     */
65
    public function setId($id): void
66
    {
67
        $this->id = $id;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getName(): string
74
    {
75
        return $this->name;
76
    }
77
78
    /**
79
     * @param string $name
80
     */
81
    public function setName(string $name): void
82
    {
83
        $this->name = $name;
84
    }
85
86
    /**
87
     * @return DateTime
88
     */
89
    public function getDob(): ?DateTime
90
    {
91
        return $this->dob;
92
    }
93
94
    /**
95
     * @param DateTime|null $dob
96
     */
97
    public function setDob(?DateTime $dob): void
98
    {
99
        $this->dob = $dob;
100
    }
101
102
    /**
103
     * @return int
104
     */
105
    public function getFood(): ?int
106
    {
107
        return $this->food;
108
    }
109
110
    /**
111
     * @param int|null $food
112
     */
113
    public function setFood(?int $food): void
114
    {
115
        $this->food = $food;
116
    }
117
118
    /**
119
     * @return bool
120
     */
121
    public function getCanFly(): bool
122
    {
123
        return $this->canFly;
124
    }
125
126
    /**
127
     * @param bool $canFly
128
     */
129
    public function setCanFly(bool $canFly): void
130
    {
131
        $this->canFly = $canFly;
132
    }
133
134
    /**
135
     * @return int
136
     */
137
    public function getDrink(): ?int
138
    {
139
        return $this->drink;
140
    }
141
142
    /**
143
     * @param int|null $drink
144
     */
145
    public function setDrink(?int $drink): void
146
    {
147
        $this->drink = $drink;
148
    }
149
150
    /**
151
     * @return array
152
     * @param string $dateFormat
153
     */
154
    public function toArray(string $dateFormat = 'd/m/Y'): array
155
    {
156
        $data = [
157
            'id' => $this->getId(),
158
            'name' => $this->getName(),
159
            'dob' => ($dob = $this->getDob()) ? $dob->format($dateFormat) : null,
160
            'food' => $this->getFood(),
161
            'canFly' => $this->getCanFly(),
162
            'drink' => $this->getDrink(),
163
        ];
164
165
        return $data;
166
    }
167
168
    /**
169
     * @return string
170
     */
171
    public function jsonSerialize(): string
172
    {
173
        return \json_encode($this->toArray());
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function __toString(): string
180
    {
181
        return $this->jsonSerialize();
182
    }
183
}
184