more final and edge case fixes

This commit is contained in:
Dennis Eichhorn 2019-12-14 21:39:31 +01:00
parent 150f86df4a
commit 7e831763e5
5 changed files with 18 additions and 14 deletions

View File

@ -28,7 +28,7 @@ use phpOMS\Uri\Http;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class Currency final class Currency
{ {
/** /**
@ -98,21 +98,25 @@ class Currency
*/ */
public static function getEcbEuroRates() : array public static function getEcbEuroRates() : array
{ {
if (!isset(self::$ecbCurrencies)) { if (!empty(self::$ecbCurrencies)) {
$request = new Request(new Http('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')); $request = new Request(new Http('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'));
$request->setMethod(RequestMethod::GET); $request->setMethod(RequestMethod::GET);
$xml = new \SimpleXMLElement(Rest::request($request)->getBody()); try {
$xml = new \SimpleXMLElement(Rest::request($request)->getBody());
if (!isset($xml->Cube)) { if (!isset($xml->Cube)) {
throw new \Exception('Invalid xml path'); throw new \Exception('Invalid xml path');
} }
$node = $xml->Cube->Cube->Cube; $node = $xml->Cube->Cube->Cube;
self::$ecbCurrencies = []; self::$ecbCurrencies = [];
foreach ($node as $key => $value) { foreach ($node as $key => $value) {
self::$ecbCurrencies[\strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate']; self::$ecbCurrencies[\strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate'];
}
} catch (\Throwable $t) {
self::$ecbCurrencies = [];
} }
} }

View File

@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class File final class File
{ {
/** /**

View File

@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class Ip final class Ip
{ {
public const IP_TABLE_ITERATIONS = 100; public const IP_TABLE_ITERATIONS = 100;

View File

@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class Measurement final class Measurement
{ {
/** /**
* Constructor. * Constructor.

View File

@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
class Numeric final class Numeric
{ {
/** /**