Skip to content

Commit b49228e

Browse files
authored
Merge pull request #89 from commerceguys/php8
Drop PHP7 compatibility.
2 parents 6dad224 + 4c90d45 commit b49228e

24 files changed

+201
-198
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,38 @@ jobs:
99
- uses: actions/checkout@v3
1010
- uses: php-actions/composer@v6
1111

12-
- name: PHPUnit Tests PHP 7.3
12+
- name: PHPUnit Tests PHP 8.0
1313
uses: php-actions/phpunit@master
1414
with:
1515
bootstrap: vendor/autoload.php
1616
configuration: phpunit.xml
1717
args: --coverage-text
1818
php_extensions: xdebug bcmath
19-
php_version: 7.3
20-
version: 9
19+
php_version: 8.0
20+
version: 10
2121
env:
2222
XDEBUG_MODE: coverage
2323

24-
- name: PHPUnit Tests PHP 8.0
24+
- name: PHPUnit Tests PHP 8.1
2525
uses: php-actions/phpunit@master
2626
with:
2727
bootstrap: vendor/autoload.php
2828
configuration: phpunit.xml
2929
args: --coverage-text
3030
php_extensions: xdebug bcmath
31-
php_version: 8.0
32-
version: 9
31+
php_version: 8.1
32+
version: 10
33+
env:
34+
XDEBUG_MODE: coverage
35+
36+
- name: PHPUnit Tests PHP 8.2
37+
uses: php-actions/phpunit@master
38+
with:
39+
bootstrap: vendor/autoload.php
40+
configuration: phpunit.xml
41+
args: --coverage-text
42+
php_extensions: xdebug bcmath
43+
php_version: 8.2
44+
version: 10
3345
env:
3446
XDEBUG_MODE: coverage

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ intl
33

44
[![Build Status](https://github.com/commerceguys/intl/actions/workflows/build.yml/badge.svg)](https://github.com/commerceguys/intl/actions/workflows/build.yml)
55

6-
A PHP 7.3+ internationalization library, powered by CLDR data.
6+
A PHP 8.0+ internationalization library, powered by CLDR data.
77

88
Features:
99
- NumberFormatter and CurrencyFormatter, inspired by [intl](http://php.net/manual/en/class.numberformatter.php).

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
"description": "Internationalization library powered by CLDR data.",
55
"license": "MIT",
66
"require": {
7-
"php": ">=7.3"
7+
"php": ">=8.0"
88
},
99
"require-dev": {
10-
"phpunit/phpunit": "^9.5",
10+
"phpunit/phpunit": "^10",
1111
"mikey179/vfsstream": "1.*"
1212
},
1313
"autoload": {
@@ -30,7 +30,7 @@
3030
],
3131
"extra": {
3232
"branch-alias": {
33-
"dev-master": "1.x-dev"
33+
"dev-master": "2.x-dev"
3434
}
3535
}
3636
}

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" stopOnFailure="false" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
33
<coverage>
44
<include>
55
<directory suffix=".php">./src/</directory>

src/Calculator.php

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class Calculator
2424
*
2525
* @return string The result.
2626
*/
27-
public static function add($first_number, $second_number, $scale = 6)
27+
public static function add(string $first_number, string $second_number, int $scale = 6): string
2828
{
2929
self::assertNumberFormat($first_number);
3030
self::assertNumberFormat($second_number);
@@ -44,7 +44,7 @@ public static function add($first_number, $second_number, $scale = 6)
4444
*
4545
* @return string The result.
4646
*/
47-
public static function subtract($first_number, $second_number, $scale = 6)
47+
public static function subtract(string $first_number, string $second_number, int $scale = 6): string
4848
{
4949
self::assertNumberFormat($first_number);
5050
self::assertNumberFormat($second_number);
@@ -64,7 +64,7 @@ public static function subtract($first_number, $second_number, $scale = 6)
6464
*
6565
* @return string The result.
6666
*/
67-
public static function multiply($first_number, $second_number, $scale = 6)
67+
public static function multiply(string $first_number, string $second_number, int $scale = 6): string
6868
{
6969
self::assertNumberFormat($first_number);
7070
self::assertNumberFormat($second_number);
@@ -84,7 +84,7 @@ public static function multiply($first_number, $second_number, $scale = 6)
8484
*
8585
* @return string The result.
8686
*/
87-
public static function divide($first_number, $second_number, $scale = 6)
87+
public static function divide(string $first_number, string $second_number, int $scale = 6): string
8888
{
8989
self::assertNumberFormat($first_number);
9090
self::assertNumberFormat($second_number);
@@ -100,7 +100,7 @@ public static function divide($first_number, $second_number, $scale = 6)
100100
*
101101
* @return string The result.
102102
*/
103-
public static function ceil($number)
103+
public static function ceil(string $number): string
104104
{
105105
if (self::compare($number, 0) == 1) {
106106
$result = bcadd($number, '1', 0);
@@ -118,7 +118,7 @@ public static function ceil($number)
118118
*
119119
* @return string The result.
120120
*/
121-
public static function floor($number)
121+
public static function floor(string $number): string
122122
{
123123
if (self::compare($number, 0) == 1) {
124124
$result = bcadd($number, '0', 0);
@@ -145,7 +145,7 @@ public static function floor($number)
145145
*
146146
* @throws \InvalidArgumentException
147147
*/
148-
public static function round($number, $precision = 0, $mode = PHP_ROUND_HALF_UP)
148+
public static function round(string $number, int $precision = 0, int $mode = PHP_ROUND_HALF_UP): string
149149
{
150150
self::assertNumberFormat($number);
151151
if (!is_numeric($precision) || $precision < 0) {
@@ -163,7 +163,7 @@ public static function round($number, $precision = 0, $mode = PHP_ROUND_HALF_UP)
163163
// The rounding direction is based on the first decimal after $precision.
164164
$number_parts = explode('.', $number);
165165
$decimals = !empty($number_parts[1]) ? $number_parts[1] : '0';
166-
$relevant_decimal = isset($decimals[$precision]) ? $decimals[$precision] : 0;
166+
$relevant_decimal = $decimals[$precision] ?? 0;
167167
if ($relevant_decimal < 5) {
168168
$number = $rounded_down;
169169
} elseif ($relevant_decimal == 5) {
@@ -197,11 +197,10 @@ public static function round($number, $precision = 0, $mode = PHP_ROUND_HALF_UP)
197197
* @return int 0 if both numbers are equal, 1 if the first one is greater,
198198
* -1 otherwise.
199199
*/
200-
public static function compare($first_number, $second_number, $scale = 6)
200+
public static function compare(string $first_number, string $second_number, int $scale = 6): int
201201
{
202202
self::assertNumberFormat($first_number);
203203
self::assertNumberFormat($second_number);
204-
205204
return bccomp($first_number, $second_number, $scale);
206205
}
207206

@@ -216,7 +215,7 @@ public static function compare($first_number, $second_number, $scale = 6)
216215
*
217216
* @return string The trimmed number.
218217
*/
219-
public static function trim($number)
218+
public static function trim(string $number): string
220219
{
221220
if (strpos($number, '.') != false) {
222221
// The number is decimal, strip trailing zeroes.
@@ -228,20 +227,18 @@ public static function trim($number)
228227
return $number;
229228
}
230229

231-
/**
232-
* Assert that the given number is a numeric string value.
233-
*
234-
* @param string $number The number to check.
235-
*
236-
* @throws \InvalidArgumentException
237-
*/
238-
public static function assertNumberFormat($number)
239-
{
240-
if (is_float($number)) {
241-
throw new \InvalidArgumentException(sprintf('The provided value "%s" must be a string, not a float.', $number));
242-
}
243-
if (!is_numeric($number)) {
244-
throw new \InvalidArgumentException(sprintf('The provided value "%s" is not a numeric value.', $number));
245-
}
246-
}
230+
/**
231+
* Assert that the given number is a numeric string value.
232+
*
233+
* @param string $number The number to check.
234+
*
235+
* @throws \InvalidArgumentException
236+
*/
237+
public static function assertNumberFormat(string $number)
238+
{
239+
if (!is_numeric($number)) {
240+
throw new \InvalidArgumentException(sprintf('The provided value "%s" is not a numeric value.', $number));
241+
}
242+
}
243+
247244
}

src/Currency/Currency.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,42 @@ final class Currency
1212
*
1313
* @var string
1414
*/
15-
protected $currencyCode;
15+
protected string $currencyCode;
1616

1717
/**
1818
* The currency name.
1919
*
2020
* @var string
2121
*/
22-
protected $name;
22+
protected string $name;
2323

2424
/**
2525
* The numeric currency code.
2626
*
2727
* @var string
2828
*/
29-
protected $numericCode;
29+
protected string $numericCode;
3030

3131
/**
3232
* The currency symbol.
3333
*
3434
* @var string
3535
*/
36-
protected $symbol;
36+
protected string $symbol;
3737

3838
/**
3939
* The number of fraction digits.
4040
*
4141
* @var int
4242
*/
43-
protected $fractionDigits = 2;
43+
protected int $fractionDigits = 2;
4444

4545
/**
4646
* The locale (i.e. "en_US").
4747
*
4848
* @var string
4949
*/
50-
protected $locale;
50+
protected string $locale;
5151

5252
/**
5353
* Creates a new Currency instance.
@@ -80,7 +80,7 @@ public function __construct(array $definition)
8080
*
8181
* @return string
8282
*/
83-
public function __toString()
83+
public function __toString(): string
8484
{
8585
return $this->currencyCode;
8686
}
@@ -90,7 +90,7 @@ public function __toString()
9090
*
9191
* @return string
9292
*/
93-
public function getCurrencyCode()
93+
public function getCurrencyCode(): string
9494
{
9595
return $this->currencyCode;
9696
}
@@ -102,7 +102,7 @@ public function getCurrencyCode()
102102
*
103103
* @return string
104104
*/
105-
public function getName()
105+
public function getName(): string
106106
{
107107
return $this->name;
108108
}
@@ -115,7 +115,7 @@ public function getName()
115115
*
116116
* @return string
117117
*/
118-
public function getNumericCode()
118+
public function getNumericCode(): string
119119
{
120120
return $this->numericCode;
121121
}
@@ -127,7 +127,7 @@ public function getNumericCode()
127127
*
128128
* @return string
129129
*/
130-
public function getSymbol()
130+
public function getSymbol(): string
131131
{
132132
return $this->symbol;
133133
}
@@ -140,7 +140,7 @@ public function getSymbol()
140140
*
141141
* @return int
142142
*/
143-
public function getFractionDigits()
143+
public function getFractionDigits(): string
144144
{
145145
return $this->fractionDigits;
146146
}
@@ -152,7 +152,7 @@ public function getFractionDigits()
152152
*
153153
* @return string
154154
*/
155-
public function getLocale()
155+
public function getLocale(): string
156156
{
157157
return $this->locale;
158158
}

0 commit comments

Comments
 (0)