Skip to content

Commit 4406e7e

Browse files
authored
Fix #44: NumericHelper::toOrdinal throws an error for numbers with fractional part
1 parent 6da49ba commit 4406e7e

File tree

8 files changed

+27
-385
lines changed

8 files changed

+27
-385
lines changed

.github/workflows/static.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ jobs:
4646
- name: Install dependencies with composer
4747
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
4848

49-
- name: Static analysis with phan
50-
run: vendor/bin/phan --no-progress-bar --output-mode checkstyle | cs2pr --graceful-warnings --colorize
49+
- name: Static analysis with psalm
50+
run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle | cs2pr --graceful-warnings --colorize

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,3 @@ phpunit.phar
2929
/phpunit.xml
3030
# phpunit cache
3131
.phpunit.result.cache
32-
33-
# Phan
34-
analysis.txt
35-

.phan/config.php

Lines changed: 0 additions & 374 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Yii String Change Log
1+
# Yii Strings Change Log
2+
3+
## 1.0.2 under development
4+
5+
- Bug #44: `NumericHelper::toOrdinal` throws an error for numbers with fractional part (vjik)
26

37
## 1.0.1 October 12, 2020
48

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"ext-mbstring": "*"
2222
},
2323
"require-dev": {
24-
"infection/infection": "^0.17.0",
25-
"phan/phan": "^3.0",
26-
"phpunit/phpunit": "^9.3"
24+
"infection/infection": "^0.16.6 || ^0.17.7",
25+
"phpunit/phpunit": "^9.4",
26+
"vimeo/psalm": "^3.17"
2727
},
2828
"autoload": {
2929
"psr-4": {

psalm.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="6"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
>
9+
<projectFiles>
10+
<directory name="src" />
11+
<ignoreFiles>
12+
<directory name="vendor" />
13+
</ignoreFiles>
14+
</projectFiles>
15+
</psalm>

src/NumericHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function toOrdinal($value): string
2222
}
2323

2424
if (fmod((float)$value, 1) !== 0.00) {
25-
return $value;
25+
return (string)$value;
2626
}
2727

2828
if (\in_array($value % 100, [11, 12, 13], true)) {

tests/NumericHelperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function testToOrdinal(): void
2323
$this->assertEquals('25th', NumericHelper::toOrdinal(25));
2424
$this->assertEquals('111th', NumericHelper::toOrdinal(111));
2525
$this->assertEquals('113th', NumericHelper::toOrdinal(113));
26+
$this->assertEquals('2.01', NumericHelper::toOrdinal(2.01));
2627

2728
$this->assertEquals('42nd', NumericHelper::toOrdinal('42'));
2829
$this->assertEquals('3.1415926', NumericHelper::toOrdinal('3.1415926'));

0 commit comments

Comments
 (0)