PHPackages                             brewerwall/unitz - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. brewerwall/unitz

Abandoned → [griffithben/unitz](/?search=griffithben%2Funitz)Library[Utility &amp; Helpers](/categories/utility)

brewerwall/unitz
================

A unit storage model to manage values between units

1.0.15(2y ago)312[1 PRs](https://github.com/griffithben/unitz/pulls)MITPHPPHP ^8.1CI passing

Since Jul 25Pushed 3mo agoCompare

[ Source](https://github.com/griffithben/unitz)[ Packagist](https://packagist.org/packages/brewerwall/unitz)[ RSS](/packages/brewerwall-unitz/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (18)Used By (0)

Unitz
=====

[](#unitz)

[![example workflow](https://github.com/griffithben/unitz/actions/workflows/main.yml/badge.svg)](https://github.com/griffithben/unitz/actions/workflows/main.yml/badge.svg)

Introduction
------------

[](#introduction)

Unitz is a way to address easy conversions among various measurable units. A utility that helps convert a unit to all types and agnostic to what type of unit it was originally set as.

### Installation

[](#installation)

```
composer require griffithben/unitz
```

### Single Type Use

[](#single-type-use)

```
// Create a new Gravity Object
$gravity = new Gravity(plato: 12);

// Gets the Plato of our Gravity
$plato = $gravity->getPlato();

// Gets the Specific Gravity of our Gravity
$specificGravity = $gravity->getSpecificGravity();

// Gets the Brix of our Gravity
$brix = $gravity->getBrix();

// Gets our Preferred Unit of measure based on our preferences
$plato = $gravity->getValue();
```

### Service Provider Use

[](#service-provider-use)

You can inject the UnitzService class into your application. Setting the user's preferences as an argument in the constructor will allow you to use the `getValue()` method to get the user's preferred unit of measure.

```
// Instantiate a new UnitzService in a Service Provider Pattern
$unitService = new UnitzService(preferences: ['Temperature' => 'Celsius']);

// Dependency injection of UnitzService within the application
$temperature = $unitService->makeTemperature(fahrenheit: 72);

// Output of getValue() based on the user's preferences
$temperature->getValue(); // 22.222222222222

// Output of getValue() based on the user's preferences with rounding
$temperature->getValue(1); // 22.2
```

### User Centric Unit Creation

[](#user-centric-unit-creation)

When setting a user's preference in the UnitService, you no longer need to specify what type of unit the user is inputting by using the `userValue` argument in the constructor of the Unit. If the user's value needs to change, the `setValue()` method will also accomplish the same idea.

```
// Create a new Gravity Object
$gravity = new Gravity(userValue: 12, preferences: ['Gravity' => 'Brix']);

// Gets the Brix of our Gravity
$brix = $gravity->getBrix();  // 12

// Gets our Preferred Unit of measure based on our preferences
$plato = $gravity->getValue(); // 12
```

### User Centric With Service Provider

[](#user-centric-with-service-provider)

```
// Instantiate a new UnitzService in a Service Provider Pattern
$unitService = new UnitzService(preferences: ['Temperature' => 'Fahrenheit']);

// Dependency injection of UnitzService within the application and a user submitted form value
$temperature = $unitService->makeTemperature(userValue: 72);

// Output of getValue() based on the user's preferences
$temperature->getValue(); // 72

// Output of getFahrenheit() will return the same as getValue() since it's the user's preference
$temperature->getFahrenheit(); // 72

// Updating the user's temperature value will have the same effect.
$temperature->setValue(76);

// Values update as needed
$temperature->getValue(); // 76
$temperature->getFahrenheit(); // 76
```

### Available Units

[](#available-units)

UnitTypesGravityPlato, SpecificGravity, BrixPressurePsi, BarTemperatureCelsius, FahrenheitVolumeOunce, Gallon, Barrel, Milliliter, Liter, HectoliterWeightOunce, Pound, Gram, KilogramColorSrm, Ebc, LovibondTimeMillisecond, Second, Minute, Hour, Day, Week, Month, YearDistillateProof, Alcohol PercentLengthInch, Foot, Yard, Mile, Millimeter, Centimeter, Meter, Kilometer### Preferences

[](#preferences)

By default, all units have a `getValue()` method that returns the users preference of unit type. There is a default preference set, but can be overridden when instantiating a new unit.

##### Default

[](#default)

```
[
    'Gravity' => 'Plato',
    'Temperature' => 'Fahrenheit',
    'Volume' => 'Gallon',
    'Pressure' => 'Psi',
    'Weight' => 'Pound',
    'Color' => 'Srm',
    'Time' => 'Minute',
    'Distillate' => 'Proof',
    'Length' => 'Foot',
];
```

##### Example

[](#example)

```
// Create a new Weight Object
$weight = new Weight(kilogram: 7.5, preferences: ['Weight' => 'Kilogram']);

// Returns Kilogram since that is the overridden preference
$kilogram = $weight->getValue();
```

### Rounding

[](#rounding)

In each type's get method, there is the option to pass in a precision of rounding. This also includes the `getValue()`method that all units share.

```
$weight = new Weight(kilogram: 7.5629145);

$kilogram = $weight->getKilogram(3);  // $kilogram = 7.563
```

Rate
----

[](#rate)

A way of representing a rate of change between two units. When accessing values of rates, all will follow the naming pattern of `$rate->get{Unit}Per{Unit}` for the respective units. Example using Flow: `$flow->getGallonPerHour()`

### Flow

[](#flow)

This class represent the amount of Volume flowed over a period of Time.

```
$flow = new Flow(new Volume(gallon: 5), new Time(hour: 1));

$flow->getGallonPerHour(); // 5

$flow->getGallonPerMinute(); // 0.083333333333333
```

---

### Boil

[](#boil)

This class represent the amount of Volume boiled over a period of Time.

```
$boil = new Boil(new Volume(gallon: 5), new Time(hour: 1));

$boil->getGallonPerHour(); // 5

$boil->getGallonPerMinute(); // 0.083333333333333
```

---

### Speed

[](#speed)

This class represent the amount of Length traveled over a period of Time.

```
$speed = new Speed(new Length(foot: 5), new Time(minute: 1));

$speed->getFeetPerMinute(); // 5

$boil->getFeetPerHour(); // 300
```

---

Calculate
---------

[](#calculate)

A library of calculations that can be used with various Unitz classes.

### Area

[](#area)

This class will calculate Area related calculations.

---

#### Rectangle

[](#rectangle)

This method will calculate the area of a rectangle based on the length and width.

```
Area::rectangle(Length $length, Length $width): Length
```

##### Arguments

[](#arguments)

- `Length $length` - Length of the rectangle
- `Length $width` - Width of the rectangle

##### Returns

[](#returns)

- `Length` - Area of the rectangle

---

#### Square

[](#square)

This method will calculate the area of a square based on the length of one side.

```
Area::square(Length $side): Length
```

##### Arguments

[](#arguments-1)

- `Length $side` - Length of one side of the square

##### Returns

[](#returns-1)

- `Length` - Area of the square

---

#### Circle

[](#circle)

This method will calculate the area of a circle based on the radius.

```
Area::circle(Length $radius): Length
```

##### Arguments

[](#arguments-2)

- `Length $radius` - Radius of the circle

##### Returns

[](#returns-2)

- `Length` - Area of the circle

---

#### Ellipse

[](#ellipse)

This method will calculate the area of an ellipse based on the major and minor axis.

```
Area::ellipse(Length $majorAxisRadius, Length $minorAxisRadius): Length
```

##### Arguments

[](#arguments-3)

- `Length $majorAxisRadius` - Major axis radius of the ellipse
- `Length $minorAxisRadius` - Minor axis radius of the ellipse

##### Returns

[](#returns-3)

- `Length` - Area of the ellipse

---

#### Triangle

[](#triangle)

This method will calculate the area of a triangle based on the base and height.

```
Area::triangle(Length $base, Length $height): Length
```

##### Arguments

[](#arguments-4)

- `Length $base` - Base of the triangle
- `Length $height` - Height of the triangle

##### Returns

[](#returns-4)

- `Length` - Area of the triangle

---

#### Equilateral Triangle

[](#equilateral-triangle)

This method will calculate the area of an equilateral triangle based on the length of one side.

```
Area::equilateralTriangle(Length $side): Length
```

##### Arguments

[](#arguments-5)

- `Length $side` - Length of one side of the equilateral triangle

##### Returns

[](#returns-5)

- `Length` - Area of the equilateral triangle

---

#### Trapezoid

[](#trapezoid)

This method will calculate the area of a trapezoid based on the length of the two bases and the height.

```
Area::trapezoid(Length $base1, Length $base2, Length $height): Length
```

##### Arguments

[](#arguments-6)

- `Length $base1` - Length of the first base of the trapezoid
- `Length $base2` - Length of the second base of the trapezoid
- `Length $height` - Height of the trapezoid

##### Returns

[](#returns-6)

- `Length` - Area of the trapezoid

---

#### Regular Pentagon

[](#regular-pentagon)

This method will calculate the area of a regular pentagon based on the length of one side.

```
Area::regularPentagon(Length $side): Length
```

##### Arguments

[](#arguments-7)

- `Length $side` - Length of one side of the regular pentagon

##### Returns

[](#returns-7)

- `Length` - Area of the regular pentagon

---

#### Regular Hexagon

[](#regular-hexagon)

This method will calculate the area of a regular hexagon based on the length of one side.

```
Area::regularHexagon(Length $side): Length
```

##### Arguments

[](#arguments-8)

- `Length $side` - Length of one side of the regular hexagon

##### Returns

[](#returns-8)

- `Length` - Area of the regular hexagon

---

#### Regular Heptagon

[](#regular-heptagon)

This method will calculate the area of a regular heptagon based on the length of one side.

```
Area::regularHeptagon(Length $side): Length
```

##### Arguments

[](#arguments-9)

- `Length $side` - Length of one side of the regular heptagon

##### Returns

[](#returns-9)

- `Length` - Area of the regular heptagon

---

#### Regular Octagon

[](#regular-octagon)

This method will calculate the area of a regular octagon based on the length of one side.

```
Area::regularOctagon(Length $side): Length
```

##### Arguments

[](#arguments-10)

- `Length $side` - Length of one side of the regular octagon

##### Returns

[](#returns-10)

- `Length` - Area of the regular octagon

---

#### Regular Nonagon

[](#regular-nonagon)

This method will calculate the area of a regular nonagon based on the length of one side.

```
Area::regularNonagon(Length $side): Length
```

##### Arguments

[](#arguments-11)

- `Length $side` - Length of one side of the regular nonagon

##### Returns

[](#returns-11)

- `Length` - Area of the regular nonagon

---

#### Regular Decagon

[](#regular-decagon)

This method will calculate the area of a regular decagon based on the length of one side.

```
Area::regularDecagon(Length $side): Length
```

##### Arguments

[](#arguments-12)

- `Length $side` - Length of one side of the regular decagon

##### Returns

[](#returns-12)

- `Length` - Area of the regular decagon

---

### Beer

[](#beer)

This class will calculate Beer related calculations.

---

#### Alcohol By Volume (ABV)

[](#alcohol-by-volume-abv)

Alcohol By Volume (ABV) is the percent of alcohol content in the beer based on the original gravity, final gravity and formula version. Source of equation is at [Brewer's Friend](https://www.brewersfriend.com/2011/06/16/alcohol-by-volume-calculator-updated/).

```
Beer::alcoholByVolume(Gravity $originalGravity, Gravity $finalGravity, string $formulaVersion = Beer::ABV_ALTERNATE_FORMULA): float
```

##### Arguments

[](#arguments-13)

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer
- `string $formulaVersion` - Formula ABV calculation: `Beer::ABV_STANDARD_FORMULA`or `Beer::ABV_ALTERNATE_FORMULA`

##### Returns

[](#returns-13)

- `float` - Alcohol By Volume (ABV) Value

---

#### Alcohol By Weight (ABW)

[](#alcohol-by-weight-abw)

Alcohol By Weight (ABW) is weighing the amount of alcohol in a fixed volume of liquid and comparing it to the weight of pure water based on the original gravity and final gravity.

```
Beer::alcoholByWeight(Gravity $originalGravity, Gravity $finalGravity): float
```

##### Arguments

[](#arguments-14)

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

[](#returns-14)

- `float` - Alcohol By Weight (ABW) Value

---

#### Standard Reference Method (SRM)

[](#standard-reference-method-srm)

Standard Reference Method (Srm) is the method for color assessment of wort or beer as published in the recommended methods of the American Society of Brewing Chemists

```
Beer::standardReferenceMethod(Weight $weight, Color $color, Volume $volume): Color
```

##### Arguments

[](#arguments-15)

- `Weight $weight` - Weight of the grain
- `Color $color` - Color of the grain
- `Volume $volume` - Volume of the water

##### Returns

[](#returns-15)

- `Unitz/Color` - Color (Color) Value

---

#### Malt Color Unit (MCU)

[](#malt-color-unit-mcu)

Malt Color Unit (MCU) is an equation that helps determine what color a beer would be.

```
Beer::maltColorUnit(Weight $weight, Color $color, Volume $volume): float
```

##### Arguments

[](#arguments-16)

- `Weight $weight` - Weight of the grain
- `Color $color` - Color of the grain
- `Volume $volume` - Volume of the water

##### Returns

[](#returns-16)

- `float` - Malt Color Unit (MCU) Value

---

#### International Bitterness Units (IBU)

[](#international-bitterness-units-ibu)

International Bitterness Units (IBU) is the bitterness of the beer based on the alpha acid of the hops, weight of the hops, time in the boil, gravity of the wort, and volume of the wort.

Based off Palmer's Calculation

```
Beer::internationalBitternessUnits(float $alphaAcid, Weight $weight, Time $time, Gravity $gravity, Volume $volume)
```

##### Arguments

[](#arguments-17)

- `float $alphaAcid` - Alpha Acid of the hops
- `Weight $weight` - Weight of the hops
- `Time $time` - Time in the boil
- `Gravity $gravity` - Gravity of the wort
- `Volume $volume` - Volume of the wort

##### Returns

[](#returns-17)

- `float` - International Bitterness Units (IBU) Value

---

#### Alpha Acid Units (AAU)

[](#alpha-acid-units-aau)

Alpha Acid Units (AAU) is the potential bitterness of the hops based on the alpha acid and weight.

```
Beer::alphaAcidUnit(float $alphaAcid, Weight $weight): float
```

##### Arguments

[](#arguments-18)

- `float $alphaAcid` - Alpha Acid of the hops
- `Weight $weight` - Weight of the hops

##### Returns

[](#returns-18)

- `float` - Alpha Acid Units (AAU) Value

---

#### Hop Utilization

[](#hop-utilization)

This is a hop utilization factor based on the Tinseth formula derived by [Glenn Tinseth](https://beersmith.com/blog/2011/02/10/beer-bitterness-and-ibus-with-glenn-tinseth-bshb-podcast-9/%5D).

```
Beer::hopUtilization(Time $time, Gravity $gravity)
```

##### Arguments

[](#arguments-19)

- `Time $time` - Time in the boil
- `Gravity $gravity` - Gravity of the wort

##### Returns

[](#returns-19)

- `float` - Hop Utilization Value

---

#### Calories

[](#calories)

Determines the number of calories in a finished beer based on the original gravity, final gravity and the volume of the beer consumed.

```
Beer::calories(Gravity $originalGravity, Gravity $finalGravity, Volume $volume)
```

##### Arguments

[](#arguments-20)

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer
- `Volume $volume` - Volume of the beer consumed

##### Returns

[](#returns-20)

- `float` - Calories

---

#### Real Extract

[](#real-extract)

Real Extract (RE) is a precise calculation concerning the gravity of beer. Source of equation is [Craft Beer &amp; Brewing](https://beerandbrewing.com/dictionary/ewOeMFnY4x/)

```
Beer::realExtract(Gravity $originalGravity, Gravity $finalGravity)
```

##### Arguments

[](#arguments-21)

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

[](#returns-21)

- `float` - Real Extract

---

#### Apparent Degree of Fermentation

[](#apparent-degree-of-fermentation)

Apparent Degree of Fermentation (ADF) is a measure of the amount of sugar that has been converted to alcohol and carbon dioxide by yeast during fermentation

```
Beer::apparentDegreeOfFermentation(Gravity $originalGravity, Gravity $finalGravity)
```

##### Arguments

[](#arguments-22)

- `Gravity $originalGravity` - Original Gravity of the beer
- `Gravity $finalGravity` - Final Gravity of the beer

##### Returns

[](#returns-22)

- `float` - Apparent Degree of Fermentation

---

#### Gravity Correction

[](#gravity-correction)

Gravity Correction based on Temperature of Sample and Hydrometer Calibration. Source [Brewers Friend](https://www.brewersfriend.com/hydrometer-temp/)

```
Beer::gravityCorrection(Gravity $gravity, Temperature $temperature, Temperature $calibrationTemperature)
```

##### Arguments

[](#arguments-23)

- `Gravity $gravity` - Gravity of the Sample
- `Temperature $temperature` - Temperature of the sample
- `Temperature $calibrationTemperature` - Temperature hydrometer is calibrated to

##### Returns

[](#returns-23)

- `Gravity` - Corrected Gravity of Sample

### Spirit

[](#spirit)

This class will calculate Spirit related calculations.

---

#### Dilute Down To Desired Proof

[](#dilute-down-to-desired-proof)

Dilute Down To Desired Proof is a calculation to determine how much water to add to a spirit to get to a desired proof.

```
Spirit::diluteDownToDesiredProof(Proof $currentProof, Proof $desiredProof, Volume $currentVolume): Volume
```

##### Arguments

[](#arguments-24)

- `Proof $currentProof` - Current Proof of the spirit
- `Proof $desiredProof` - Desired Proof of the spirit
- `Volume $currentVolume` - Current Volume of the spirit

##### Returns

[](#returns-24)

- `Volume` - Volume of water to add to the spirit

---

#### Distilled Alcohol Volume

[](#distilled-alcohol-volume)

Distilled Alcohol Volume is a calculation to determine the volume of alcohol distilled depending on the wash abv and still efficiency.

```
Spirit::distilledAlcoholVolume(Volume $volume, Distillate $wash, float $stillEfficiencyPercent): Volume
```

##### Arguments

[](#arguments-25)

- `Volume $volume` - Volume of the wash
- `Distillate $wash` - Distillate of the wash
- `float $stillEfficiencyPercent` - Still efficiency percentage

##### Returns

[](#returns-25)

- `Volume` - Volume of the distilled alcohol

---

#### Distilled Remaining Water Volume

[](#distilled-remaining-water-volume)

Distilled Remaining Water Volume is a calculation to determine the volume of water remaining after distilling a spirit.

```
Spirit::distilledRemainingWaterVolume(Volume $volume, Distillate $wash, float $stillEfficiencyPercent): Volume
```

##### Arguments

[](#arguments-26)

- `Volume $volume` - Volume of the wash
- `Distillate $wash` - Distillate of the wash
- `float $stillEfficiencyPercent` - Still efficiency percentage

##### Returns

[](#returns-26)

- `Volume` - Volume of the remaining water

### Water

[](#water)

This class will calculate Water related calculations.

---

#### Parts Per Million (PPM)

[](#parts-per-million-ppm)

Parts Per Million (PPM) is a calculation to determine the amount of a substance in a solution.

```
Water::partsPerMillion(Weight $substance, Volume $volume): float
```

##### Arguments

[](#arguments-27)

- `Weight $substance` - Weight of the substance
- `Volume $volume` - Volume of the water

##### Returns

[](#returns-27)

- `float` - Parts Per Million (PPM) Value

---

#### Boil Off Volume

[](#boil-off-volume)

Boil Off Volume determines the Volume boiled off based on Boil Rate and Time.

```
Water::boilOffVolume(Boil $boilRate, Time $time): Volume
```

##### Arguments

[](#arguments-28)

- `Boil $boilRate` - Boil Rate of your system
- `Time $time` - Time of the boil

##### Returns

[](#returns-28)

- `Volume` - Volume that has been boiled off

---

#### Post Boil Volume

[](#post-boil-volume)

Post Boil Volume determines the Volume solution remaining after a Pre Boil Volume, Boil Rate and Time are given.

```
Water::boilOffVolume(Volume postBoilVolume, Boil $boilRate, Time $time): Volume
```

##### Arguments

[](#arguments-29)

- `Volume $preBoilVolume` - Volume of solution before it's boiled
- `Boil $boilRate` - Boil Rate of your system
- `Time $time` - Time of the boil

##### Returns

[](#returns-29)

- `Volume` - Volume that remains from the boil

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance53

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Recently: every ~38 days

Total

16

Last Release

803d ago

PHP version history (2 changes)1.0.0PHP ^8.0

1.0.6PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ea2196b6325a23c4064113f6febe2041eb8e8c2e66365228f80cd1e082dce45?d=identicon)[griffithben](/maintainers/griffithben)

---

Top Contributors

[![griffithben](https://avatars.githubusercontent.com/u/632330?v=4)](https://github.com/griffithben "griffithben (95 commits)")

---

Tags

beerbrewinghacktoberfestunits-of-measure

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brewerwall-unitz/health.svg)

```
[![Health](https://phpackages.com/badges/brewerwall-unitz/health.svg)](https://phpackages.com/packages/brewerwall-unitz)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[illuminate/support

The Illuminate Support package.

583107.1M34.5k](/packages/illuminate-support)[stoutlogic/acf-builder

An Advanced Custom Field Configuration Builder

8311.8M60](/packages/stoutlogic-acf-builder)[sculpin/sculpin

Static Site Generator

1.5k102.8k12](/packages/sculpin-sculpin)[kms/froala-editor-bundle

Provides a Froala editor integration for Symfony 4 &amp; 5.

110272.8k](/packages/kms-froala-editor-bundle)[wyrihaximus/react-child-process-messenger

Messenger decorator for react/child-process

32279.4k4](/packages/wyrihaximus-react-child-process-messenger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
