Skip to content

Commit

Permalink
Merge pull request #1 from jordanbrauer/develop
Browse files Browse the repository at this point in the history
MVP version of component
  • Loading branch information
jordanbrauer authored Oct 9, 2017
2 parents 2e10f52 + 75c5342 commit 1a77872
Show file tree
Hide file tree
Showing 31 changed files with 1,868 additions and 12 deletions.
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

0 comments on commit 1a77872

Please sign in to comment.