Skip to content

Commit

Permalink
reverse method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 26, 2017
1 parent 4d910e9 commit db5f011
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Illuminate/Http/JsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,26 @@ public function setData($data = [])
$this->data = json_encode($data, $this->encodingOptions);
}

if ($this->hasJsonError(json_last_error())) {
if (! $this->hasValidJson(json_last_error())) {
throw new InvalidArgumentException(json_last_error_msg());
}

return $this->update();
}

/**
* Determine if an error occured during JSON encoding.
*
* @param int $jsonError
* @return bool
*/
protected function hasValidJson($jsonError)
{
return $jsonError === JSON_ERROR_NONE ||
($jsonError === JSON_ERROR_UNSUPPORTED_TYPE &&
$this->hasEncodingOption(JSON_PARTIAL_OUTPUT_ON_ERROR));
}

/**
* {@inheritdoc}
*/
Expand All @@ -85,26 +98,13 @@ public function setEncodingOptions($options)
}

/**
* Checks the JSON encoding option is set.
* Determine if a JSON encoding option is set.
*
* @param int $option
* @return bool
*/
public function isEncodingOptionSet($option)
public function hasEncodingOption($option)
{
return (bool) ($this->encodingOptions & $option);
}

/**
* Checks if error happened during json_encode.
*
* @param int $jsonError
* @return bool
*/
protected function hasJsonError($jsonError)
{
return $jsonError !== JSON_ERROR_NONE &&
($jsonError !== JSON_ERROR_UNSUPPORTED_TYPE ||
! $this->isEncodingOptionSet(JSON_PARTIAL_OUTPUT_ON_ERROR));
}
}

0 comments on commit db5f011

Please sign in to comment.