From 6a22a9c5df21a4d3c568d10c88d5e9c7225ff376 Mon Sep 17 00:00:00 2001 From: pierpaolocira Date: Mon, 5 Dec 2016 22:54:57 +0100 Subject: [PATCH] Fixed coding standard errors for #62 --- source/AbstractPhysicalQuantity.php | 32 ++++----- source/PhysicalQuantityInterface.php | 10 +-- tests/AbstractPhysicalQuantityTest.php | 90 +++++++++++++------------- 3 files changed, 67 insertions(+), 65 deletions(-) diff --git a/source/AbstractPhysicalQuantity.php b/source/AbstractPhysicalQuantity.php index 607ef28..568b7fa 100644 --- a/source/AbstractPhysicalQuantity.php +++ b/source/AbstractPhysicalQuantity.php @@ -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; } /** diff --git a/source/PhysicalQuantityInterface.php b/source/PhysicalQuantityInterface.php index c1e8ef9..8f9071e 100644 --- a/source/PhysicalQuantityInterface.php +++ b/source/PhysicalQuantityInterface.php @@ -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(); } diff --git a/tests/AbstractPhysicalQuantityTest.php b/tests/AbstractPhysicalQuantityTest.php index bed713f..e6d066a 100644 --- a/tests/AbstractPhysicalQuantityTest.php +++ b/tests/AbstractPhysicalQuantityTest.php @@ -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; } /** @@ -245,23 +245,23 @@ 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)); + } } /** @@ -269,21 +269,21 @@ public function testIsUnitDefined() */ 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); } /**