Completed
Push — master ( 3aaa33...c01ad8 )
by Jan Philip
03:33
created

Dish::getPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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