Skip to content

Commit

Permalink
Fixed coding standard errors for PhpUnitsOfMeasure#62
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolocira committed Dec 5, 2016
1 parent a8ddf71 commit 6a22a9c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 65 deletions.
32 changes: 17 additions & 15 deletions source/AbstractPhysicalQuantity.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,26 +214,28 @@ public function isEquivalentQuantity(PhysicalQuantityInterface $testQuantity)
/**
* @see \PhpUnitsOfMeasure\PhysicalQuantityInterface::isUnitDefined
*/
public static function isUnitDefined($name) {
$units = static::getUnitDefinitions();
foreach ($units as $unit) {
if ($name === $unit->getName() || $unit->isAliasOf($name)) {
return true;
}
}
return false;
public static function isUnitDefined($name)
{
$units = static::getUnitDefinitions();
foreach ($units as $unit) {
if ($name === $unit->getName() || $unit->isAliasOf($name)) {
return true;
}
}
return false;
}

/**
* @see \PhpUnitsOfMeasure\PhysicalQuantityInterface::listAllUnits
*/
public static function listAllUnits() {
$return = array();
$units = static::getUnitDefinitions();
foreach ($units as $unit) {
$return[$unit->getName()] = $unit->getAliases();
}
return $return;
public static function listAllUnits()
{
$return = array();
$units = static::getUnitDefinitions();
foreach ($units as $unit) {
$return[$unit->getName()] = $unit->getAliases();
}
return $return;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions source/PhysicalQuantityInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ public function isEquivalentQuantity(PhysicalQuantityInterface $testQuantity);
/**
* Verify if the given value respond to an already defined unit of meaure of the current
* phisical quantity.
*
*
* @param string $name the string to verify
*
*
* @return boolean True if $name has been defined into the current physical quantity, false if not.
*/
public static function isUnitDefined($name);

/**
* Return a list of all the unit of measure defined in the current physical quantity
*
*
* @return array of all units as strings.
* Keys of the array are the units of measure; for any key the value is
* another array containing all aliases.
* Keys of the array are the units of measure; for any key the value is
* another array containing all aliases.
*/
public static function listAllUnits();
}
90 changes: 45 additions & 45 deletions tests/AbstractPhysicalQuantityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ protected function getTestUnitOfMeasure($name, $aliases = [])
*/
protected function getTestUnitOfMeasureSafe($name, $aliases = [])
{
$newUnit = new UnitOfMeasure(
$name,
function ($valueInNativeUnit) {
return $valueInNativeUnit / 1;
},
function ($valueInThisUnit) {
return $valueInThisUnit * 1;
}
);
foreach ($aliases as $alias) {
$newUnit->addAlias($alias);
}
return $newUnit;
$newUnit = new UnitOfMeasure(
$name,
function ($valueInNativeUnit) {
return $valueInNativeUnit / 1;
},
function ($valueInThisUnit) {
return $valueInThisUnit * 1;
}
);
foreach ($aliases as $alias) {
$newUnit->addAlias($alias);
}
return $newUnit;
}

/**
Expand Down Expand Up @@ -245,45 +245,45 @@ public function testGetAllUnits()
*/
public function testIsUnitDefined()
{
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);
$someExistingUnits = array('u', 'uvees', 'v', 'vorp', 'noconflict', 'definitelynoconflict_1', 'definitelynoconflict_2');
$unexistingUnits = array('kg', 'l', 'definitelynoconflict_');
foreach ($someExistingUnits as $someExistingUnit) {
$this->assertTrue(Wonkicity::isUnitDefined($someExistingUnit));
}
foreach ($unexistingUnits as $unexistingUnit) {
$this->assertFalse(Wonkicity::isUnitDefined($unexistingUnit));
}
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);
$someExistingUnits = array('u', 'uvees', 'v', 'vorp', 'noconflict', 'definitelynoconflict_1', 'definitelynoconflict_2');
$unexistingUnits = array('kg', 'l', 'definitelynoconflict_');
foreach ($someExistingUnits as $someExistingUnit) {
$this->assertTrue(Wonkicity::isUnitDefined($someExistingUnit));
}
foreach ($unexistingUnits as $unexistingUnit) {
$this->assertFalse(Wonkicity::isUnitDefined($unexistingUnit));
}
}

/**
* @covers \PhpUnitsOfMeasure\AbstractPhysicalQuantity::listAllUnits
*/
public function testListAllUnits()
{
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);
$allUnits = Wonkicity::listAllUnits();
$expected = array(
'u' => array('uvee', 'uvees'),
'v' => array('vorp', 'vorps'),
'noconflict' => array('definitelynoconflict_1', 'definitelynoconflict_2'),
);
$this->assertEquals($allUnits, $expected);
/* The following code still doesn't work: see #63.
* It is possible to enable this line (instead of the line after) to verify if #63 has been closed
$newUnit = $this->getTestUnitOfMeasure('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
*/
$newUnit = $this->getTestUnitOfMeasureSafe('noconflict', ['definitelynoconflict_1', 'definitelynoconflict_2']);
Wonkicity::addUnit($newUnit);
$allUnits = Wonkicity::listAllUnits();
$expected = array(
'u' => array('uvee', 'uvees'),
'v' => array('vorp', 'vorps'),
'noconflict' => array('definitelynoconflict_1', 'definitelynoconflict_2'),
);
$this->assertEquals($allUnits, $expected);
}

/**
Expand Down

0 comments on commit 6a22a9c

Please sign in to comment.