for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
Author: Irfa Ardiansyah <[email protected]>
version: 1.1
https://github.com/irfaardy/php-hari-libur
*/
namespace Irfa\HariLibur\Core;
use Irfa\HariLibur\Core\ConfigLoader as Conf;
class Localization
{
private $region;
/**
* Method ini berfungsi untuk set tanggal dari config.
*
* @return boolean
private function lang()
if(!empty($this->region))
return strtoupper($this->region);
return strtoupper($this->region)
string
boolean
}
$config = new Conf();
return $config->region();
return $config->region()
protected function regionSet($region)
$this->region = $region;
* Method ini berfungsi untuk mengambil data libur dari file json.
public function holidayData($array = true)
if(function_exists('resource_path'))
$published_file = resource_path('irfa/php-hari-libur/'.$this->lang().'.json');
}else{
$published_file = __DIR__.'../../../../../../resources/irfa/php-hari-libur/'.$this->lang().'.json';
if(file_exists($published_file))
$file = $published_file;
} else{
$file = __DIR__.'/'.'../../Data/'.$this->lang().'.json';
// dd($file);
$this->checkFile($file);
$arr = file_get_contents($file);
if($this->isJson($arr))
return json_decode($arr,$array);
throw new \Exception('Json data is invalid.');
return false;
return false
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 return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
* Method ini berfungsi untuk validasi json
private function isJson($string) {
json_decode($string);
return (json_last_error() == JSON_ERROR_NONE);
private function checkFile($file)
if(!file_exists($file))
throw new \Exception('Region "'.$this->lang().'" is not found.');