Skip to content

Commit

Permalink
[11.x] No need to redeclare variables (#53887)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Dec 13, 2024
1 parent c17277e commit 69284e3
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ protected function flushOutputBuffer()
->map(fn ($line) => trim($line))
->filter()
->each(function ($line) {
if ((new Stringable($line))->contains('Development Server (http')) {
$stringable = new Stringable($line);

if ($stringable->contains('Development Server (http')) {
if ($this->serverRunningHasBeenDisplayed === false) {
$this->serverRunningHasBeenDisplayed = true;

Expand All @@ -292,23 +294,19 @@ protected function flushOutputBuffer()
return;
}

if ((new Stringable($line))->contains(' Accepted')) {
$requestPort = static::getRequestPortFromLine($line);
$requestPort = static::getRequestPortFromLine($line);

if ($stringable->contains(' Accepted')) {
$this->requestsPool[$requestPort] = [
$this->getDateFromLine($line),
$this->requestsPool[$requestPort][1] ?? false,
microtime(true),
];
} elseif ((new Stringable($line))->contains([' [200]: GET '])) {
$requestPort = static::getRequestPortFromLine($line);

} elseif ($stringable->contains([' [200]: GET '])) {
$this->requestsPool[$requestPort][1] = trim(explode('[200]: GET', $line)[1]);
} elseif ((new Stringable($line))->contains('URI:')) {
$requestPort = static::getRequestPortFromLine($line);

} elseif ($stringable->contains('URI:')) {
$this->requestsPool[$requestPort][1] = trim(explode('URI: ', $line)[1]);
} elseif ((new Stringable($line))->contains(' Closing')) {
} elseif ($stringable->contains(' Closing')) {
$requestPort = static::getRequestPortFromLine($line);

if (empty($this->requestsPool[$requestPort])) {
Expand Down Expand Up @@ -339,11 +337,11 @@ protected function flushOutputBuffer()

$this->output->write(' '.str_repeat('<fg=gray>.</>', $dots));
$this->output->writeln(" <fg=gray>~ {$runTime}</>");
} elseif ((new Stringable($line))->contains(['Closed without sending a request', 'Failed to poll event'])) {
} elseif ($stringable->contains(['Closed without sending a request', 'Failed to poll event'])) {
// ...
} elseif (! empty($line)) {
if ((new Stringable($line))->startsWith('[')) {
$line = (new Stringable($line))->after('] ');
if ($stringable->startsWith('[')) {
$line = $stringable->after('] ');
}

$this->output->writeln(" <fg=gray>$line</>");
Expand Down

1 comment on commit 69284e3

@vincentauger
Copy link

@vincentauger vincentauger commented on 69284e3 Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lucasmichot - moving $requestPort = static::getRequestPortFromLine($line); outside the check condition creates a bug as the Closed without sending a request does not get parsed/grouped properly by the regex in getRequestPortFromLine(). Since the regex does not return matches, the function then causes an exception which causes the server to fail with an InvalidArgumentException.

Example of line that will cause a problem:

 [Tue Dec 17 16:25:20 2024] 127.0.0.1:59356 Closed without sending a request; it was probably just an unused speculative preconnection

Please sign in to comment.