Skip to content

Commit

Permalink
Merge pull request #492 from tienvx/remove-this
Browse files Browse the repository at this point in the history
refactor: Remove $this return value
  • Loading branch information
tienvx committed Feb 26, 2024
2 parents 5d300ed + 152eceb commit bcee663
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ public function __construct(
$this->bodyDriver = $bodyDriver ?? new InteractionBodyDriver($client);
}

protected function withBody(Interaction $interaction, InteractionPart $part): self
protected function withBody(Interaction $interaction, InteractionPart $part): void
{
$this->bodyDriver->registerBody($interaction, $part);

return $this;
}

protected function withHeaders(Interaction $interaction, InteractionPart $interactionPart): self
protected function withHeaders(Interaction $interaction, InteractionPart $interactionPart): void
{
$headers = $interaction->getHeaders($interactionPart);
$partId = match ($interactionPart) {
Expand All @@ -38,7 +36,5 @@ protected function withHeaders(Interaction $interaction, InteractionPart $intera
$this->client->call('pactffi_with_header_v2', $interaction->getHandle(), $partId, (string) $header, (int) $index, (string) $value);
}
}

return $this;
}
}
17 changes: 6 additions & 11 deletions src/PhpPact/Consumer/Driver/InteractionPart/RequestDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,24 @@ class RequestDriver extends AbstractInteractionPartDriver implements RequestDriv
{
public function registerRequest(Interaction $interaction): void
{
$this
->withRequest($interaction)
->withQueryParameters($interaction)
->withHeaders($interaction, InteractionPart::REQUEST)
->withBody($interaction, InteractionPart::REQUEST);
$this->withBody($interaction, InteractionPart::REQUEST);
$this->withHeaders($interaction, InteractionPart::REQUEST);
$this->withQueryParameters($interaction);
$this->withRequest($interaction);
}

private function withQueryParameters(Interaction $interaction): self
private function withQueryParameters(Interaction $interaction): void
{
foreach ($interaction->getRequest()->getQuery() as $key => $values) {
foreach (array_values($values) as $index => $value) {
$this->client->call('pactffi_with_query_parameter_v2', $interaction->getHandle(), (string) $key, (int) $index, (string) $value);
}
}

return $this;
}

private function withRequest(Interaction $interaction): self
private function withRequest(Interaction $interaction): void
{
$request = $interaction->getRequest();
$this->client->call('pactffi_with_request', $interaction->getHandle(), $request->getMethod(), $request->getPath());

return $this;
}
}
13 changes: 6 additions & 7 deletions src/PhpPact/Consumer/Driver/InteractionPart/ResponseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ class ResponseDriver extends AbstractInteractionPartDriver implements ResponseDr
{
public function registerResponse(Interaction $interaction): void
{
$this
->withResponse($interaction)
->withHeaders($interaction, InteractionPart::RESPONSE)
->withBody($interaction, InteractionPart::RESPONSE);
// @todo Fix 'Exception: String could not be parsed as XML' in xml's consumer test
// when calling `withBody` before `withHeaders`
$this->withHeaders($interaction, InteractionPart::RESPONSE);
$this->withBody($interaction, InteractionPart::RESPONSE);
$this->withResponse($interaction);
}

private function withResponse(Interaction $interaction): self
private function withResponse(Interaction $interaction): void
{
$this->client->call('pactffi_response_status_v2', $interaction->getHandle(), $interaction->getResponse()->getStatus());

return $this;
}
}

0 comments on commit bcee663

Please sign in to comment.