Completed
Push — master ( 622740...e78b73 )
by f
01:58
created

src/English/CardinalNumeralGenerator.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace morphos\English;
3
4
use morphos\NumeralGenerator;
5
6
class CardinalNumeralGenerator extends NumeralGenerator
7
{
8
    public static $words = [
9
        1 => 'one',
10
        2 => 'two',
11
        3 => 'three',
12
        4 => 'four',
13
        5 => 'five',
14
        6 => 'six',
15
        7 => 'seven',
16
        8 => 'eight',
17
        9 => 'nine',
18
        10 => 'ten',
19
        11 => 'eleven',
20
        12 => 'twelve',
21
        13 => 'thirteen',
22
        14 => 'fourteen',
23
        15 => 'fifteen',
24
        16 => 'sixteen',
25
        17 => 'seventeen',
26
        18 => 'eighteen',
27
        19 => 'nineteen',
28
        20 => 'twenty',
29
        30 => 'thirty',
30
        40 => 'forty',
31
        50 => 'fifty',
32
        60 => 'sixty',
33
        70 => 'seventy',
34
        80 => 'eighty',
35
        90 => 'ninety',
36
    ];
37
38
    public static $exponents = [
39
        '100' => 'hundred',
40
        '1000' => 'thousand',
41
        '1000000' => 'million',
42
        '1000000000' => 'billion',
43
        '1000000000000' => 'trillion',
44
    ];
45
46
    public static function getCases($number)
47
    {
48
    }
49
50
    public static function getCase($number, $case)
51
    {
52
    }
53
54
    /**
55
     * @param $number
56
     * @return mixed|string
57
     */
58 6
    public static function generate($number)
59
    {
60
        // simple numeral
61 6
        if (isset(self::$words[$number]) || isset(self::$exponents[$number])) {
62 6
            return isset(self::$words[$number]) ? self::$words[$number] : self::$exponents[$number];
63
        }
64
        // compound numeral
65
        else {
66 5
            $parts = [];
67 5
            $words = [];
68
69 5 View Code Duplication
            foreach (array_reverse(self::$exponents, true) as $word_number => $word) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70 5
                if ($number >= $word_number) {
71 5
                    $count = floor($number / $word_number);
72 5
                    $number = $number % ($count * $word_number);
73 5
                    $parts[] = self::generate($count).' '.self::generate($word_number).($word_number != 100 && $number > 0 ? ',' : null);
74
                }
75
            }
76
77 5 View Code Duplication
            foreach (array_reverse(self::$words, true) as $word_number => $word) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78 5
                if ($number >= $word_number) {
79 5
                    $words[] = self::generate($word_number);
80 5
                    $number %= $word_number;
81
                }
82
            }
83 5
            $parts[] = implode('-', $words);
84
85 5
            return implode(' ', $parts);
86
        }
87
    }
88
}
89