Completed
Push — master ( 2f74f3...29426d )
by Samson
02:55
created

Converter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 83
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isZero() 0 4 1
convert() 0 1 ?
A isGeezNumberHundred() 0 4 1
A isGeezNumber() 0 4 1
A isGeezNumberOne() 0 4 1
A isGeezNumberTenThousand() 0 4 1
1
<?php
2
3
namespace Geezify\Converter;
4
5
/**
6
 * Converter class provide the base functionality
7
 * for the Ascii and Geez converters.
8
 *
9
 * @author Sam As End <4sam21{at}gmail.com>
10
 */
11
abstract class Converter
12
{
13
    // i don't want readers to think it's a white
14
    // space, it's just an empty string
15
    const EMPTY_CHARACTER = '';
16
17
    const GEEZ_NUMBERS = [
18
        0     => '', '፩', '፪', '፫', '፬', '፭', '፮', '፯', '፰', '፱', '፲',
19
        20    => '፳',
20
        30    => '፴',
21
        40    => '፵',
22
        50    => '፶',
23
        60    => '፷',
24
        70    => '፸',
25
        80    => '፹',
26
        90    => '፺',
27
        100   => '፻',
28
        10000 => '፼',
29
    ];
30
31
    /**
32
     * Check if a number is strictly ZERO.
33
     *
34
     * @param int $number
35
     *
36
     * @return bool if true it's zero
37
     */
38
    public static function isZero($number)
39
    {
40
        return $number === 0;
41
    }
42
43
    abstract public function convert($number);
44
45
    /**
46
     * Checks if the number is ፻.
47
     *
48
     * @param string $geez_number
49
     *
50
     * @return bool
51
     */
52
    protected function isGeezNumberHundred($geez_number)
53
    {
54
        return $this->isGeezNumber($geez_number, 100);
55
    }
56
57
    /**
58
     * Checks if the geez number character is equal to ascii number.
59
     *
60
     * @param string $geez_number
61
     * @param int    $number
62
     *
63
     * @return bool
64
     */
65
    protected function isGeezNumber($geez_number, $number)
66
    {
67
        return $geez_number === self::GEEZ_NUMBERS[$number];
68
    }
69
70
    /**
71
     * Checks if the number is ፩.
72
     *
73
     * @param $geez_number
74
     *
75
     * @return bool
76
     */
77
    protected function isGeezNumberOne($geez_number)
78
    {
79
        return $this->isGeezNumber($geez_number, 1);
80
    }
81
82
    /**
83
     * Checks if the number is ፼
84
     *
85
     * @param $geez_number
86
     *
87
     * @return bool
88
     */
89
    protected function isGeezNumberTenThousand($geez_number)
90
    {
91
        return $this->isGeezNumber($geez_number, 10000);
92
    }
93
}
94