Skip to content

Commit

Permalink
Sanity check for NumberFormatter when intl is not installed (#91)
Browse files Browse the repository at this point in the history
* added sanity check for NumberFormatter class when intl extension is not installed

* Update MetricSuffix.php

* Update BinarySuffix.php
  • Loading branch information
thunderer authored and norberttech committed Feb 25, 2019
1 parent 17a5ab5 commit 2710e07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Coduo/PHPHumanizer/String/BinarySuffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ final class BinarySuffix
*/
public function __construct($number, $locale = 'en', $precision = null)
{
if (!\class_exists('NumberFormatter')) {
throw new \RuntimeException('Binary suffix converter requires intl extension!');
}

if (!\is_numeric($number)) {
throw new \InvalidArgumentException('Binary suffix converter accept only numeric values.');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Coduo/PHPHumanizer/String/MetricSuffix.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ final class MetricSuffix
*/
public function __construct($number, $locale = 'en')
{
if (!\class_exists('NumberFormatter')) {
throw new \RuntimeException('Metric suffix converter requires intl extension!');
}

if (!\is_numeric($number)) {
throw new \InvalidArgumentException('Metric suffix converter accept only numeric values.');
}
Expand Down

0 comments on commit 2710e07

Please sign in to comment.