Completed
Push — feature/middleware ( 16c6e3...4ff047 )
by Derek Stephen
07:45
created

Dragon::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BoneMvc\Module\Dragon\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use JsonSerializable;
7
8
/**
9
 * @ORM\Entity(repositoryClass="\BoneMvc\Module\Dragon\Repository\DragonRepository")
10
 */
11
class Dragon implements JsonSerializable
12
{
13
    /**
14
     * @var int $id
15
     * @ORM\Id
16
     * @ORM\Column(type="integer")
17
     * @ORM\GeneratedValue
18
     */
19
    private $id;
20
21
    /**
22
     * @var string $name
23
     * @ORM\Column(type="string", length=30, nullable=false)
24
     */
25
    private $name;
26
27
    /**
28
     * @return int
29
     */
30
    public function getId()
31
    {
32
        return $this->id;
33
    }
34
35
    /**
36
     * @param int $id
37
     */
38
    public function setId($id)
39
    {
40
        $this->id = $id;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getName(): ?string
47
    {
48
        return $this->name;
49
    }
50
51
    /**
52
     * @param string $name
53
     */
54
    public function setName(string $name)
55
    {
56
        $this->name = $name;
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function toArray()
63
    {
64
        $data = [
65
            'id' => $this->getId(),
66
            'name' => $this->getName(),
0 ignored issues
show
Bug introduced by
Consider using $this->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
67
        ];
68
69
        return $data;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function __toString()
76
    {
77
        return $this->jsonSerialize();
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function jsonSerialize()
84
    {
85
        return \json_encode($this->toArray());
86
    }
87
88
89
}
90