Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added typing / comments to the SenderInterface #592

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/Senders/AgentSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sendBatch(array $batch, string $accessToken): void
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function wait(string $accessToken, int $max)
public function wait(string $accessToken, int $max): void
{
return;
}
Expand All @@ -65,9 +65,4 @@ private function loadAgentFile()
$filename = $this->agentLogLocation . '/rollbar-relay.' . getmypid() . '.' . microtime(true) . '.rollbar';
$this->agentLog = fopen($filename, 'a');
}

public function toString()
{
return "agent log: " . $this->agentLogLocation;
}
}
7 changes: 1 addition & 6 deletions src/Senders/CurlSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function sendBatch(array $batch, string $accessToken): void
$this->checkForCompletedRequests($accessToken);
}

public function wait(string $accessToken, int $max = 0)
public function wait(string $accessToken, int $max = 0): void
{
if (count($this->inflightRequests) <= $max) {
return;
Expand Down Expand Up @@ -187,9 +187,4 @@ private function removeFinishedRequests(string $accessToken)
}
$this->maybeSendMoreBatchRequests($accessToken);
}

public function toString()
{
return "Rollbar API endpoint: " . $this->getEndpoint();
}
}
8 changes: 1 addition & 7 deletions src/Senders/FluentSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function sendBatch(array $batch, string $accessToken, &$responses = array
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function wait(string $accessToken, int $max)
public function wait(string $accessToken, int $max): void
{
return;
}
Expand All @@ -108,10 +108,4 @@ protected function loadFluentLogger()
{
$this->fluentLogger = new FluentLogger($this->fluentHost, $this->fluentPort);
}

public function toString()
{
return "fluentd " . $this->fluentHost . ":" . $this->fluentPort .
" tag: " . $this->fluentTag;
}
}
41 changes: 37 additions & 4 deletions src/Senders/SenderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,46 @@

namespace Rollbar\Senders;

use Rollbar\Payload\Payload;
use Rollbar\Payload\EncodedPayload;
use Rollbar\Payload\Payload;
use Rollbar\Response;

/**
* The sender interface is used to define how an error report sender should transport payloads to Rollbar Service.
*
* An optional constructor can be included in the implementing class. If the constructor is present a single argument
* with the value of the `senderOptions` config option will be passed to the constructor.
*/
interface SenderInterface
{
public function send(EncodedPayload $payload, string $accessToken);
/**
* Sends the payload to the Rollbar service and returns the response.
*
* @param EncodedPayload $payload The payload to deliver to the Rollbar service.
* @param string $accessToken The project access token.
*
* @return Response
*/
public function send(EncodedPayload $payload, string $accessToken): Response;

/**
* Sends an array of payloads to the Rollbar service.
*
* @param Payload[] $batch The array of {@see Payload} instances.
* @param string $accessToken The project access token.
*
* @return void
*/
public function sendBatch(array $batch, string $accessToken): void;
public function wait(string $accessToken, int $max);
public function toString();

/**
* Method used to keep the batch send process alive until all or $max number of Payloads are sent, which ever comes
* first.
*
* @param string $accessToken The project access token.
* @param int $max The maximum payloads to send before stopping the batch send process.
*
* @return void
*/
public function wait(string $accessToken, int $max): void;
}
2 changes: 1 addition & 1 deletion tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testLoggingPayload(): void
);
$senderMock = $this->getMockBuilder(SenderInterface::class)
->getMock();
$senderMock->method('send')->willReturn(null);
$senderMock->method('send')->willReturn(new Response(200, 'Test'));

$payload = new \Rollbar\Payload\EncodedPayload(array('data'=>array()));
$payload->encode();
Expand Down