<commit_before># PHP Units of Measure
master: [![Build Status](https://travis-ci.org/triplepoint/php-units-of-measure.png?branch=master)](https://travis-ci.org/triplepoint/php-units-of-measure)

## Introduction
This is a PHP library for representing and converting physical units of measure.  The utility of this library
is in encapsulating physical quantities in such a way that you don't have to keep track of which
unit they're represented in.  For instance:

``` php
use PhpUnitsOfMeasure\PhysicalQuantity\Length;

$height = new Length(6.16, 'feet');
echo $height->toUnit('m');

// would print 1.87757, which is 6.16 feet in meters.
```

Having this abstraction allows you to create interfaces that accept physical quantities
without requiring them to be in a particular unit.  For example, this function assumes the
height is a float of a particular unit (presumably feet):

``` php
function isTooTallToRideThisTrain( $height )
{
  return $height > 5;
}

// Calling the function requires that you first convert whatever quantity you have into the expected units:
isTooTallToRideThisTrain(2 / 0.3048);
```

Whereas this version allows for height to be provided in whatever unit is convenient:

``` php
use PhpUnitsOfMeasure\PhysicalQuantity\Length;

function isTooTallToRideThisTrain( Length $height )
{
  return $height->toUnit('ft') > 5;
}

// Calling the function now allows any unit to be used:
isTooTallToRideThisTrain( new Length(2, 'm') );
```

## Installation
This library is best included in your projects via composer.  See the [Composer website](http://getcomposer.org/)
for more details, and see the [Packagist.org site for this library](https://packagist.org/packages/triplepoint/php-units-of-measure).

## Use
### Conversion
As in the examples above, the basic usage of this library is in representing physical quantities and converting
between typical units of measure.  For example:

``` php
$quantity = new \PhpUnitsOfMeasure\PhysicalQuantity\Mass(6, 'lbs');
echo $quantity->toUnit('g');
```
It's also possible to implicity cast a quantity to a string, which will display its original value:

``` php
$quantity = new \PhpUnitsOfMeasure\PhysicalQuantity\Mass(6, 'pounds');
echo $quantity; // '6 lbs'
```

### Aritmetic Operators
There's also support for addition and subtraction.  The `PhysicalQuantity` objects are immutable, and as such
these arithmetic methods return new quantity objects representing the results:
<commit_msg>whoops, typo in the README.<commit_after># PHP Units of Measure
master: [![Build Status](https://travis-ci.org/triplepoint/php-units-of-measure.png?branch=master)](https://travis-ci.org/triplepoint/php-units-of-measure)

## Introduction
This is a PHP library for representing and converting physical units of measure.  The utility of this library
is in encapsulating physical quantities in such a way that you don't have to keep track of which
unit they're represented in.  For instance:

``` php
use PhpUnitsOfMeasure\PhysicalQuantity\Length;

$height = new Length(6.16, 'feet');
echo $height->toUnit('m');

// would print 1.87757, which is 6.16 feet in meters.
```

Having this abstraction allows you to create interfaces that accept physical quantities
without requiring them to be in a particular unit.  For example, this function assumes the
height is a float of a particular unit (presumably feet):

``` php
function isTooTallToRideThisTrain( $height )
{
  return $height > 5;
}

// Calling the function requires that you first convert whatever quantity you have into the expected units:
isTooTallToRideThisTrain(2 / 0.3048);
```

Whereas this version allows for height to be provided in whatever unit is convenient:

``` php
use PhpUnitsOfMeasure\PhysicalQuantity\Length;

function isTooTallToRideThisTrain( Length $height )
{
  return $height->toUnit('ft') > 5;
}

// Calling the function now allows any unit to be used:
isTooTallToRideThisTrain( new Length(2, 'm') );
```

## Installation
This library is best included in your projects via composer.  See the [Composer website](http://getcomposer.org/)
for more details, and see the [Packagist.org site for this library](https://packagist.org/packages/triplepoint/php-units-of-measure).

## Use
### Conversion
As in the examples above, the basic usage of this library is in representing physical quantities and converting
between typical units of measure.  For example:

``` php
$quantity = new \PhpUnitsOfMeasure\PhysicalQuantity\Mass(6, 'lbs');
echo $quantity->toUnit('g');
```
It's also possible to implicity cast a quantity to a string, which will display its original value:

``` php
$quantity = new \PhpUnitsOfMeasure\PhysicalQuantity\Mass(6, 'pounds');
echo $quantity; // '6 lbs'
```

### Arithmetic Operators
There's also support for addition and subtraction.  The `PhysicalQuantity` objects are immutable, and as such
these arithmetic methods return new quantity objects representing the results:

{'fraction_non_alphanumeric': 0.09603255340793489, 'fraction_numerical': 0.009766022380467955, 'mean_word_length': 4.995121951219512, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3969306', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1366, 'n_words': 568}