| Total Complexity | 9 |
| Total Lines | 61 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class Property |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var mixed |
||
| 21 | */ |
||
| 22 | private $value; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string|null |
||
| 26 | */ |
||
| 27 | private $label; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param mixed $value |
||
| 31 | * @param string $label |
||
| 32 | * @param ValueFormatter[] $valueFormatters |
||
| 33 | */ |
||
| 34 | public function __construct($value, ?string $label = null, array $valueFormatters = []) |
||
| 35 | { |
||
| 36 | $this->validateFormatters($valueFormatters); |
||
| 37 | |||
| 38 | $this->value = $this->formatValue($value, $valueFormatters); |
||
| 39 | $this->label = $label; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function getLabel(): ?string |
||
| 43 | { |
||
| 44 | return $this->label; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return mixed |
||
| 49 | */ |
||
| 50 | public function getValue() |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param mixed $value |
||
| 57 | * @param ValueFormatter[] $valueFormatters |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | private function formatValue($value, array $valueFormatters) |
||
| 61 | { |
||
| 62 | foreach ($valueFormatters as $formatter) { |
||
| 63 | $value = $formatter->format($value); |
||
| 64 | } |
||
| 65 | |||
| 66 | return $value; |
||
| 67 | } |
||
| 68 | |||
| 69 | private function validateFormatters(array $valueFormatters): void |
||
| 78 | )); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 83 |