From 7e831763e5446bc320e763c2b01a08c7d9d115fd Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 14 Dec 2019 21:39:31 +0100 Subject: [PATCH] more final and edge case fixes --- Utils/Converter/Currency.php | 24 ++++++++++++++---------- Utils/Converter/File.php | 2 +- Utils/Converter/Ip.php | 2 +- Utils/Converter/Measurement.php | 2 +- Utils/Converter/Numeric.php | 2 +- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Utils/Converter/Currency.php b/Utils/Converter/Currency.php index 1a952d7b9..74b41e8b7 100644 --- a/Utils/Converter/Currency.php +++ b/Utils/Converter/Currency.php @@ -28,7 +28,7 @@ use phpOMS\Uri\Http; * @link https://orange-management.org * @since 1.0.0 */ -class Currency +final class Currency { /** @@ -98,21 +98,25 @@ class Currency */ 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->setMethod(RequestMethod::GET); - $xml = new \SimpleXMLElement(Rest::request($request)->getBody()); + try { + $xml = new \SimpleXMLElement(Rest::request($request)->getBody()); - if (!isset($xml->Cube)) { - throw new \Exception('Invalid xml path'); - } + if (!isset($xml->Cube)) { + throw new \Exception('Invalid xml path'); + } - $node = $xml->Cube->Cube->Cube; - self::$ecbCurrencies = []; + $node = $xml->Cube->Cube->Cube; + self::$ecbCurrencies = []; - foreach ($node as $key => $value) { - self::$ecbCurrencies[\strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate']; + foreach ($node as $key => $value) { + self::$ecbCurrencies[\strtoupper((string) $value->attributes()['currency'])] = (float) $value->attributes()['rate']; + } + } catch (\Throwable $t) { + self::$ecbCurrencies = []; } } diff --git a/Utils/Converter/File.php b/Utils/Converter/File.php index 00dd088b8..605b33dab 100644 --- a/Utils/Converter/File.php +++ b/Utils/Converter/File.php @@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter; * @link https://orange-management.org * @since 1.0.0 */ -class File +final class File { /** diff --git a/Utils/Converter/Ip.php b/Utils/Converter/Ip.php index e83482ea2..b9f0cb03f 100644 --- a/Utils/Converter/Ip.php +++ b/Utils/Converter/Ip.php @@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter; * @link https://orange-management.org * @since 1.0.0 */ -class Ip +final class Ip { public const IP_TABLE_ITERATIONS = 100; diff --git a/Utils/Converter/Measurement.php b/Utils/Converter/Measurement.php index 92d31cbac..9fea1ab83 100644 --- a/Utils/Converter/Measurement.php +++ b/Utils/Converter/Measurement.php @@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter; * @link https://orange-management.org * @since 1.0.0 */ -class Measurement +final class Measurement { /** * Constructor. diff --git a/Utils/Converter/Numeric.php b/Utils/Converter/Numeric.php index 40047af72..b4a887f6e 100644 --- a/Utils/Converter/Numeric.php +++ b/Utils/Converter/Numeric.php @@ -22,7 +22,7 @@ namespace phpOMS\Utils\Converter; * @link https://orange-management.org * @since 1.0.0 */ -class Numeric +final class Numeric { /**