Skip to content

Commit

Permalink
Fixed error when passing non-array variables to send() function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacMelloni committed Mar 5, 2019
1 parent 2f32929 commit f6e2f2e
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Kfz24/Client/Aws/SqsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ public function setLargePayloadMessageExtension(
*/
public function send($message)
{
$message = $this->prepareMessageFromArrayMessage($message);
$message = $this->prepareMessageFromNonArrayMessage($message);
if (is_array($message)) {
$message = $this->prepareMessageFromArrayMessage($message);
} else {
$message = $this->prepareMessageFromNonArrayMessage($message);
}


if (
$this->largePayloadMessageExtension !== null
Expand Down Expand Up @@ -220,18 +224,16 @@ private function isJsonString(string $message): bool
}

/**
* @param mixed $message
* @param array $message
*
* @return array
*/
private function prepareMessageFromArrayMessage($message): array
private function prepareMessageFromArrayMessage(array $message): array
{
if (is_array($message)) {
if (!array_key_exists(self::MESSAGE_BODY, $message)) {
$message = [self::MESSAGE_BODY => json_encode($message)];
} else if (is_array($message[self::MESSAGE_BODY]) || is_object($message[self::MESSAGE_BODY])) {
$message[self::MESSAGE_BODY] = json_encode($message[self::MESSAGE_BODY]);
}
if (!array_key_exists(self::MESSAGE_BODY, $message)) {
$message = [self::MESSAGE_BODY => json_encode($message)];
} else if (is_array($message[self::MESSAGE_BODY]) || is_object($message[self::MESSAGE_BODY])) {
$message[self::MESSAGE_BODY] = json_encode($message[self::MESSAGE_BODY]);
}

return $message;
Expand All @@ -244,12 +246,10 @@ private function prepareMessageFromArrayMessage($message): array
*/
private function prepareMessageFromNonArrayMessage($message): array
{
if (!is_array($message)) {
if (is_string($message) && $this->isJsonString($message)) {
$message = [self::MESSAGE_BODY => $message];
} else {
$message = [self::MESSAGE_BODY => json_encode($message)];
}
if (is_string($message) && $this->isJsonString($message)) {
$message = [self::MESSAGE_BODY => $message];
} else {
$message = [self::MESSAGE_BODY => json_encode($message)];
}

return $message;
Expand Down

0 comments on commit f6e2f2e

Please sign in to comment.