Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Sep 23, 2022
2 parents 5778321 + f029afd commit c26538f
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 120 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[1.1.1]: https://github.com/pronamic/wp-number/compare/1.1.0...1.1.1
# Changelog
All notable changes to this project will be documented in this file.

Expand All @@ -6,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.1.1] - 2022-09-23
- Coding standards.

## [1.1.0] - 2022-01-10
### Changed
- Improved precision support [pronamic/wp-pronamic-pay#281](https://github.com/pronamic/wp-pronamic-pay/issues/281).
Expand All @@ -17,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- First release.

[Unreleased]: https://github.com/pronamic/wp-number/compare/1.1.0...HEAD
[Unreleased]: https://github.com/pronamic/wp-number/compare/1.1.1...HEAD
[1.1.0]: https://github.com/pronamic/wp-number/compare/1.0.1...1.1.0
[1.0.1]: https://github.com/pronamic/wp-number/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/pronamic/wp-number/releases/tag/1.0.0
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"koodimonni/composer-dropin-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"roots/wordpress-core-installer": true,
"bamarni/composer-bin-plugin": true
}
},
"repositories": [
{
Expand Down
4 changes: 2 additions & 2 deletions src/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class Number implements JsonSerializable {
* @psalm-var array<int, class-string<Calculator>>
* @var array<int, string>
*/
private static $calculators = array(
private static $calculators = [
BcMathCalculator::class,
PhpCalculator::class,
);
];

/**
* Construct and initialize number object.
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function parse( $string ) {
$decimal_sep = $wp_locale->number_format['decimal_point'];

// Separators.
$separators = array( $decimal_sep, '.', ',' );
$separators = [ $decimal_sep, '.', ',' ];
$separators = array_unique( array_filter( $separators ) );

// Check.
foreach ( array( - 3, - 2 ) as $i ) {
foreach ( [ - 3, - 2 ] as $i ) {
$test = substr( $string, $i, 1 );

if ( in_array( $test, $separators, true ) ) {
Expand Down Expand Up @@ -71,7 +71,7 @@ public function parse( $string ) {
*
* @link https://taaladvies.net/taal/advies/vraag/275/euro_komma_en_streepje_in_de_notatie_van_hele_bedragen/
*/
if ( \in_array( $half, array( '-', '', '' ), true ) ) {
if ( \in_array( $half, [ '-', '', '' ], true ) ) {
$half = '';
}

Expand Down
104 changes: 52 additions & 52 deletions tests/src/NumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,16 @@ public function test_from_float( $value, $expected ) {
* @return array
*/
public function data_provider_from_float() {
return array(
array( 0.0, '0' ),
array( 0.12345678, '0.12345678' ),
array( 123.456789, '123.456789' ),
array( 0.123456789, '0.123456789' ),
array( 0.123456789123456789, \version_compare( \PHP_VERSION, '7.1', '<' ) ? '0.12345678912346' : '0.12345678912345678' ),
array( 123456.789, '123456.789' ),
array( 123456.78, '123456.78' ),
array( 12345678901.123456789123456789, \version_compare( \PHP_VERSION, '7.1', '<' ) ? '12345678901.123' : '12345678901.123457' ),
);
return [
[ 0.0, '0' ],
[ 0.12345678, '0.12345678' ],
[ 123.456789, '123.456789' ],
[ 0.123456789, '0.123456789' ],
[ 0.123456789123456789, \version_compare( \PHP_VERSION, '7.1', '<' ) ? '0.12345678912346' : '0.12345678912345678' ],
[ 123456.789, '123456.789' ],
[ 123456.78, '123456.78' ],
[ 12345678901.123456789123456789, \version_compare( \PHP_VERSION, '7.1', '<' ) ? '12345678901.123' : '12345678901.123457' ],
];
}

/**
Expand Down Expand Up @@ -283,25 +283,25 @@ public function test_php_is_numeric_examples( $value, $expected ) {
* @return array
*/
public function provider_php_is_numeric_examples() {
$data = array(
array( '42', '42' ),
array( 1337, '1337' ),
array( 0x539, '1337' ), // Hexadecimal number.
array( 02471, '1337' ), // Octal number.
array( 0b10100111001, '1337' ), // Binary number.
array( 1337e0, '1337' ),
array( '02471', '02471' ),
array( '1337e0', '1337e0' ),
array( 9.1, '9.1' ),
);
$data = [
[ '42', '42' ],
[ 1337, '1337' ],
[ 0x539, '1337' ], // Hexadecimal number.
[ 02471, '1337' ], // Octal number.
[ 0b10100111001, '1337' ], // Binary number.
[ 1337e0, '1337' ],
[ '02471', '02471' ],
[ '1337e0', '1337e0' ],
[ 9.1, '9.1' ],
];

/**
* On PHP version before 7 it seems that '0x539' is
* numeric.
*/
if ( \version_compare( \PHP_VERSION, '7', '<' ) ) {
// phpcs:ignore PHPCompatibility.Miscellaneous.ValidIntegers.HexNumericStringFound
$data[] = array( '0x539', '0x539' );
$data[] = [ '0x539', '0x539' ];
}

return $data;
Expand All @@ -326,22 +326,22 @@ public function test_php_not_numeric_examples( $value ) {
* @return array
*/
public function provider_php_not_numeric_examples() {
$data = array(
array( '0b10100111001' ),
array( 'not numeric' ),
array( array() ),
array( null ),
array( '' ),
array( '-' ),
);
$data = [
[ '0b10100111001' ],
[ 'not numeric' ],
[ [] ],
[ null ],
[ '' ],
[ '-' ],
];

/**
* On PHP version after 5.6 it seems that '0x539' is
* not numeric.
*/
if ( version_compare( \PHP_VERSION, '7', '>=' ) ) {
// phpcs:ignore PHPCompatibility.Miscellaneous.ValidIntegers.HexNumericStringFound
$data[] = array( '0x539' );
$data[] = [ '0x539' ];
}

return $data;
Expand Down Expand Up @@ -370,11 +370,11 @@ public function test_php_abs_examples( $value, $expected ) {
* @return array
*/
public function provider_php_abs_examples() {
return array(
array( -4.2, '4.2' ),
array( 5, '5' ),
array( -5, '5' ),
);
return [
[ -4.2, '4.2' ],
[ 5, '5' ],
[ -5, '5' ],
];
}

/**
Expand Down Expand Up @@ -433,7 +433,7 @@ public function test_calculator() {

$calculators = $calculators_property->getValue();

$calculators_property->setValue( array() );
$calculators_property->setValue( [] );

$number_1 = new Number( '1' );
$number_2 = new Number( '2' );
Expand Down Expand Up @@ -476,19 +476,19 @@ public function test_format_i18n( $locale, $decimals, $value, $expected ) {
* @return array
*/
public function format_i18n_provider() {
return array(
return [
// Dutch.
array( 'nl_NL', 2, 49.7512, '49,75' ),
array( 'nl_NL', 4, 49.7512, '49,7512' ),
array( 'nl_NL', 2, 1234567890.1234, '1.234.567.890,12' ),
[ 'nl_NL', 2, 49.7512, '49,75' ],
[ 'nl_NL', 4, 49.7512, '49,7512' ],
[ 'nl_NL', 2, 1234567890.1234, '1.234.567.890,12' ],

// English.
array( 'en_US', 2, 49.7512, '49.75' ),
array( 'en_US', 2, 1234567890.1234, '1,234,567,890.12' ),
[ 'en_US', 2, 49.7512, '49.75' ],
[ 'en_US', 2, 1234567890.1234, '1,234,567,890.12' ],

// French.
array( 'fr_FR', 2, 1234567890.1234, '1 234 567 890,12' ),
);
[ 'fr_FR', 2, 1234567890.1234, '1 234 567 890,12' ],
];
}

/**
Expand All @@ -510,13 +510,13 @@ public function test_intval( $value, $expected ) {
* @return array
*/
public function provider_test_to_int() {
return array(
array( '50', 50 ),
array( '123.45', 123 ),
array( '123.56', 123 ),
array( '123.99', 123 ),
array( '-10', -10 ),
);
return [
[ '50', 50 ],
[ '123.45', 123 ],
[ '123.56', 123 ],
[ '123.99', 123 ],
[ '-10', -10 ],
];
}

/**
Expand Down
122 changes: 61 additions & 61 deletions tests/src/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,75 +69,75 @@ public function test_string_to_amount( $thousands_sep, $decimal_sep, $string, $e
* @return array
*/
public function string_to_amount_provider() {
return array(
return [
// Thousands separator is '' and decimal separator is '.'.
array( '', '.', '1', '1' ),
array( '', '.', '2,5', '2.5' ),
array( '', '.', '2,50', '2.5' ),
array( '', '.', '1250,00', '1250' ),
array( '', '.', '1250,75', '1250.75' ),
array( '', '.', '1250.75', '1250.75' ),
array( '', '.', '1.250,00', '1250' ),
array( '', '.', '2.500,75', '2500.75' ),
array( '', '.', '2500,75-', '-2500.75' ),
array( '', '.', '-2500,75', '-2500.75' ),
array( '', '.', '2500-', '-2500' ),
array( '', '.', '-2500', '-2500' ),
array( '', '.', '1-', '-1' ),
[ '', '.', '1', '1' ],
[ '', '.', '2,5', '2.5' ],
[ '', '.', '2,50', '2.5' ],
[ '', '.', '1250,00', '1250' ],
[ '', '.', '1250,75', '1250.75' ],
[ '', '.', '1250.75', '1250.75' ],
[ '', '.', '1.250,00', '1250' ],
[ '', '.', '2.500,75', '2500.75' ],
[ '', '.', '2500,75-', '-2500.75' ],
[ '', '.', '-2500,75', '-2500.75' ],
[ '', '.', '2500-', '-2500' ],
[ '', '.', '-2500', '-2500' ],
[ '', '.', '1-', '-1' ],
// Thousands separator is '.' and decimal separator is ','.
array( '.', ',', '1', '1' ),
array( '.', ',', '2,5', '2.5' ),
array( '.', ',', '2,50', '2.5' ),
array( '.', ',', '1250,00', '1250' ),
array( '.', ',', '2500,75', '2500.75' ),
array( '.', ',', '1.250,00', '1250' ),
array( '.', ',', '2.500,75', '2500.75' ),
array( '.', ',', '2.500,750', '2500.75' ),
array( '.', ',', '1.234.567.890', '1234567890' ),
array( '.', ',', '2.500,75-', '-2500.75' ),
array( '.', ',', '-2.500,75', '-2500.75' ),
array( '.', ',', '2.500-', '-2500' ),
array( '.', ',', '-2.500', '-2500' ),
array( '.', ',', '1-', '-1' ),
[ '.', ',', '1', '1' ],
[ '.', ',', '2,5', '2.5' ],
[ '.', ',', '2,50', '2.5' ],
[ '.', ',', '1250,00', '1250' ],
[ '.', ',', '2500,75', '2500.75' ],
[ '.', ',', '1.250,00', '1250' ],
[ '.', ',', '2.500,75', '2500.75' ],
[ '.', ',', '2.500,750', '2500.75' ],
[ '.', ',', '1.234.567.890', '1234567890' ],
[ '.', ',', '2.500,75-', '-2500.75' ],
[ '.', ',', '-2.500,75', '-2500.75' ],
[ '.', ',', '2.500-', '-2500' ],
[ '.', ',', '-2.500', '-2500' ],
[ '.', ',', '1-', '-1' ],
// Thousands separator is ',' and decimal separator is '.'.
array( ',', '.', '1', '1' ),
array( ',', '.', '2.5', '2.5' ),
array( ',', '.', '2.50', '2.5' ),
array( ',', '.', '1250.00', '1250' ),
array( ',', '.', '1250.75', '1250.75' ),
array( ',', '.', '1,250.00', '1250' ),
array( ',', '.', '2,500.75', '2500.75' ),
array( ',', '.', '2,500.', '2500' ),
array( ',', '.', '2,500.75-', '-2500.75' ),
array( ',', '.', '-2,500.75', '-2500.75' ),
array( ',', '.', '2,500-', '-2500' ),
array( ',', '.', '-2,500', '-2500' ),
array( ',', '.', '1-', '-1' ),
[ ',', '.', '1', '1' ],
[ ',', '.', '2.5', '2.5' ],
[ ',', '.', '2.50', '2.5' ],
[ ',', '.', '1250.00', '1250' ],
[ ',', '.', '1250.75', '1250.75' ],
[ ',', '.', '1,250.00', '1250' ],
[ ',', '.', '2,500.75', '2500.75' ],
[ ',', '.', '2,500.', '2500' ],
[ ',', '.', '2,500.75-', '-2500.75' ],
[ ',', '.', '-2,500.75', '-2500.75' ],
[ ',', '.', '2,500-', '-2500' ],
[ ',', '.', '-2,500', '-2500' ],
[ ',', '.', '1-', '-1' ],
// Thousands separator is ' ' and decimal separator is '.'.
array( ' ', '.', '2 500.75', '2500.75' ),
[ ' ', '.', '2 500.75', '2500.75' ],
// Thousands separator is 't' and decimal separator is '.'.
array( 't', '.', '2t500.75', '2500.75' ),
array( 't', '.', '2t500.7', '2500.7' ),
[ 't', '.', '2t500.75', '2500.75' ],
[ 't', '.', '2t500.7', '2500.7' ],
// Thousands separator is 't' and decimal separator is '-'.
array( 't', '-', '2t500-75', '2500.75' ),
array( 't', '-', '2t500-7', '2500.7' ),
[ 't', '-', '2t500-75', '2500.75' ],
[ 't', '-', '2t500-7', '2500.7' ],
// Thousands separator is 't' and decimal separator is ' '.
array( 't', ' ', '2t500 75', '2500.75' ),
array( 't', ' ', '2t500 7', '2500.7' ),
[ 't', ' ', '2t500 75', '2500.75' ],
[ 't', ' ', '2t500 7', '2500.7' ],
// Thousands separator is ' ' and decimal separator is 'd'.
array( ' ', 'd', '2 500d75', '2500.75' ),
array( ' ', 'd', '2 500d7', '2500.7' ),
array( ' ', 'd', '-2 500d75', '-2500.75' ),
array( ' ', 'd', '-2 500d7', '-2500.7' ),
[ ' ', 'd', '2 500d75', '2500.75' ],
[ ' ', 'd', '2 500d7', '2500.7' ],
[ ' ', 'd', '-2 500d75', '-2500.75' ],
[ ' ', 'd', '-2 500d7', '-2500.7' ],
// Other.
array( '.', ',', 'EUR 1.250', '1250' ),
array( '.', ',', 'EUR 1.250,75', '1250.75' ),
array( '.', ',', 'EUR -1.250', '-1250' ),
array( '.', ',', 'EUR -1.250,75', '-1250.75' ),
array( '.', ',', '1.250,-', '1250' ),
array( '.', ',', '-1.250,-', '-1250' ),
array( '', '', '123456789', '123456789' ),
array( false, false, '123 456 789', '123456789' ),
);
[ '.', ',', 'EUR 1.250', '1250' ],
[ '.', ',', 'EUR 1.250,75', '1250.75' ],
[ '.', ',', 'EUR -1.250', '-1250' ],
[ '.', ',', 'EUR -1.250,75', '-1250.75' ],
[ '.', ',', '1.250,-', '1250' ],
[ '.', ',', '-1.250,-', '-1250' ],
[ '', '', '123456789', '123456789' ],
[ false, false, '123 456 789', '123456789' ],
];
}
}

0 comments on commit c26538f

Please sign in to comment.