Skip to content

Commit

Permalink
Timeframe service fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
firstred committed Mar 27, 2021
1 parent 23d5381 commit e84af0d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
61 changes: 59 additions & 2 deletions src/Entity/Request/GetTimeframes.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@
* Class GetTimeframes.
*
* @method Message|null getMessage()
* @method Timeframe[]|null getTimeframe()
* @method GetTimeframes setMessage(Message|null $message = null)
* @method GetTimeframes setTimeframe(Timeframe[]|null $timeframes = null)
*
* @since 1.0.0
*/
Expand Down Expand Up @@ -106,6 +104,65 @@ public function __construct(Message $message = null, array $timeframes = null)
$this->setTimeframe($timeframes);
}

/**
* Set timeframes
*
* @param Timeframe|Timeframe[]|null $timeframes
*
* @return $this
*
* @since 1.0.0
* @since 1.2.0 Accept singular timeframe object
*/
public function setTimeframe($timeframes)
{
return $this->setTimeframes($timeframes);
}

/**
* Set timeframes
*
* @param Timeframe|Timeframe[]|null $timeframes
*
* @return $this
*
* @since 1.2.0
*/
public function setTimeframes($timeframes)
{
if ($timeframes instanceof Timeframe) {
$timeframes = [$timeframes];
}

$this->Timeframe = $timeframes;

return $this;
}

/**
* Get timeframes
*
* @return Timeframe[]|null
*
* @sinc 1.0.0
*/
public function getTimeframe()
{
return $this->getTimeframes();
}

/**
* Get timeframes
*
* @return Timeframe[]|null
*
* @since 1.2.0
*/
public function getTimeframes()
{
return $this->Timeframe;
}

/**
* Return a serializable array for the XMLWriter.
*
Expand Down
5 changes: 2 additions & 3 deletions src/Service/TimeframeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,11 @@ public function buildGetTimeframesRequestREST(GetTimeframes $getTimeframes)
$query['City'] = $city;
}
foreach ($timeframe->getOptions() as $option) {
if ('PG' === $option) {
continue;
}
$query['Options'] .= ",$option";
}
$query['Options'] = ltrim($query['Options'], ',');
$query['Options'] = $query['Options'] ?: 'Daytime';

$endpoint = '?'.http_build_query($query);

return $this->postnl->getRequestFactory()->createRequest(
Expand Down
1 change: 0 additions & 1 deletion tests/Service/TimeframeServiceRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ public function testGetTimeframesRest()
$this->assertCount(5, $responseTimeframes->getReasonNoTimeframes());
$this->assertCount(6, $responseTimeframes->getTimeframes());
$this->assertInstanceOf(Timeframe::class, $responseTimeframes->getTimeframes()[0]);
$this->assertJsonStringEqualsJsonString(json_encode($payload), json_encode($responseTimeframes));
$this->assertNotTrue($this->containsStdClass($responseTimeframes));
}
}

0 comments on commit e84af0d

Please sign in to comment.