Skip to content

Commit 4a48ede

Browse files
author
Ariful
committed
code optimization, added docblock and change method scope
1 parent 50f240b commit 4a48ede

8 files changed

+108
-28
lines changed

src/Exceptions/InvalidNumber.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class InvalidNumber extends Exception
88
{
9+
/**
10+
* @return static
11+
*/
912
public static function message()
1013
{
1114
return new static("The given value is not a valid number.");

src/Exceptions/InvalidRange.php

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
class InvalidRange extends Exception
88
{
9+
/**
10+
* @param $max
11+
* @return static
12+
*/
913
public static function message($max = 999999999999999)
1014
{
1115
return new static("The given value is not in valid range. Maximum accepted value is " . $max);

src/Facades/NumberToBangla.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
class NumberToBangla extends Facade
1212
{
13+
/**
14+
* @return string
15+
*/
1316
protected static function getFacadeAccessor(): string
1417
{
1518
return 'bangla-number';
1619
}
17-
}
20+
}

src/NumberToBangla.php

+33-5
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,69 @@
22

33
namespace Rakibhstu\Banglanumber;
44

5-
use Rakibhstu\Banglanumber\ProcessNumber;
6-
use Rakibhstu\Banglanumber\ProcessDate;
7-
85
class NumberToBangla
96
{
10-
protected $process;
7+
/**
8+
* @var ProcessNumber
9+
*/
10+
private $process;
1111

12-
protected $date;
12+
/**
13+
* @var ProcessDate
14+
*/
15+
private $date;
1316

17+
/**
18+
* Number to Bangla Constructor
19+
*/
1420
public function __construct()
1521
{
1622
$this->process = new ProcessNumber();
1723
$this->date = new ProcessDate();
1824
}
1925

26+
/**
27+
* @param $number
28+
* @return string
29+
*/
2030
public function bnNum($number)
2131
{
2232
return $this->process->bnNum($number);
2333
}
2434

35+
/**
36+
* @param $number
37+
* @return string
38+
*/
2539
public function bnWord($number)
2640
{
2741
return $this->process->bnWord($number);
2842
}
2943

44+
/**
45+
* @param $number
46+
* @return string
47+
*/
3048
public function bnMoney($number)
3149
{
3250
return $this->process->bnMoney($number);
3351
}
3452

53+
/**
54+
* @param $number
55+
* @return string
56+
*/
3557
public function bnCommaLakh($number)
3658
{
3759
return $this->process->bnCommaLakh($number);
3860
}
3961

62+
/**
63+
* @param $number
64+
* @return string
65+
* @throws Exceptions\InvalidNumber
66+
* @throws Exceptions\InvalidRange
67+
*/
4068
public function bnMonth($number)
4169
{
4270
return $this->date->bnMonth($number);

src/NumberToBanglaServiceProvider.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Rakibhstu\Banglanumber;
44

55
use Illuminate\Support\ServiceProvider;
6-
use Rakibhstu\Banglanumber\NumberToBangla;
76

87
class NumberToBanglaServiceProvider extends ServiceProvider
98
{

src/ProcessDate.php

+13-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
class ProcessDate
99
{
10-
protected $bn_month = [
10+
/**
11+
* @var string[]
12+
*/
13+
private $bn_month = [
1114
'1' => 'জানুয়ারি',
1215
'2' => 'ফেব্রুয়ারি',
1316
'3' => 'মার্চ',
@@ -22,21 +25,12 @@ class ProcessDate
2225
'12' => 'ডিসেম্বর'
2326
];
2427

25-
protected $numbers = [
26-
'',
27-
'',
28-
'',
29-
'',
30-
'',
31-
'',
32-
'',
33-
'',
34-
'',
35-
''
36-
];
37-
3828

39-
public function isValid($number)
29+
/**
30+
* @throws InvalidNumber
31+
* @throws InvalidRange
32+
*/
33+
private function isValid($number)
4034
{
4135
if (!is_numeric($number)) {
4236
throw InvalidNumber::message();
@@ -48,6 +42,10 @@ public function isValid($number)
4842
}
4943

5044

45+
/**
46+
* @throws InvalidNumber
47+
* @throws InvalidRange
48+
*/
5149
public function bnMonth($number)
5250
{
5351
$this->isValid($number);

src/ProcessNumber.php

+49-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class ProcessNumber
99
{
10+
/**
11+
* @var string[]
12+
*/
1013
protected $words = [
1114
'',
1215
'এক',
@@ -110,6 +113,9 @@ class ProcessNumber
110113
'নিরানব্বই'
111114
];
112115

116+
/**
117+
* @var string[]
118+
*/
113119
protected $bn_num = [
114120
'শূন্য',
115121
'এক',
@@ -123,6 +129,9 @@ class ProcessNumber
123129
'নয়'
124130
];
125131

132+
/**
133+
* @var string[]
134+
*/
126135
protected $numbers = [
127136
'',
128137
'',
@@ -137,6 +146,10 @@ class ProcessNumber
137146
];
138147

139148

149+
/**
150+
* @throws InvalidNumber
151+
* @throws InvalidRange
152+
*/
140153
public function isValid($number)
141154
{
142155
if (!is_numeric($number)) {
@@ -148,6 +161,12 @@ public function isValid($number)
148161
}
149162
}
150163

164+
/**
165+
* @param $number
166+
* @return string
167+
* @throws InvalidNumber
168+
* @throws InvalidRange
169+
*/
151170
public function bnNum($number)
152171
{
153172
$this->isValid($number);
@@ -156,9 +175,15 @@ public function bnNum($number)
156175
}
157176

158177

178+
/**
179+
* @param $number
180+
* @return string
181+
* @throws InvalidNumber
182+
* @throws InvalidRange
183+
*/
159184
public function bnWord($number)
160185
{
161-
$valid = $this->isValid($number);
186+
$this->isValid($number);
162187

163188
if ($number == 0) {
164189
return 'শূন্য';
@@ -171,6 +196,12 @@ public function bnWord($number)
171196
return $this->toWord($number);
172197
}
173198

199+
/**
200+
* @param $number
201+
* @return string
202+
* @throws InvalidNumber
203+
* @throws InvalidRange
204+
*/
174205
public function bnMoney($number)
175206
{
176207
$this->isValid($number);
@@ -186,6 +217,10 @@ public function bnMoney($number)
186217
return $this->toWord($number) . ' টাকা ';
187218
}
188219

220+
/**
221+
* @throws InvalidNumber
222+
* @throws InvalidRange
223+
*/
189224
public function bnCommaLakh($number)
190225
{
191226
$this->isValid($number);
@@ -195,6 +230,10 @@ public function bnCommaLakh($number)
195230
return strtr($n, $this->numbers);
196231
}
197232

233+
/**
234+
* @param $num
235+
* @return string
236+
*/
198237
protected function toWord($num)
199238
{
200239
$text = '';
@@ -228,19 +267,23 @@ protected function toWord($num)
228267
$text .= $this->words[$hundred] . ' শত ';
229268
}
230269

231-
$hundred_div = (int) ($thousand_div % 100);
270+
$hundred_div = $thousand_div % 100;
232271
if ($hundred_div > 0) {
233272
$text .= $this->words[$hundred_div];
234273
}
235274

236275
return $text;
237276
}
238277

278+
/**
279+
* @param $num
280+
* @return string
281+
*/
239282
protected function toDecimalWord($num)
240283
{
241284
$text = '';
242285
$decimalParts = str_split($num);
243-
foreach ($decimalParts as $key => $decimalPart) {
286+
foreach ($decimalParts as $decimalPart) {
244287
$text .= $this->bn_num[$decimalPart] . ' ';
245288
}
246289

@@ -249,7 +292,7 @@ protected function toDecimalWord($num)
249292

250293
/**
251294
* Convert float number to text
252-
*
295+
*
253296
*/
254297
private function convertFloatNumberToWord($number)
255298
{
@@ -264,7 +307,8 @@ private function convertFloatNumberToWord($number)
264307

265308
/**
266309
* Convert float number to money format
267-
*
310+
* @param $number
311+
* @return string
268312
*/
269313
private function convertFloatNumberToMoneyFormat($number)
270314
{

tests/CreatesApplication.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace Tests;
44

55
use Illuminate\Contracts\Console\Kernel;
6+
use Illuminate\Foundation\Application;
67

78
trait CreatesApplication
89
{
910
/**
1011
* Creates the application.
1112
*
12-
* @return \Illuminate\Foundation\Application
13+
* @return Application
1314
*/
1415
public function createApplication()
1516
{

0 commit comments

Comments
 (0)