Total Complexity | 8 |
Total Lines | 68 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | class CurrencyNumberInfo |
||
23 | { |
||
24 | protected int $number; |
||
25 | protected int $decimals; |
||
26 | |||
27 | /** |
||
28 | * @var float |
||
29 | */ |
||
30 | protected $float; |
||
31 | |||
32 | /** |
||
33 | * @param int $number |
||
34 | * @param int $decimals |
||
35 | */ |
||
36 | public function __construct(int $number, int $decimals = 0) |
||
37 | { |
||
38 | $this->number = $number; |
||
39 | $this->decimals = $decimals; |
||
40 | } |
||
41 | |||
42 | public function isNegative() : bool |
||
43 | { |
||
44 | return $this->number < 0; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Gets the number as a float, e.g. 100.25 |
||
49 | * @return float |
||
50 | */ |
||
51 | public function getFloat() : float |
||
52 | { |
||
53 | return (float)($this->getString()); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Returns the number without decimals (positive integer). e.g. 100 |
||
58 | * @return int |
||
59 | */ |
||
60 | public function getNumber() : int |
||
61 | { |
||
62 | return $this->number; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Returns the decimals of the number, if any. |
||
67 | * @return int |
||
68 | */ |
||
69 | public function getDecimals() : int |
||
70 | { |
||
71 | return $this->decimals; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Counts the number of decimals in the number. |
||
76 | * @return int |
||
77 | */ |
||
78 | public function countDecimals() : int |
||
79 | { |
||
80 | if ($this->decimals === 0) { |
||
81 | return 0; |
||
82 | } |
||
83 | |||
84 | return strlen((string)$this->decimals); |
||
85 | } |
||
86 | |||
87 | public function getString() : string |
||
90 | } |
||
91 | } |
||
92 |