'Yard', self::METER => 'Meter', self::KILOGRAM => 'Kilogram', }; } public function abbreviation(): string { return match ($this) { self::YARD => 'yard', self::METER => 'm', self::KILOGRAM => 'kg', }; } /** * @return list */ public static function values(): array { return array_column(self::cases(), 'value'); } public function minStock(): float { return match ($this) { self::YARD => self::MIN_STOCK_YARD, self::METER => self::MIN_STOCK_METER, self::KILOGRAM => self::MIN_STOCK_KILOGRAM, }; } public function usesLengthUnit(): bool { return match ($this) { self::YARD, self::METER => true, self::KILOGRAM => false, }; } public function cmPerUnit(): ?float { return match ($this) { self::YARD => self::CM_PER_YARD, self::METER => self::CM_PER_METER, self::KILOGRAM => null, }; } public function toCm(float $value): ?float { $cmPerUnit = $this->cmPerUnit(); if ($cmPerUnit === null) { return null; } return $value * $cmPerUnit; } public function fromCm(float $cm): float { $cmPerUnit = $this->cmPerUnit(); if ($cmPerUnit === null || $cmPerUnit <= 0) { return $cm; } return $cm / $cmPerUnit; } public function pricePerCm(int $pricePerUnit): ?float { $cmPerUnit = $this->cmPerUnit(); if ($cmPerUnit === null || $cmPerUnit <= 0) { return null; } return $pricePerUnit / $cmPerUnit; } }