Skip to content

Commit

Permalink
fixed: issue-49
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehedi Hasan Nahid committed Oct 17, 2019
1 parent 99533dd commit 8b38cea
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/JsonQueriable.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,21 @@ protected function isMultiArray($arr)
*
* @param string $value
* @param bool $isReturnMap
*
*
* @return bool|array
*/
public function isJson($value, $isReturnMap = false)
{
if (is_array($value) || is_object($value)) {
return false;
}

$data = json_decode($value, true);

if (json_last_error() !== JSON_ERROR_NONE) {
return false;
}

return $isReturnMap ? $data : true;
}

Expand Down Expand Up @@ -300,11 +300,11 @@ protected function getDataFromFile($file, $type = 'application/json')
$context = stream_context_create($opts);
$data = file_get_contents($file, 0, $context);
$json = $this->isJson($data, true);

if (!$json) {
throw new InvalidJsonException();
}

return $json;
}

Expand All @@ -331,6 +331,8 @@ protected function getFromNested($map, $node)
$path = explode('.', $node);

foreach ($path as $val) {
if (!is_array($map)) return $map;

if (!array_key_exists($val, $map)) {
$terminate = true;
break;
Expand Down Expand Up @@ -379,10 +381,10 @@ protected function processConditions()
if (!method_exists(Condition::class, $function)) {
throw new ConditionNotAllowedException("Exception: $function condition not allowed");
}

$function = [Condition::class, $function];
}

$value = $this->getFromNested($val, $rule['key']);
$return = $value instanceof ValueNotFound ? false : call_user_func_array($function, [$value, $rule['value']]);
$tmp &= $return;
Expand Down

0 comments on commit 8b38cea

Please sign in to comment.