Completed
Pull Request — master (#86)
by Scott
01:49
created

Language   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 10 1
providesLanguages() 0 1 ?
specialNumbers() 0 1 ?
1
<?php
2
3
namespace Povils\PHPMND;
4
5
use NumberFormatter;
6
7
abstract class Language
8
{
9
    /**
10
     * @var NumberFormatter
11
     */
12
    protected $formatter;
13
14
    public function __construct($language)
15
    {
16
        $this->formatter = new NumberFormatter($language, NumberFormatter::SPELLOUT);
17
    }
18
19
    /*
20
     * Returns an array of words which
21
     */
22
    public function parse(int $number): array
23
    {
24
        $words = $this->specialNumbers()[$number] ?? [];
25
        $formatted = $this->formatter->format($number);
26
27
        $formatted = str_replace(['-', ','], ' ', $formatted);
28
        $formatted = explode(' ', $formatted);
29
30
        return array_merge($words, $formatted);
31
    }
32
33
    abstract public static function providesLanguages(): array;
34
35
    abstract public function specialNumbers(): array;
36
}
37