-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSimpleField.php
More file actions
41 lines (37 loc) · 1.08 KB
/
Copy pathSimpleField.php
File metadata and controls
41 lines (37 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Mindee\Parsing\V2\Field;
/**
* A simple field with a scalar value.
*/
class SimpleField extends BaseField
{
/**
* @var string|float|boolean|null Value contained in the field.
*/
public $value;
/**
* @param array $serverResponse Raw server response array.
* @param integer $indentLevel Level of indentation for rst display.
*/
public function __construct(array $serverResponse, int $indentLevel = 0)
{
parent::__construct($serverResponse, $indentLevel);
$this->value = array_key_exists('value', $serverResponse) ? $serverResponse['value'] : null;
if (is_int($this->value)) {
$this->value = (float) $this->value;
}
}
/**
* @return string
*/
public function __toString(): string
{
if (is_bool($this->value)) {
return $this->value ? 'True' : 'False';
}
if (is_numeric($this->value)) {
return number_format($this->value, 1, '.', '');
}
return $this->value !== null ? (string)$this->value : '';
}
}