Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVP version of component #1

Merged
merged 22 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f83ddbc
Feat: add symfony/var-dumper dev dependency
jordanbrauer Oct 7, 2017
7de1518
Update: test namespace & directory hierarchy
jordanbrauer Oct 8, 2017
ed0ffe6
Update: add unit testsuite
jordanbrauer Oct 9, 2017
a6f6395
Feat: list of default measurements via class constants
jordanbrauer Oct 9, 2017
41a2b92
Feat: interface and unit tests for the abstract Unit of measure class
jordanbrauer Oct 9, 2017
73f9ee4
Feat: add a few default length units. meter is base for all length units
jordanbrauer Oct 9, 2017
4e241a1
Feat: unit registry class to store and retrieve supported units to/from
jordanbrauer Oct 9, 2017
3a84d07
Feat: add unit converter class to actually convert values from/to units
jordanbrauer Oct 9, 2017
92e48ef
Update: add examples file
jordanbrauer Oct 9, 2017
e85984c
Feat: support conversion to Astronomical Units
jordanbrauer Oct 9, 2017
3fc8d05
Feat: support conversion to Decimeters
jordanbrauer Oct 9, 2017
fa2dc15
Feat: support conversion to Feet
jordanbrauer Oct 9, 2017
557d426
Feat: support conversion to Hands
jordanbrauer Oct 9, 2017
aec8229
Feat: support conversion to Kilometers
jordanbrauer Oct 9, 2017
cf453c6
Feat: support conversion to Lightyears
jordanbrauer Oct 9, 2017
0a12953
Feat: support conversion to Micrometers
jordanbrauer Oct 9, 2017
b377122
Feat: support conversion to Miles
jordanbrauer Oct 9, 2017
c9499c8
Feat: support conversion to Nanometers
jordanbrauer Oct 9, 2017
9dd7546
Feat: support conversion to Parsecs
jordanbrauer Oct 9, 2017
5ca7f5c
Feat: support conversion to Picometers
jordanbrauer Oct 9, 2017
d1196f6
Feat: support conversion to Yards
jordanbrauer Oct 9, 2017
75c5342
Fix: included missing base LengthUnit file
jordanbrauer Oct 9, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
}
],
"scripts": {
"test": "phpunit --configuration='./phpunit.xml' --test-suffix='.spec.php' --color=always ./dev/tests/"
"test": "phpunit --configuration='./phpunit.xml' --test-suffix='.spec.php' --color=always ./tests/"
},
"require": {},
"require-dev": {
"phpdocumentor/phpdocumentor": "^2.9",
"phpunit/phpunit": "^6.3"
"phpunit/phpunit": "^6.3",
"symfony/var-dumper": "^3.3"
},
"autoload": {
"psr-4": {
Expand All @@ -25,7 +26,7 @@
},
"autoload-dev": {
"psr-4": {
"UnitConverter\\Tests\\Unit\\": "dev/tests/unit/UnitConverter/"
"UnitConverter\\Tests\\Unit\\": "tests/unit/UnitConverter/"
}
}
}
72 changes: 70 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions examples.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

require_once "vendor/autoload.php";

use UnitConverter\UnitConverter;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\AbstractUnit;
use UnitConverter\Measure;
use UnitConverter\Unit\Length\{
Centimeter,
Inch
};

# Configuring a New Converter
# ===========================

$units = array(
new Centimeter,
new Inch,
);

$registry = new UnitRegistry($units);

$converter = new UnitConverter($registry);

# Registering Custom Units
# ========================

$registry->registerUnit(new class extends AbstractUnit {
protected $name = "testtt";
protected $symbol = "Tst";
protected $unitOf = Measure::VOLUME;
protected $base = self::class;
protected $units = 1;
});

# Converting Units
# ================

$conversion =
$converter
->convert(1)
->from("in")
->to("cm")
;
20 changes: 13 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
verbose="true"
colors="true"
>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="general">
<directory suffix=".spec.php">dev/tests/</directory>
<testsuite name="fullspec">
<directory suffix=".spec.php">tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<testsuites>
<testsuite name="unit">
<directory suffix=".spec.php">tests/unit/</directory>
</testsuite>
</testsuites>
</phpunit>
46 changes: 46 additions & 0 deletions src/UnitConverter/Measure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2017 Jordan Brauer <[email protected]>
* @license MIT
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types = 1);

namespace UnitConverter;

/**
* A static class containing constants that define the available
* default types of measurement.
*
* @version 1.0.0
* @since 1.0.0
* @author Jordan Brauer <[email protected]>
*/
class Measure
{
const LENGTH = "length";

const AREA = "area";

const VOLUME = "volume";

const WEIGHT = "weight";

const SPEED = "speed";

const ROTATION = "rotation";

const TEMPERATURE = "temperature";

const PRESSURE = "pressure";

const TIME = "time";

const ENERGY = "energy";
}
Loading