Skip to content

Commit 3f14f00

Browse files
committed
Merge branch 'master' into 9.x
2 parents e579087 + 00fc85e commit 3f14f00

28 files changed

+122
-401
lines changed

integrations/guzzle.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
use function GuzzleHttp\Promise\rejection_for;
3+
use GuzzleHttp\Promise\Create;
44
use Illuminated\Console\Exceptions\RuntimeException;
55
use Psr\Http\Message\RequestInterface;
66
use Psr\Http\Message\ResponseInterface;
@@ -12,19 +12,13 @@
1212
*
1313
* @see https://github.com/dmitry-ivanov/laravel-console-logger#guzzle-6-integration
1414
* @see http://docs.guzzlephp.org/en/stable/handlers-and-middleware.html
15-
*
16-
* @param \Psr\Log\LoggerInterface $logger
17-
* @param string $type
18-
* @param callable|null $shouldLogRequestParams
19-
* @param callable|null $shouldLogResponseBody
20-
* @return \Closure
2115
*/
22-
function iclogger_guzzle_middleware(LoggerInterface $logger, string $type = 'raw', callable $shouldLogRequestParams = null, callable $shouldLogResponseBody = null)
16+
function iclogger_guzzle_middleware(LoggerInterface $logger, string $type = 'raw', callable $shouldLogRequestParams = null, callable $shouldLogResponseBody = null): Closure
2317
{
2418
return function (callable $handler) use ($logger, $type, $shouldLogRequestParams, $shouldLogResponseBody) {
2519
return function (RequestInterface $request, array $options) use ($handler, $logger, $type, $shouldLogRequestParams, $shouldLogResponseBody) {
2620
// Gather information about the request
27-
$method = (string) $request->getMethod();
21+
$method = $request->getMethod();
2822
$uri = (string) $request->getUri();
2923
$body = (string) $request->getBody();
3024

@@ -80,6 +74,7 @@ function (ResponseInterface $response) use ($request, $logger, $type, $shouldLog
8074
}
8175
// Save the parsed body of response, so that it could be re-used instead of double decoding
8276
if (!empty($context)) {
77+
/** @noinspection PhpUndefinedFieldInspection */
8378
$response->iclParsedBody = $context;
8479
}
8580
}
@@ -88,7 +83,7 @@ function (ResponseInterface $response) use ($request, $logger, $type, $shouldLog
8883
return $response;
8984
},
9085
function ($reason) {
91-
return rejection_for($reason);
86+
return Create::rejectionFor($reason);
9287
}
9388
);
9489
};

src/Exceptions/ExceptionHandler.php

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,41 @@
33
namespace Illuminated\Console\Exceptions;
44

55
use Illuminate\Foundation\Exceptions\Handler;
6-
use Psr\Log\LoggerInterface;
6+
use Monolog\Logger;
77
use Throwable;
88

99
class ExceptionHandler extends Handler
1010
{
1111
/**
1212
* The logger instance.
13-
*
14-
* @var \Psr\Log\LoggerInterface
1513
*/
16-
private $logger;
14+
private Logger $logger;
1715

1816
/**
1917
* Time when execution started.
20-
*
21-
* @var float
2218
*/
23-
private $timeStarted;
24-
25-
/**
26-
* Time when execution finished.
27-
*
28-
* @var float
29-
*/
30-
private $timeFinished;
19+
private float $timeStarted;
3120

3221
/**
3322
* Reserved memory for the shutdown execution.
3423
*
3524
* @see https://github.com/dmitry-ivanov/laravel-console-logger/issues/4
36-
*
37-
* @var string
3825
*/
39-
protected $reservedMemory;
26+
protected ?string $reservedMemory;
4027

4128
/**
4229
* Initialize the exception handler.
43-
*
44-
* @param \Psr\Log\LoggerInterface $logger
45-
* @return void
4630
*/
47-
public function initialize(LoggerInterface $logger)
31+
public function initialize(Logger $logger): void
4832
{
4933
$this->setLogger($logger);
5034
$this->registerShutdownFunction();
5135
}
5236

5337
/**
5438
* Set the logger.
55-
*
56-
* @param \Psr\Log\LoggerInterface $logger
57-
* @return void
5839
*/
59-
public function setLogger(LoggerInterface $logger)
40+
public function setLogger(Logger $logger): void
6041
{
6142
$this->logger = $logger;
6243
}
@@ -66,11 +47,8 @@ public function setLogger(LoggerInterface $logger)
6647
*
6748
* Note that this method doesn't decorate, but overwrite the parent method:
6849
* @see https://github.com/dmitry-ivanov/laravel-console-logger/pull/11
69-
*
70-
* @param \Throwable $e
71-
* @return void
7250
*/
73-
public function report(Throwable $e)
51+
public function report(Throwable $e): void
7452
{
7553
$context = [
7654
'code' => $e->getCode(),
@@ -93,11 +71,8 @@ public function report(Throwable $e)
9371

9472
/**
9573
* Add Sentry support.
96-
*
97-
* @param \Throwable $e
98-
* @return void
9974
*/
100-
private function addSentrySupport(Throwable $e)
75+
private function addSentrySupport(Throwable $e): void
10176
{
10277
if (app()->bound('sentry') && $this->shouldReport($e)) {
10378
app('sentry')->captureException($e);
@@ -106,10 +81,8 @@ private function addSentrySupport(Throwable $e)
10681

10782
/**
10883
* Register the shutdown function.
109-
*
110-
* @return void
11184
*/
112-
private function registerShutdownFunction()
85+
private function registerShutdownFunction(): void
11386
{
11487
$this->timeStarted = microtime(true);
11588
$this->reservedMemory = str_repeat(' ', 20 * 1024);
@@ -119,23 +92,21 @@ private function registerShutdownFunction()
11992

12093
/**
12194
* Callback for the shutdown function.
122-
*
123-
* @return void
12495
*/
125-
public function onShutdown()
96+
public function onShutdown(): void
12697
{
12798
$this->reservedMemory = null;
12899

129-
$this->timeFinished = microtime(true);
130-
$executionTime = round($this->timeFinished - $this->timeStarted, 3);
100+
$timeFinished = microtime(true);
101+
$executionTime = round($timeFinished - $this->timeStarted, 3);
131102
$this->logger->info("Execution time: {$executionTime} sec.");
132103

133104
$memoryPeak = format_bytes(memory_get_peak_usage(true));
134105
$this->logger->info("Memory peak usage: {$memoryPeak}.");
135106

136107
$this->logger->info('%separator%');
137108

138-
$handlers = (array) $this->logger->getHandlers();
109+
$handlers = $this->logger->getHandlers();
139110
foreach ($handlers as $handler) {
140111
$handler->close();
141112
}

src/Exceptions/RuntimeException.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@ class RuntimeException extends SymfonyRuntimeException
99
{
1010
/**
1111
* The context.
12-
*
13-
* @var array
1412
*/
15-
private $context;
13+
private array $context;
1614

1715
/**
1816
* Create a new instance of the exception.
19-
*
20-
* @param string $message
21-
* @param array $context
22-
* @param int $code
23-
* @param \Exception|null $previous
24-
* @return void
2517
*/
2618
public function __construct(string $message = '', array $context = [], int $code = 0, Exception $previous = null)
2719
{
@@ -32,10 +24,8 @@ public function __construct(string $message = '', array $context = [], int $code
3224

3325
/**
3426
* Get the context.
35-
*
36-
* @return array
3727
*/
38-
public function getContext()
28+
public function getContext(): array
3929
{
4030
return $this->context;
4131
}

0 commit comments

Comments
 (0)