Skip to content

Commit 2710e07

Browse files
thunderernorberttech
authored andcommitted
Sanity check for NumberFormatter when intl is not installed (#91)
* added sanity check for NumberFormatter class when intl extension is not installed * Update MetricSuffix.php * Update BinarySuffix.php
1 parent 17a5ab5 commit 2710e07

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/Coduo/PHPHumanizer/String/BinarySuffix.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ final class BinarySuffix
3939
*/
4040
public function __construct($number, $locale = 'en', $precision = null)
4141
{
42+
if (!\class_exists('NumberFormatter')) {
43+
throw new \RuntimeException('Binary suffix converter requires intl extension!');
44+
}
45+
4246
if (!\is_numeric($number)) {
4347
throw new \InvalidArgumentException('Binary suffix converter accept only numeric values.');
4448
}

src/Coduo/PHPHumanizer/String/MetricSuffix.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ final class MetricSuffix
3838
*/
3939
public function __construct($number, $locale = 'en')
4040
{
41+
if (!\class_exists('NumberFormatter')) {
42+
throw new \RuntimeException('Metric suffix converter requires intl extension!');
43+
}
44+
4145
if (!\is_numeric($number)) {
4246
throw new \InvalidArgumentException('Metric suffix converter accept only numeric values.');
4347
}

0 commit comments

Comments
 (0)