BaseIdNameEntity::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace NekoAPI\Component\Entity;
4
5
/**
6
 * Class BaseIdNameEntity
7
 *
8
 * @package NekoAPI\Component\Entity
9
 * @author  Aurimas Niekis <[email protected]>
10
 */
11
abstract class BaseIdNameEntity extends BaseNameEntity
12
{
13
    /**
14
     * @var int
15
     */
16
    private $id;
17
18 4
    public function __construct(int $id, string $name)
19
    {
20 4
        parent::__construct($name);
21
22 4
        $this->id = $id;
23 4
    }
24
25
    /**
26
     * @return int
27
     */
28 3
    public function getId(): ?int
29
    {
30 3
        return $this->id;
31
    }
32
33
    /**
34
     * @param int $id
35
     *
36
     * @return BaseIdNameEntity
37
     */
38 1
    public function setId(int $id): BaseIdNameEntity
39
    {
40 1
        $this->id = $id;
41
42 1
        return $this;
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48 1
    public function jsonSerialize(): array
49
    {
50
        return [
51 1
            'id'   => $this->getId(),
52 1
            'name' => $this->getName(),
53
        ];
54
    }
55
}