self::MAX_MILLI) { throw new InvalidWorkflowStepMaterial; } } /** * A quantity typed as "2,5" or "2.5", with at most three decimals. * * @throws InvalidWorkflowStepMaterial */ public static function parse(int $stockItemId, string $quantity): self { $quantity = str_replace(',', '.', preg_replace('/[\s\x{00A0}]+/u', '', $quantity) ?? ''); if (preg_match('/^(\d{1,7})(?:\.(\d{1,3}))?$/', $quantity, $matches) !== 1) { throw new InvalidWorkflowStepMaterial; } return new self($stockItemId, (int) $matches[1] * 1000 + (int) str_pad($matches[2] ?? '', 3, '0')); } }