PHPackages                             apiotrowski/unit-converter - 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. apiotrowski/unit-converter

ActiveLibrary

apiotrowski/unit-converter
==========================

Unit converter it is service which converts values based on raw string query.

2.6(7y ago)010proprietaryPHPPHP ~7.1

Since Oct 17Pushed 7y ago1 watchersCompare

[ Source](https://github.com/apiotrowski/unit-converter)[ Packagist](https://packagist.org/packages/apiotrowski/unit-converter)[ RSS](/packages/apiotrowski-unit-converter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (9)Used By (0)

Unit Converter
==============

[](#unit-converter)

[![Build Status](https://camo.githubusercontent.com/d99598ab5b7fe89b645294309d7ba3e091a76364c43ea9012433c31f9b40f011/68747470733a2f2f7472617669732d63692e6f72672f6170696f74726f77736b692f756e69742d636f6e7665727465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/apiotrowski/unit-converter)

Unit converter it is php service which converts values based on raw string query.

> QueryExample: 10cm to ?in

Converter will automatically resolve supported converter and make calculation. In the output it return new **Value**.

**Value** is an Object what have two property: *Value* (string), *Unit* (object).

Manual conversion
-----------------

[](#manual-conversion)

If you want to convert values not using Convert Manager you can do it directly by calling following snippet:

```
(new LengthConverter())->convertTo(new Value(10, UnitFactory::build(LengthUnit::CENTIMETRE)), UnitFactory::build(LengthUnit::INCH));
```

Current converters list implemented inside:
-------------------------------------------

[](#current-converters-list-implemented-inside)

- Length Converter (unit: ml, km, m, cm, in, ft)
- Weight Converter (unit: t, kg, g, dag, lbs, oz)

How to use it
-------------

[](#how-to-use-it)

Unit Converter is really simple to use and easy to extend. In a bellow example I show how to use this tool.

```
$convertManager = new ConvertManager(new ArrayCollection([ new LengthConverter(), new WeightConverter() ]), new QueryResolver());
$convertedValue = $convertManager->convert('10cm to ?in');
```

After you call convert() function all magic happened inside. At the beginning it resolve the query to php form, choose what converter should be used, and in the end converts value to destination unit.

In the output ($convertedValue) you get *Value* object with the result.

To calculation values tool is use [BC Math library](http://php.net/manual/en/ref.bc.php).

Tool are tested in [PHPUnit](https://phpunit.de/), so everything should work Without any mistake.

How to extend Unit Converter
----------------------------

[](#how-to-extend-unit-converter)

To Extend Converter User should:

1. Create new Converter class and Unit class,
2. Add new created Unit class to list of the supported units in the UnitFactory class,
3. During initialization of ConvertManager, add your converter class to list of supported converters.

Supported PHP Versions
----------------------

[](#supported-php-versions)

- PHP 7.0 with installed BC Math Extension

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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 ~108 days

Recently: every ~0 days

Total

8

Last Release

2733d ago

Major Versions

v1.0 → 2.02018-11-12

PHP version history (2 changes)v1.0PHP ~7.0

2.1PHP ~7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1fa0d7e7a77aa9006ec96c487ac78f4815ecd6cb58a80912ef6103c54099f473?d=identicon)[apiotrowski](/maintainers/apiotrowski)

---

Top Contributors

[![apiotrowski](https://avatars.githubusercontent.com/u/4092746?v=4)](https://github.com/apiotrowski "apiotrowski (38 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/apiotrowski-unit-converter/health.svg)

```
[![Health](https://phpackages.com/badges/apiotrowski-unit-converter/health.svg)](https://phpackages.com/packages/apiotrowski-unit-converter)
```

PHPackages © 2026

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