Skip to content

Commit

Permalink
Applied automated CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Sep 19, 2022
1 parent 068ae33 commit 1f6df0e
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions bin/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ static function (int $errorCode, string $message = '', string $file = '', int $l
E_STRICT | E_NOTICE | E_WARNING,
);

$variables = EnvironmentVariables::fromEnvironment(new ImportGpgKeyFromStringViaTemporaryFile());
$logger = new Logger(
$variables = EnvironmentVariables::fromEnvironment(new ImportGpgKeyFromStringViaTemporaryFile());
$logger = new Logger(
'automatic-releases',
[new StreamHandler(STDERR, $variables->logLevel())],
[
new ConvertLogContextHttpRequestsIntoStrings(),
new ConvertLogContextHttpResponsesIntoStrings(),
]
],
);
$loadEvent = new LoadCurrentGithubEventFromGithubActionPath($variables);
$fetch = new FetchAndSetCurrentUserByReplacingCurrentOriginRemote($variables);
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClient/LoggingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function sendRequest(RequestInterface $request): ResponseInterface
[
'request' => $request,
'response' => $response,
]
],
);

return $response;
}
}
}
6 changes: 4 additions & 2 deletions src/Monolog/ConvertLogContextHttpRequestsIntoStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Monolog\Processor\ProcessorInterface;
use Psr\Http\Message\RequestInterface;

use function array_map;

/** @internal */
final class ConvertLogContextHttpRequestsIntoStrings implements ProcessorInterface
{
Expand All @@ -31,7 +33,7 @@ public function __invoke(LogRecord $record): LogRecord
->__toString();
}, $record->context),
$record->extra,
$record->formatted
$record->formatted,
);
}
}
}
6 changes: 4 additions & 2 deletions src/Monolog/ConvertLogContextHttpResponsesIntoStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Monolog\Processor\ProcessorInterface;
use Psr\Http\Message\ResponseInterface;

use function array_map;

/** @internal */
final class ConvertLogContextHttpResponsesIntoStrings implements ProcessorInterface
{
Expand All @@ -31,7 +33,7 @@ public function __invoke(LogRecord $record): LogRecord
. '"';
}, $record->context),
$record->extra,
$record->formatted
$record->formatted,
);
}
}
}
5 changes: 1 addition & 4 deletions test/unit/HttpClient/LoggingHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@

use Http\Discovery\Psr17FactoryDiscovery;
use Laminas\AutomaticReleases\HttpClient\LoggingHttpClient;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use Psr\Log\LoggerInterface;
use function fopen;

/** @covers \Laminas\AutomaticReleases\HttpClient\LoggingHttpClient */
final class LoggingHttpClientTest extends TestCase
Expand Down Expand Up @@ -48,7 +45,7 @@ public function testWillLogRequestAndResponse(): void
self::assertSame(
$response,
(new LoggingHttpClient($next, $logger))
->sendRequest($request)
->sendRequest($request),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testWillScrubSensitiveRequestInformation(): void
'foo' => 'bar',
'plain request' => 'GET http://example.com/foo',
'sensitive request' => 'POST https://example.com/foo?bar=baz',
]
],
),
(new ConvertLogContextHttpRequestsIntoStrings())(new LogRecord(
$date,
Expand All @@ -49,8 +49,8 @@ public function testWillScrubSensitiveRequestInformation(): void
'foo' => 'bar',
'plain request' => $plainRequest,
'sensitive request' => $sensitiveRequest,
]
))
],
)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@

use DateTimeImmutable;
use Http\Discovery\Psr17FactoryDiscovery;
use Laminas\AutomaticReleases\HttpClient\LoggingHttpClient;
use Laminas\AutomaticReleases\Monolog\ConvertLogContextHttpRequestsIntoStrings;
use Laminas\AutomaticReleases\Monolog\ConvertLogContextHttpResponsesIntoStrings;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
use Monolog\Logger;
use Monolog\LogRecord;
use PHPUnit\Framework\TestCase;
use Psr\Http\Client\ClientInterface;
use function fopen;

/** @covers \Laminas\AutomaticReleases\Monolog\ConvertLogContextHttpResponsesIntoStrings */
final class ConvertLogContextHttpResponsesIntoStringsTest extends TestCase
Expand Down Expand Up @@ -44,7 +38,7 @@ public function testWillScrubSensitiveRequestInformation(): void
'foo' => 'bar',
'plain response' => '401 ""',
'sensitive response' => '403 "this should be printed"',
]
],
),
(new ConvertLogContextHttpResponsesIntoStrings())(new LogRecord(
$date,
Expand All @@ -55,8 +49,8 @@ public function testWillScrubSensitiveRequestInformation(): void
'foo' => 'bar',
'plain response' => $plainResponse,
'sensitive response' => $sensitiveResponse,
]
))
],
)),
);
}
}
7 changes: 5 additions & 2 deletions test/unit/Monolog/VerifyLoggingIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;

use function fopen;
use function rewind;
use function stream_get_contents;

/**
* Small integration test to ensure future compatibility with monolog in our setup.
Expand All @@ -37,7 +40,7 @@ public function testLoggedRequestAndResponseBodyPartsDoNotContainSecretsAndPostD
[
new ConvertLogContextHttpRequestsIntoStrings(),
new ConvertLogContextHttpResponsesIntoStrings(),
]
],
);

$logger->debug('message', ['request' => $request, 'response' => $response]);
Expand All @@ -47,7 +50,7 @@ public function testLoggedRequestAndResponseBodyPartsDoNotContainSecretsAndPostD
self::assertStringContainsString(
': message {"request":"GET http://example.com/foo/bar","response":"204 \"hello world\""} []',
stream_get_contents($stream),
'Request and response contents have been serialized into the final log message'
'Request and response contents have been serialized into the final log message',
);
}
}

0 comments on commit 1f6df0e

Please sign in to comment.