. */ declare(strict_types=1); namespace App\Services\InfoProviderSystem\DTOs; class ParameterDTO { public function __construct( public readonly string $name, public readonly ?string $value_text = null, public readonly ?float $value_typ = null, public readonly ?float $value_min = null, public readonly ?float $value_max = null, public readonly ?string $unit = null, public readonly ?string $symbol = null, public readonly ?string $group = null, ) { } public static function parseValueField(string $name, string|float $value, ?string $unit = null, ?string $symbol = null, ?string $group = null): self { if (is_float($value) || is_numeric($value)) { return new self($name, value_typ: (float) $value, unit: $unit, symbol: $symbol, group: $group); } return new self($name, value_text: $value, unit: $unit, symbol: $symbol, group: $group); } public static function parseValueIncludingUnit(string $name, string|float $value, ?string $symbol = null, ?string $group = null): self { if (is_float($value) || is_numeric($value)) { return new self($name, value_typ: (float) $value, symbol: $symbol, group: $group); } $unit = null; if (preg_match('/^(?[0-9.]+)\s*(?[a-zA-Z]+)$/', $value, $matches)) { $value = $matches['value']; $unit = $matches['unit']; } return new self($name, value_text: $value, unit: $unit, symbol: $symbol, group: $group); } }