Completed
Push — master ( 12c461...346425 )
by Jan Philip
03:11
created

Dish::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
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
 * Created by IntelliJ IDEA.
4
 * User: uni
5
 * Date: 22.11.17
6
 * Time: 17:48
7
 */
8
9
namespace JPBernius\FMeat\Entities;
10
11
12
/**
13
 * Class Dish
14
 * @package JPBernius\FMeat\Entities
15
 */
16
class Dish implements Entity
17
{
18
19
    /** @var string */
20
    private $name;
21
22
    /** @var float */
23
    private $price;
24
25
    /**
26
     * Dish constructor.
27
     * @param string $name
28
     * @param float $price
29
     */
30 3
    public function __construct(string $name, float $price)
31
    {
32 3
        $this->name = $name;
33 3
        $this->price = $price;
34 3
    }
35
36
    /**
37
     * @param \stdClass $jsonObject
38
     * @return Dish
39
     */
40 3
    public static function fromJson(\stdClass $jsonObject): self
41
    {
42 3
        return new Dish($jsonObject->name, $jsonObject->price);
43
    }
44
45
    /**
46
     * @return string
47
     */
48 3
    public function getName(): string
49
    {
50 3
        return $this->name;
51
    }
52
53
    /**
54
     * @return float
55
     */
56
    public function getPrice(): float
57
    {
58
        return $this->price;
59
    }
60
61
    /**
62
     * Specify data which should be serialized to JSON
63
     * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
64
     * @return mixed data which can be serialized by <b>json_encode</b>,
65
     * which is a value of any type other than a resource.
66
     * @since 5.4.0
67
     */
68
    public function jsonSerialize(): array
69
    {
70
        return [
71
            'name' => $this->getName(),
72
            'price' => $this->getPrice()
73
        ];
74
    }
75
}