Skip to content

Commit

Permalink
Merge pull request #2 from rakibdevs/hotfix/bncommalakh-protected
Browse files Browse the repository at this point in the history
Fixed Protected Method Issue and Refactor
  • Loading branch information
rakibdevs authored Sep 24, 2022
2 parents c8cedd2 + b632daa commit 50f240b
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 140 deletions.
3 changes: 2 additions & 1 deletion src/Exceptions/InvalidNumber.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Rakibhstu\Banglanumber\Exceptions;

use Exception;
Expand All @@ -9,4 +10,4 @@ public static function message()
{
return new static("The given value is not a valid number.");
}
}
}
7 changes: 4 additions & 3 deletions src/Exceptions/InvalidRange.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace Rakibhstu\Banglanumber\Exceptions;

use Exception;

class InvalidRange extends Exception
class InvalidRange extends Exception
{
public static function message($max = 999999999999999)
{
return new static("The given value is not in valid range. Maximum accepted value is ".$max);
return new static("The given value is not in valid range. Maximum accepted value is " . $max);
}
}
}
15 changes: 6 additions & 9 deletions src/NumberToBangla.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,32 @@ class NumberToBangla

public function __construct()
{
$this->process = new ProcessNumber;
$this->date = new ProcessDate;
$this->process = new ProcessNumber();
$this->date = new ProcessDate();
}

public function bnNum($number)
{
return $this->process->bnNum($number);
}


public function bnWord($number)
{
{
return $this->process->bnWord($number);
}

public function bnMoney($number)
{
{
return $this->process->bnMoney($number);
}

public function bnCommaLakh($number)
{
return $this->process->bnCommaLakh($number);
return $this->process->bnCommaLakh($number);
}

public function bnMonth($number)
public function bnMonth($number)
{
return $this->date->bnMonth($number);

}

}
2 changes: 1 addition & 1 deletion src/NumberToBanglaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NumberToBanglaServiceProvider extends ServiceProvider
public function register()
{
$this->app->singleton(NumberToBangla::class);

$this->app->alias(NumberToBangla::class, 'bangla-number');
}

Expand Down
67 changes: 37 additions & 30 deletions src/ProcessDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,55 @@

class ProcessDate
{

protected $bn_month = array(
'1' => 'জানুয়ারি',
'2' => 'ফেব্রুয়ারি',
'3' => 'মার্চ',
'4' => 'এপ্রিল',
'5' => 'মে',
'6' => 'জুন',
'7' => 'জুলাই',
'8' => 'আগস্ট',
'9' => 'সেপ্টেম্বর',
'10' => 'অক্টোবর',
'11' => 'নভেম্বর',
'12' => 'ডিসেম্বর'
);

protected $numbers = array('','','','','','','','','','');


public function isValid($number)
protected $bn_month = [
'1' => 'জানুয়ারি',
'2' => 'ফেব্রুয়ারি',
'3' => 'মার্চ',
'4' => 'এপ্রিল',
'5' => 'মে',
'6' => 'জুন',
'7' => 'জুলাই',
'8' => 'আগস্ট',
'9' => 'সেপ্টেম্বর',
'10' => 'অক্টোবর',
'11' => 'নভেম্বর',
'12' => 'ডিসেম্বর'
];

protected $numbers = [
'',
'',
'',
'',
'',
'',
'',
'',
'',
''
];


public function isValid($number)
{
if(!is_numeric($number)){
if (!is_numeric($number)) {
throw InvalidNumber::message();
}

if($number > 999999999999999 || strpos($number, 'E') !== false){
if ($number > 999999999999999 || strpos($number, 'E') !== false) {
throw InvalidRange::message();
}
}


public function bnMonth($number)
public function bnMonth($number)
{
$this->isValid($number);

if($number >= 1 && $number <= 12 ){
if ($number >= 1 && $number <= 12) {
return $this->bn_month[(int)$number];
}else{
throw InvalidRange::message(12);
}

}


}
throw InvalidRange::message(12);
}
}
Loading

0 comments on commit 50f240b

Please sign in to comment.