InflectionOrdinalizeTrait::doOrdinalize()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
nc 5
nop 1
dl 0
loc 17
ccs 0
cts 11
cp 0
crap 30
rs 9.4555
c 1
b 0
f 0
1
<?php
2
3
namespace Nip\Inflector\Traits;
4
5
/**
6
 * Trait InflectionOrdinalizeTrait
7
 * @package Nip\Inflector\Traits
8
 *
9
 * @method ordinalize($string)
10
 */
11
trait InflectionOrdinalizeTrait
12
{
13
14
15
    /**
16
     * @param $number
17
     * @return string
18
     */
19
    protected function doOrdinalize($number)
20
    {
21
        if (in_array(($number % 100), range(11, 13))) {
22
            return $number . 'th';
23
        } else {
24
            switch (($number % 10)) {
25
                case 1:
26
                    return $number . 'st';
27
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
28
                case 2:
29
                    return $number . 'nd';
30
                    break;
31
                case 3:
32
                    return $number . 'rd';
33
                default:
34
                    return $number . 'th';
35
                    break;
36
            }
37
        }
38
    }
39
}
40