Passed
Push — develop ( 0b3512...4ec848 )
by BENARD
04:21
created

GetOrdinalSuffixTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 11
c 1
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getOrdinalSuffix() 0 16 8
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Traits;
4
5
trait GetOrdinalSuffixTrait
6
{
7
    /**
8
     * @param $number
9
     * @return string
10
     */
11
    private function getOrdinalSuffix($number): string
12
    {
13
        if ($number <= 0) {
14
            return '';
15
        }
16
        $number %= 100;
17
        if ($number != 11 && ($number % 10) == 1) {
18
            return 'st';
19
        }
20
        if ($number != 12 && ($number % 10) == 2) {
21
            return 'nd';
22
        }
23
        if ($number != 13 && ($number % 10) == 3) {
24
            return 'rd';
25
        }
26
        return 'th';
27
    }
28
}
29