Skip to content
This repository was archived by the owner on Jul 1, 2019. It is now read-only.

Commit 63809d5

Browse files
Andrey HelldarStyleCIBot
authored andcommitted
Apply fixes from StyleCI
1 parent 245e8c3 commit 63809d5

File tree

5 files changed

+86
-87
lines changed

5 files changed

+86
-87
lines changed

src/DigitServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function register()
5555
*/
5656
protected function registerDigitText()
5757
{
58-
$this->app->singleton('digittext', function($app) {
58+
$this->app->singleton('digittext', function ($app) {
5959
return new Facade();
6060
});
6161
}

src/DigitText.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class DigitText
7676
*/
7777
private function lang($lang = 'en')
7878
{
79-
$filename = sprintf("%s/lang/%s.php", __DIR__, trim($lang));
79+
$filename = sprintf('%s/lang/%s.php', __DIR__, trim($lang));
8080
$this->lang = file_exists($filename) ? trim($lang) : $this->lang_fallback;
8181
}
8282

@@ -115,14 +115,14 @@ public function get($digit = 0.0, $lang = 'en', $is_currency = false)
115115

116116
// Return text from php_intl library
117117
$intl = $this->intl();
118-
if(!empty($intl)) {
118+
if (!empty($intl)) {
119119
return $intl;
120120
}
121121

122122
// Loading texts from locale page
123123
$this->loadTexts();
124124

125-
if($this->digit == 0) {
125+
if ($this->digit == 0) {
126126
return $this->texts['zero'];
127127
}
128128

@@ -134,8 +134,8 @@ public function get($digit = 0.0, $lang = 'en', $is_currency = false)
134134

135135
$groups = str_split($this->dsort((int) $digit), 3);
136136
$result = '';
137-
for($i = sizeof($groups) - 1; $i >= 0; $i--) {
138-
if((int) $groups[$i] > 0) {
137+
for ($i = sizeof($groups) - 1; $i >= 0; $i--) {
138+
if ((int) $groups[$i] > 0) {
139139
$result .= ' '.$this->digits($groups[$i], $i);
140140
}
141141
}
@@ -152,20 +152,20 @@ public function get($digit = 0.0, $lang = 'en', $is_currency = false)
152152
*/
153153
private function fixDigit($digit = null)
154154
{
155-
if(empty($digit)) {
155+
if (empty($digit)) {
156156
$this->digit = 0;
157157

158158
return;
159159
}
160160

161-
if(strripos((string) $digit, '.') === false) {
161+
if (strripos((string) $digit, '.') === false) {
162162
$this->digit = intval($digit);
163163

164164
return;
165165
}
166166

167-
$digit = explode('.', str_replace([',', '-', ' ', "'", '`'], '', (string) $digit));
168-
$this->digit = sprintf("%s.%s", intval($digit[0]), intval($digit[1]));
167+
$digit = explode('.', str_replace(array(',', '-', ' ', "'", '`'), '', (string) $digit));
168+
$this->digit = sprintf('%s.%s', intval($digit[0]), intval($digit[1]));
169169
}
170170

171171
/**
@@ -180,8 +180,8 @@ private function fixDigit($digit = null)
180180
*/
181181
private function intl()
182182
{
183-
if($this->is_currency) {
184-
if(extension_loaded('php_intl')) {
183+
if ($this->is_currency) {
184+
if (extension_loaded('php_intl')) {
185185
return (new \MessageFormatter($this->lang, '{n, spellout}'))->format(array('n' => $this->digit));
186186
}
187187
}
@@ -198,9 +198,9 @@ private function intl()
198198
*/
199199
private function loadTexts()
200200
{
201-
$filename = sprintf("%s/lang/%s.php", __DIR__, $this->lang);
202-
$lang = file_exists($filename) ? $this->lang : $this->lang_fallback;
203-
$this->texts = require sprintf("%s/lang/%s.php", __DIR__, $lang);
201+
$filename = sprintf('%s/lang/%s.php', __DIR__, $this->lang);
202+
$lang = file_exists($filename) ? $this->lang : $this->lang_fallback;
203+
$this->texts = require sprintf('%s/lang/%s.php', __DIR__, $lang);
204204
}
205205

206206
/**
@@ -212,13 +212,13 @@ private function loadTexts()
212212
*/
213213
private function fraction($digit = null)
214214
{
215-
if(empty($digit)) {
215+
if (empty($digit)) {
216216
$this->surplus = 0;
217217

218218
return;
219219
}
220220

221-
$pos = strripos((string) $digit, '.');
221+
$pos = strripos((string) $digit, '.');
222222
$this->surplus = $pos === false ? 0 : mb_substr((string) $digit, $pos + 1);
223223
}
224224

@@ -231,14 +231,14 @@ private function fraction($digit = null)
231231
*/
232232
private function dsort($digit = '0')
233233
{
234-
$digit = (string) $digit;
234+
$digit = (string) $digit;
235235
$sortedDigit = '';
236236

237-
if($digit == '0') {
237+
if ($digit == '0') {
238238
return array(0 => 0);
239239
}
240240

241-
for($i = strlen($digit) - 1; $i >= 0; $i--) {
241+
for ($i = strlen($digit) - 1; $i >= 0; $i--) {
242242
$sortedDigit .= $digit[$i];
243243
}
244244

@@ -255,21 +255,21 @@ private function dsort($digit = '0')
255255
*/
256256
private function digits($digit = 0.0, $id = 0)
257257
{
258-
if($digit == 0) {
258+
if ($digit == 0) {
259259
return $this->texts['zero'];
260260
}
261261

262262
$digitUnsorted = (int) $this->dsort($digit);
263263

264-
$array = str_split((string) $digit, 1);
264+
$array = str_split((string) $digit, 1);
265265
$result = '';
266266

267-
for($i = sizeof($array) - 1; $i >= 0; $i--) {
268-
if($i === 1 && $array[$i] == '1') {
269-
$d = $array[$i].$array[$i - 1];
267+
for ($i = sizeof($array) - 1; $i >= 0; $i--) {
268+
if ($i === 1 && $array[$i] == '1') {
269+
$d = $array[$i].$array[$i - 1];
270270
$result .= ' '.trim($this->texts[$id == 1 ? 3 : 0][(int) $d]);
271271
$i--;
272-
} elseif((int) $array[$i] > 0) {
272+
} elseif ((int) $array[$i] > 0) {
273273
$result .= ' '.$this->texts[$id == 1 ? $i + 3 : $i][$array[$i]];
274274
}
275275
}
@@ -287,25 +287,25 @@ private function digits($digit = 0.0, $id = 0)
287287
*/
288288
private function decline($group = 0, $digit = 0.0)
289289
{
290-
$text = (string) ((int) $digit);
291-
$text = (int) $text[strlen($digit) - 1];
290+
$text = (string) ((int) $digit);
291+
$text = (int) $text[strlen($digit) - 1];
292292
$result = '';
293293

294-
switch($group) {
294+
switch ($group) {
295295
case 1:
296296
$result = ' '.$this->texts['thousands'][0];
297-
if($text == 1) {
297+
if ($text == 1) {
298298
$result = ' '.$this->texts['thousands'][1];
299-
} elseif($text >= 2 && $text <= 4) {
299+
} elseif ($text >= 2 && $text <= 4) {
300300
$result = ' '.$this->texts['thousands'][2];
301301
}
302302
break;
303303

304304
case 2:
305305
$result = ' '.$this->texts['millions'][0];
306-
if($text >= 2 && $text <= 4) {
306+
if ($text >= 2 && $text <= 4) {
307307
$result = ' '.$this->texts['millions'][1];
308-
} elseif(($text >= 5 && $text <= 9) || $text == 0) {
308+
} elseif (($text >= 5 && $text <= 9) || $text == 0) {
309309
$result = ' '.$this->texts['millions'][2];
310310
}
311311
break;
@@ -326,20 +326,20 @@ private function decline($group = 0, $digit = 0.0)
326326
*/
327327
private function getCurrency($content = null)
328328
{
329-
if(empty($content)) {
329+
if (empty($content)) {
330330
return '---';
331331
}
332332

333-
if($this->texts['currency']['position'] == 'before') {
333+
if ($this->texts['currency']['position'] == 'before') {
334334
$result = $this->texts['currency']['int'].' '.$content;
335335

336-
if($this->surplus > 0) {
336+
if ($this->surplus > 0) {
337337
$result .= '.'.$this->surplus;
338338
}
339339
} else {
340340
$result = trim($content).' '.$this->texts['currency']['int'];
341341

342-
if($this->surplus > 0) {
342+
if ($this->surplus > 0) {
343343
$result .= ' '.$this->surplus.' '.$this->texts['currency']['fraction'];
344344
} else {
345345
$result .= ' 00 '.$this->texts['currency']['fraction'];

src/Facade.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Helldar\DigitText;
44

5-
65
class Facade
76
{
87
/**
@@ -20,4 +19,4 @@ public static function digit($digit = null)
2019
{
2120
return (new DigitText())->get($digit);
2221
}
23-
}
22+
}

src/helpers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* @author Andrey Helldar <helldar@ai-rus.com>
55
*
66
* @since 2017-03-27
7+
*
78
* @return DigitText
89
*/
910
function digit_text()
1011
{
1112
return new DigitText();
12-
}
13+
}

tests/DigitTextTest.php

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,34 @@ class DigitTextTest extends PHPUnit_Framework_TestCase
2121
*
2222
* @since 2016-11-28
2323
* @since 2017-03-27
24-
*
2524
* @since 1.0
2625
*/
2726
public function testRu()
2827
{
2928
$result = array(
30-
$this->object->get(0, 'ru') => 'ноль',
31-
$this->object->get(64.23, 'ru', true) => 'шестьдесят четыре руб 23 коп',
32-
$this->object->get(764, 'ru') => 'семьсот шестьдесят четыре',
33-
$this->object->get(2866, 'ru') => 'две тысячи восемьсот шестьдесят шесть',
34-
$this->object->get(7700, 'ru') => 'семь тысяч семьсот',
35-
$this->object->get('10,000', 'ru') => 'десять тысяч',
36-
$this->object->get(14383, 'ru') => 'четырнадцать тысячи триста восемьдесят три',
37-
$this->object->get(20383, 'ru') => 'двадцать тысяч триста восемьдесят три',
38-
$this->object->get(700383, 'ru') => 'семьсот тысяч триста восемьдесят три',
39-
$this->object->get(7644383, 'ru') => 'семь миллионов шестьсот сорок четыре тысячи триста восемьдесят три',
29+
$this->object->get(0, 'ru') => 'ноль',
30+
$this->object->get(64.23, 'ru', true) => 'шестьдесят четыре руб 23 коп',
31+
$this->object->get(764, 'ru') => 'семьсот шестьдесят четыре',
32+
$this->object->get(2866, 'ru') => 'две тысячи восемьсот шестьдесят шесть',
33+
$this->object->get(7700, 'ru') => 'семь тысяч семьсот',
34+
$this->object->get('10,000', 'ru') => 'десять тысяч',
35+
$this->object->get(14383, 'ru') => 'четырнадцать тысячи триста восемьдесят три',
36+
$this->object->get(20383, 'ru') => 'двадцать тысяч триста восемьдесят три',
37+
$this->object->get(700383, 'ru') => 'семьсот тысяч триста восемьдесят три',
38+
$this->object->get(7644383, 'ru') => 'семь миллионов шестьсот сорок четыре тысячи триста восемьдесят три',
4039
$this->object->get(70043783.65, 'ru', true) => 'семьдесят миллионов сорок три тысячи семьсот восемьдесят три руб 65 коп',
41-
$this->object->get(786443783, 'ru') => 'семьсот восемьдесят шесть миллионов четыреста сорок три тысячи семьсот восемьдесят три',
42-
$this->object->get(109, 'ru') => 'сто девять',
43-
$this->object->get(110, 'ru') => 'сто десять',
44-
$this->object->get(111, 'ru') => 'сто одиннадцать',
45-
$this->object->get(112, 'ru') => 'сто двенадцать',
46-
$this->object->get(116, 'ru') => 'сто шестнадцать',
47-
$this->object->get(118, 'ru') => 'сто восемнадцать',
48-
$this->object->get(120, 'ru') => 'сто двадцать',
49-
$this->object->get(121, 'ru') => 'сто двадцать один',
50-
$this->object->get(10010, 'ru') => 'десять тысяч десять',
51-
$this->object->get(10110, 'ru') => 'десять тысяч сто десять',
52-
$this->object->get(510110, 'ru') => 'пятьсот десять тысяч сто десять',
40+
$this->object->get(786443783, 'ru') => 'семьсот восемьдесят шесть миллионов четыреста сорок три тысячи семьсот восемьдесят три',
41+
$this->object->get(109, 'ru') => 'сто девять',
42+
$this->object->get(110, 'ru') => 'сто десять',
43+
$this->object->get(111, 'ru') => 'сто одиннадцать',
44+
$this->object->get(112, 'ru') => 'сто двенадцать',
45+
$this->object->get(116, 'ru') => 'сто шестнадцать',
46+
$this->object->get(118, 'ru') => 'сто восемнадцать',
47+
$this->object->get(120, 'ru') => 'сто двадцать',
48+
$this->object->get(121, 'ru') => 'сто двадцать один',
49+
$this->object->get(10010, 'ru') => 'десять тысяч десять',
50+
$this->object->get(10110, 'ru') => 'десять тысяч сто десять',
51+
$this->object->get(510110, 'ru') => 'пятьсот десять тысяч сто десять',
5352
);
5453

5554
$this->runTestDigits($result);
@@ -67,30 +66,30 @@ public function testRu()
6766
public function testEn()
6867
{
6968
$result = array(
70-
$this->object->get() => 'zero',
71-
$this->object->get(64.23, 'en', true) => 'sixty four dollars 23 cents',
72-
$this->object->get(764) => 'seven hundred sixty four',
73-
$this->object->get(2866) => 'two thousands eight hundred sixty six',
74-
$this->object->get(7700) => 'seven thousands seven hundred',
75-
$this->object->get('10,000') => 'ten thousands',
76-
$this->object->get(14383) => 'fourteen thousands three hundred eighty three',
77-
$this->object->get(20383) => 'twenty thousands three hundred eighty three',
78-
$this->object->get(700383) => 'seven hundred thousands three hundred eighty three',
79-
$this->object->get(7644383) => 'seven million six hundred forty four thousands three hundred eighty three',
69+
$this->object->get() => 'zero',
70+
$this->object->get(64.23, 'en', true) => 'sixty four dollars 23 cents',
71+
$this->object->get(764) => 'seven hundred sixty four',
72+
$this->object->get(2866) => 'two thousands eight hundred sixty six',
73+
$this->object->get(7700) => 'seven thousands seven hundred',
74+
$this->object->get('10,000') => 'ten thousands',
75+
$this->object->get(14383) => 'fourteen thousands three hundred eighty three',
76+
$this->object->get(20383) => 'twenty thousands three hundred eighty three',
77+
$this->object->get(700383) => 'seven hundred thousands three hundred eighty three',
78+
$this->object->get(7644383) => 'seven million six hundred forty four thousands three hundred eighty three',
8079
$this->object->get(70043783.65, 'en', true) => 'seventy million forty three thousands seven hundred eighty three dollars 65 cents',
81-
$this->object->get(786443783) => 'seven hundred eighty six million four hundred forty three thousands seven hundred eighty three',
82-
$this->object->get(109) => 'one hundred nine',
83-
$this->object->get(110) => 'one hundred ten',
84-
$this->object->get(111) => 'one hundred eleven',
85-
$this->object->get(112) => 'one hundred twelve',
86-
$this->object->get(115) => 'one hundred fifteen',
87-
$this->object->get(116) => 'one hundred sixteen',
88-
$this->object->get(118) => 'one hundred eighteen',
89-
$this->object->get(120) => 'one hundred twenty',
90-
$this->object->get(121) => 'one hundred twenty one',
91-
$this->object->get(10010) => 'ten thousands ten',
92-
$this->object->get(10110) => 'ten thousands one hundred ten',
93-
$this->object->get(510110) => 'five hundred ten thousands one hundred ten',
80+
$this->object->get(786443783) => 'seven hundred eighty six million four hundred forty three thousands seven hundred eighty three',
81+
$this->object->get(109) => 'one hundred nine',
82+
$this->object->get(110) => 'one hundred ten',
83+
$this->object->get(111) => 'one hundred eleven',
84+
$this->object->get(112) => 'one hundred twelve',
85+
$this->object->get(115) => 'one hundred fifteen',
86+
$this->object->get(116) => 'one hundred sixteen',
87+
$this->object->get(118) => 'one hundred eighteen',
88+
$this->object->get(120) => 'one hundred twenty',
89+
$this->object->get(121) => 'one hundred twenty one',
90+
$this->object->get(10010) => 'ten thousands ten',
91+
$this->object->get(10110) => 'ten thousands one hundred ten',
92+
$this->object->get(510110) => 'five hundred ten thousands one hundred ten',
9493
);
9594

9695
$this->runTestDigits($result);
@@ -108,7 +107,7 @@ public function testEn()
108107
*/
109108
public function runTestDigits($items = array())
110109
{
111-
foreach($items as $key => $result) {
110+
foreach ($items as $key => $result) {
112111
$this->assertEquals($result, $key);
113112
}
114113
}

0 commit comments

Comments
 (0)