Passed
Pull Request — master (#39)
by Alexander
02:20 queued 01:01
created

NumericHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toOrdinal() 0 14 5
1
<?php
2
3
namespace Yiisoft\Strings;
4
5
final class NumericHelper
6
{
7
    /**
8
     * Converts number to its ordinal English form. For example, converts 13 to 13th, 2 to 2nd ...
9
     * @param int $number The number to get its ordinal value.
10
     * @return string
11
     */
12 1
    public static function toOrdinal(int $number): ?string
13
    {
14 1
        if (\in_array($number % 100, range(11, 13), true)) {
15 1
            return $number . 'th';
16
        }
17 1
        switch ($number % 10) {
18 1
            case 1:
19 1
                return $number . 'st';
20 1
            case 2:
21 1
                return $number . 'nd';
22 1
            case 3:
23 1
                return $number . 'rd';
24
            default:
25 1
                return $number . 'th';
26
        }
27
    }
28
}
29