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

Dish   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 61.53%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 60
ccs 8
cts 13
cp 0.6153
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromJson() 0 4 1
A getName() 0 4 1
A getPrice() 0 4 1
A jsonSerialize() 0 7 1
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
}