Skip to content

Commit

Permalink
[Feature] Remove the requestPassedAsString variable LRN-44748
Browse files Browse the repository at this point in the history
  • Loading branch information
sreenivasa-murty-lrn committed Sep 17, 2024
1 parent 3ee465c commit 19b7b66
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/Request/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ class Init
*/
private $requestPacket;

/**
* Tracking if the request was passed as a string
* @var bool
*/
private $requestPassedAsString = false;

/**
* An optional value used to define what type of request is being
* made. This is only required for certain requests made to the
Expand Down Expand Up @@ -247,9 +241,7 @@ public function generate(bool $encode = true)
break;
case 'assess':
// Stringify the request packet if necessary
$output = $this->requestPassedAsString ?
Json::encode($this->requestPacket) :
$this->requestPacket;
$output = $this->requestPacket;
break;
case 'author':
case 'authoraide':
Expand All @@ -259,9 +251,7 @@ public function generate(bool $encode = true)
$output['security'] = $this->securityPacket;

// Stringify the request packet if necessary
$output['request'] = $this->requestPassedAsString ?
Json::encode($this->requestPacket) :
$this->requestPacket;
$output['request'] = $this->requestPacket;
break;
case 'questions':
// Add the security packet (with signature) to the root of output
Expand All @@ -271,7 +261,7 @@ public function generate(bool $encode = true)
unset($output['domain']);

if (!empty($this->requestPacket)) {
$output = array_merge($output, $this->requestPacket);
$output['request'] = $this->requestPacket;
}
break;
case 'events':
Expand All @@ -297,7 +287,7 @@ public function generate(bool $encode = true)
*/
public function generateSignature(): string
{
$preHashString = $this->preHashStringGenerator->getPreHashString (
$preHashString = $this->preHashStringGenerator->getPreHashString(
$this->securityPacket,
$this->requestPacket,
$this->action
Expand Down Expand Up @@ -413,10 +403,8 @@ private function setServiceOptions()
*/
public function validate(string $service, string $secret, $securityPacket, $requestPacket): array
{
if (is_string($requestPacket)) {
//$requestPacketObject = json_decode($requestPacket);
//$requestPacket = (array)$requestPacketObject;
$this->requestPassedAsString = true;
if (!is_string($requestPacket)) {
throw new ValidationException('The request packet must a JSON string');
}

if (is_null($requestPacket)) {
Expand Down

0 comments on commit 19b7b66

Please sign in to comment.