Skip to content

Commit

Permalink
Change LogEvent name to RpcLogEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Nov 22, 2024
1 parent ef1425a commit 98054c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/HttpHandler/Guzzle6HttpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
namespace Google\Auth\HttpHandler;

use Google\Auth\Logging\LogEvent;
use Google\Auth\Logging\LoggingTrait;
use Google\Auth\Logging\RpcLogEvent;
use GuzzleHttp\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -59,7 +59,7 @@ public function __invoke(RequestInterface $request, array $options = [])
$requestEvent = null;

if ($this->logger) {
$requestEvent = new LogEvent();
$requestEvent = new RpcLogEvent();

$requestEvent->method = $request->getMethod();
$requestEvent->url = $request->getUri()->__toString();
Expand All @@ -76,7 +76,7 @@ public function __invoke(RequestInterface $request, array $options = [])
$response = $this->client->send($request, $options);

if ($this->logger) {
$responseEvent = new LogEvent($requestEvent->milliseconds);
$responseEvent = new RpcLogEvent($requestEvent->milliseconds);

$responseEvent->headers = $response->getHeaders();
$responseEvent->payload = $response->getBody()->getContents();
Expand All @@ -103,7 +103,7 @@ public function async(RequestInterface $request, array $options = [])
$requestEvent = null;

if ($this->logger) {
$requestEvent = new LogEvent();
$requestEvent = new RpcLogEvent();

$requestEvent->method = $request->getMethod();
$requestEvent->url = (string) $request->getUri();
Expand All @@ -121,7 +121,7 @@ public function async(RequestInterface $request, array $options = [])

if ($this->logger) {
$promise->then(function (ResponseInterface $response) use ($requestEvent) {
$responseEvent = new LogEvent($requestEvent->milliseconds);
$responseEvent = new RpcLogEvent($requestEvent->milliseconds);

$responseEvent->headers = $response->getHeaders();
$responseEvent->payload = $response->getBody()->getContents();
Expand Down
6 changes: 3 additions & 3 deletions src/Logging/LoggingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ trait LoggingTrait
/**
* @param LogEvent $event
*/
private function logRequest(LogEvent $event): void
private function logRequest(RpcLogEvent $event): void
{
$debugEvent = [
'timestamp' => $event->timestamp,
Expand Down Expand Up @@ -60,7 +60,7 @@ private function logRequest(LogEvent $event): void
/**
* @param LogEvent $event
*/
private function logResponse(LogEvent $event): void
private function logResponse(RpcLogEvent $event): void
{
$debugEvent = [
'timestamp' => $event->timestamp,
Expand Down Expand Up @@ -116,7 +116,7 @@ private function logResponse(LogEvent $event): void
/**
* @param LogEvent $event
*/
private function logStatus(LogEvent $event): void
private function logStatus(RpcLogEvent $event): void
{
$infoEvent = [
'timestamp' => $event->timestamp,
Expand Down
4 changes: 3 additions & 1 deletion src/Logging/LogEvent.php → src/Logging/RpcLogEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Google\Auth\Logging;

class LogEvent
class RpcLogEvent
{
/**
* Timestamp in format RFC3339 representing when this event ocurred
Expand Down Expand Up @@ -120,6 +120,8 @@ class LogEvent
public function __construct(null|float $startTime = null)

Check failure on line 120 in src/Logging/RpcLogEvent.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

PHPDoc tag @param for parameter $startTime with type string|null is not subtype of native type float|null.
{
$this->timestamp = date(DATE_RFC3339);

// Takes the micro time and convets it to millis
$this->milliseconds = round(microtime(true) * 1000);

if ($startTime) {
Expand Down
10 changes: 5 additions & 5 deletions tests/Logging/LoggingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

namespace Google\Auth\Tests\Logging;

use Google\Auth\Logging\LogEvent;
use Google\Auth\Logging\LoggingTrait;
use Google\Auth\Logging\RpcLogEvent;
use Google\Auth\Logging\StdOutLogger;
use Google\Auth\Tests\BaseTest;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -92,9 +92,9 @@ public function testLogResponse()
$this->assertEquals($event->status, $parsedInfoEvent['jsonPayload']['response.status']);
}

private function getNewLogEvent(): LogEvent
private function getNewLogEvent(): RpcLogEvent
{
$event = new LogEvent();
$event = new RpcLogEvent();
$event->clientId = 123;
$event->method = 'get';
$event->url = 'test.com';
Expand Down Expand Up @@ -124,12 +124,12 @@ public function __construct()
$this->logger = new StdOutLogger();
}

public function logRequestEvent(LogEvent $event): void
public function logRequestEvent(RpcLogEvent $event): void
{
$this->logRequest($event);
}

public function logResponseEvent(LogEvent $event): void
public function logResponseEvent(RpcLogEvent $event): void
{
$this->logResponse($event);
}
Expand Down

0 comments on commit 98054c8

Please sign in to comment.