| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Square\Legacy\Models; |
| 6 |
|
| 7 |
use stdClass; |
| 8 |
|
| 9 |
/** |
| 10 |
* Specifies a decimal number range. |
| 11 |
*/ |
| 12 |
class FloatNumberRange implements \JsonSerializable |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var array |
| 16 |
*/ |
| 17 |
private $startAt = []; |
| 18 |
|
| 19 |
/** |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
private $endAt = []; |
| 23 |
|
| 24 |
/** |
| 25 |
* Returns Start At. |
| 26 |
* A decimal value indicating where the range starts. |
| 27 |
*/ |
| 28 |
public function getStartAt(): ?string |
| 29 |
{ |
| 30 |
if (count($this->startAt) == 0) { |
| 31 |
return null; |
| 32 |
} |
| 33 |
return $this->startAt['value']; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Sets Start At. |
| 38 |
* A decimal value indicating where the range starts. |
| 39 |
* |
| 40 |
* @maps start_at |
| 41 |
*/ |
| 42 |
public function setStartAt(?string $startAt): void |
| 43 |
{ |
| 44 |
$this->startAt['value'] = $startAt; |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Unsets Start At. |
| 49 |
* A decimal value indicating where the range starts. |
| 50 |
*/ |
| 51 |
public function unsetStartAt(): void |
| 52 |
{ |
| 53 |
$this->startAt = []; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Returns End At. |
| 58 |
* A decimal value indicating where the range ends. |
| 59 |
*/ |
| 60 |
public function getEndAt(): ?string |
| 61 |
{ |
| 62 |
if (count($this->endAt) == 0) { |
| 63 |
return null; |
| 64 |
} |
| 65 |
return $this->endAt['value']; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Sets End At. |
| 70 |
* A decimal value indicating where the range ends. |
| 71 |
* |
| 72 |
* @maps end_at |
| 73 |
*/ |
| 74 |
public function setEndAt(?string $endAt): void |
| 75 |
{ |
| 76 |
$this->endAt['value'] = $endAt; |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Unsets End At. |
| 81 |
* A decimal value indicating where the range ends. |
| 82 |
*/ |
| 83 |
public function unsetEndAt(): void |
| 84 |
{ |
| 85 |
$this->endAt = []; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Encode this object to JSON |
| 90 |
* |
| 91 |
* @param bool $asArrayWhenEmpty Whether to serialize this model as an array whenever no fields |
| 92 |
* are set. (default: false) |
| 93 |
* |
| 94 |
* @return array|stdClass |
| 95 |
*/ |
| 96 |
#[\ReturnTypeWillChange] // @phan-suppress-current-line PhanUndeclaredClassAttribute for (php < 8.1) |
| 97 |
public function jsonSerialize(bool $asArrayWhenEmpty = false) |
| 98 |
{ |
| 99 |
$json = []; |
| 100 |
if (!empty($this->startAt)) { |
| 101 |
$json['start_at'] = $this->startAt['value']; |
| 102 |
} |
| 103 |
if (!empty($this->endAt)) { |
| 104 |
$json['end_at'] = $this->endAt['value']; |
| 105 |
} |
| 106 |
$json = array_filter($json, function ($val) { |
| 107 |
return $val !== null; |
| 108 |
}); |
| 109 |
|
| 110 |
return (!$asArrayWhenEmpty && empty($json)) ? new stdClass() : $json; |
| 111 |
} |
| 112 |
} |
| 113 |
|