php-value-object / temperature
Temperature ValueObject for PHP. Easy to use with implementation of Kelvin, Celsius and Fahrenheit
v0.2
2018-02-05 19:56 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpstan/phpstan-shim: ^0.9
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-11-16 03:37:19 UTC
README
This repository provides Temperature ValueObject implementation for PHP that is easy to use and easily allow your classes to
depend on Temperature
object instead of just float or string.
Install
You can install this package via composer
composer require php-value-object/temperature
Example
function isItWarm(Temperature $temperature) : bool { $hot = new Celsius(23); if($temperature->gte($hot)) { return true; // t-shirt time } return false; // jacket time } $temperature = new Kelvin(0); isItWarm($temperature); // false
Usage
The temperature classes are supported: Celsius
, Fahrenheit
and Kelvin
.
It is possible to compare them via helper methods:
eq
- equalsgt
- greater thangte
- greater than or equalslt
- less thanlte
- less than or equalscompareTo
- returns -1, 0, 1 if less than, equal or greater than
To introduce new temperature class simply extend Temperature.
Licence
MIT
Contributing
Any contributions are welcome
Building & Development
The easiest way how to develop is to git clone
and run make
git clone git@github.com:PHPValueObject/Temperature.git temperature
cd temperature
make