1 | <?php |
||
2 | |||
3 | namespace ZpgRtf\Objects; |
||
4 | |||
5 | /** |
||
6 | * This describes a single area. It is a constituent of a number of other objects. This should not be confused with the |
||
7 | * areas object. |
||
8 | */ |
||
9 | View Code Duplication | class AreaObject implements \JsonSerializable |
|
0 ignored issues
–
show
|
|||
10 | { |
||
11 | /** @var null|float **/ |
||
12 | private $value; |
||
13 | |||
14 | /** |
||
15 | * Array of enum (sq_feet, sq_yards, sq_metres, acres, hectares) |
||
16 | * |
||
17 | * @var null|string |
||
18 | */ |
||
19 | private $units; |
||
20 | |||
21 | /** |
||
22 | * @return null|float |
||
23 | */ |
||
24 | 2 | public function getValue() |
|
25 | { |
||
26 | 2 | return $this->value; |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param float $value |
||
31 | * |
||
32 | * @return AreaObject |
||
33 | */ |
||
34 | 1 | public function setValue(float $value): self |
|
35 | { |
||
36 | 1 | $this->value = $value; |
|
37 | |||
38 | 1 | return $this; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * @return null|string |
||
43 | */ |
||
44 | 2 | public function getUnits() |
|
45 | { |
||
46 | 2 | return $this->units; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $units |
||
51 | * |
||
52 | * @return AreaObject |
||
53 | */ |
||
54 | 1 | public function setUnits(string $units): self |
|
55 | { |
||
56 | 1 | $this->units = $units; |
|
57 | |||
58 | 1 | return $this; |
|
59 | } |
||
60 | |||
61 | /** {@inheritDoc} */ |
||
62 | 1 | public function jsonSerialize(): array |
|
63 | { |
||
64 | 1 | return array_filter([ |
|
65 | 1 | 'units' => $this->getUnits(), |
|
66 | 1 | 'value' => $this->getValue(), |
|
67 | ]); |
||
68 | } |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.