irfaardy /
php-hari-libur
| 1 | <?php |
||
| 2 | /* |
||
| 3 | Author: Irfa Ardiansyah <[email protected]> |
||
| 4 | version: 1.1 |
||
| 5 | https://github.com/irfaardy/php-hari-libur |
||
| 6 | */ |
||
| 7 | namespace Irfa\HariLibur\Core; |
||
| 8 | |||
| 9 | use Irfa\HariLibur\Core\ConfigLoader as Conf; |
||
| 10 | |||
| 11 | class Localization |
||
| 12 | { |
||
| 13 | private $region; |
||
| 14 | /** |
||
| 15 | * Method ini berfungsi untuk set tanggal dari config. |
||
| 16 | * |
||
| 17 | * @return boolean |
||
| 18 | */ |
||
| 19 | private function lang() |
||
| 20 | { |
||
| 21 | if(!empty($this->region)) |
||
| 22 | { |
||
| 23 | return strtoupper($this->region); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 24 | } |
||
| 25 | |||
| 26 | $config = new Conf(); |
||
| 27 | return $config->region(); |
||
|
0 ignored issues
–
show
|
|||
| 28 | } |
||
| 29 | |||
| 30 | protected function regionSet($region) |
||
| 31 | { |
||
| 32 | $this->region = $region; |
||
| 33 | } |
||
| 34 | /** |
||
| 35 | * Method ini berfungsi untuk mengambil data libur dari file json. |
||
| 36 | * |
||
| 37 | * @return boolean |
||
| 38 | */ |
||
| 39 | public function holidayData($array = true) |
||
| 40 | { |
||
| 41 | if(function_exists('resource_path')) |
||
| 42 | { |
||
| 43 | $published_file = resource_path('irfa/php-hari-libur/'.$this->lang().'.json'); |
||
| 44 | }else{ |
||
| 45 | $published_file = __DIR__.'../../../../../../resources/irfa/php-hari-libur/'.$this->lang().'.json'; |
||
| 46 | } |
||
| 47 | if(file_exists($published_file)) |
||
| 48 | { |
||
| 49 | $file = $published_file; |
||
| 50 | } else{ |
||
| 51 | $file = __DIR__.'/'.'../../Data/'.$this->lang().'.json'; |
||
| 52 | } |
||
| 53 | // dd($file); |
||
| 54 | |||
| 55 | $this->checkFile($file); |
||
| 56 | $arr = file_get_contents($file); |
||
| 57 | if($this->isJson($arr)) |
||
| 58 | { |
||
| 59 | return json_decode($arr,$array); |
||
| 60 | } else{ |
||
| 61 | throw new \Exception('Json data is invalid.'); |
||
| 62 | |||
| 63 | return false; |
||
|
0 ignored issues
–
show
return false is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last Loading history...
|
|||
| 64 | } |
||
| 65 | } |
||
| 66 | /** |
||
| 67 | * Method ini berfungsi untuk validasi json |
||
| 68 | * |
||
| 69 | * @return boolean |
||
| 70 | */ |
||
| 71 | private function isJson($string) { |
||
| 72 | json_decode($string); |
||
| 73 | return (json_last_error() == JSON_ERROR_NONE); |
||
| 74 | } |
||
| 75 | |||
| 76 | private function checkFile($file) |
||
| 77 | { |
||
| 78 | if(!file_exists($file)) |
||
| 79 | { |
||
| 80 | throw new \Exception('Region "'.$this->lang().'" is not found.'); |
||
| 81 | return false; |
||
|
0 ignored issues
–
show
return false is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last Loading history...
|
|||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | } |
||
| 86 |