Skip to content
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
12 changes: 6 additions & 6 deletions src/Illuminate/Bus/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ public function add($jobs)
if (is_array($job)) {
$count += count($job);

return with($this->prepareBatchedChain($job), function ($chain) {
return $chain->first()
->allOnQueue($this->options['queue'] ?? null)
->allOnConnection($this->options['connection'] ?? null)
->chain($chain->slice(1)->values()->all());
});
$chain = $this->prepareBatchedChain($job);

return $chain->first()
->allOnQueue($this->options['queue'] ?? null)
->allOnConnection($this->options['connection'] ?? null)
->chain($chain->slice(1)->values()->all());
} else {
$job->withBatchId($this->id);

Expand Down
18 changes: 9 additions & 9 deletions src/Illuminate/Console/Signals.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public function register($signal, $callback)
{
$this->previousHandlers[$signal] ??= $this->initializeSignal($signal);

with($this->getHandlers(), function ($handlers) use ($signal) {
$handlers[$signal] ??= $this->initializeSignal($signal);
$handlers = $this->getHandlers();

$this->setHandlers($handlers);
});
$handlers[$signal] ??= $this->initializeSignal($signal);

$this->setHandlers($handlers);

$this->registry->register($signal, $callback);

with($this->getHandlers(), function ($handlers) use ($signal) {
$lastHandlerInserted = array_pop($handlers[$signal]);
$handlers = $this->getHandlers();

$lastHandlerInserted = array_pop($handlers[$signal]);

array_unshift($handlers[$signal], $lastHandlerInserted);
array_unshift($handlers[$signal], $lastHandlerInserted);

$this->setHandlers($handlers);
});
$this->setHandlers($handlers);
}

/**
Expand Down
42 changes: 21 additions & 21 deletions src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ protected function shouldIgnoreDeprecationErrors()
*/
protected function ensureDeprecationLoggerIsConfigured()
{
with(static::$app['config'], function ($config) {
if ($config->get('logging.channels.deprecations')) {
return;
}
$config = static::$app['config'];

$this->ensureNullLogDriverIsConfigured();
if ($config->get('logging.channels.deprecations')) {
return;
}

if (is_array($options = $config->get('logging.deprecations'))) {
$driver = $options['channel'] ?? 'null';
} else {
$driver = $options ?? 'null';
}
$this->ensureNullLogDriverIsConfigured();

$config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}"));
});
if (is_array($options = $config->get('logging.deprecations'))) {
$driver = $options['channel'] ?? 'null';
} else {
$driver = $options ?? 'null';
}

$config->set('logging.channels.deprecations', $config->get("logging.channels.{$driver}"));
}

/**
Expand All @@ -156,16 +156,16 @@ protected function ensureDeprecationLoggerIsConfigured()
*/
protected function ensureNullLogDriverIsConfigured()
{
with(static::$app['config'], function ($config) {
if ($config->get('logging.channels.null')) {
return;
}
$config = static::$app['config'];

$config->set('logging.channels.null', [
'driver' => 'monolog',
'handler' => NullHandler::class,
]);
});
if ($config->get('logging.channels.null')) {
return;
}

$config->set('logging.channels.null', [
'driver' => 'monolog',
'handler' => NullHandler::class,
]);
}

/**
Expand Down
38 changes: 19 additions & 19 deletions src/Illuminate/Foundation/Console/DocsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ public function handle(Http $http, Cache $cache)
*/
protected function openUrl()
{
with($this->url(), function ($url) {
$this->components->info("Opening the docs to: <fg=yellow>{$url}</>");
$url = $this->url();

$this->open($url);
});
$this->components->info("Opening the docs to: <fg=yellow>{$url}</>");

$this->open($url);
}

/**
Expand All @@ -145,9 +145,9 @@ protected function url()
]);
}

return with($this->page(), function ($page) {
return trim("https://laravel.com/docs/{$this->version()}/{$page}#{$this->section($page)}", '#/');
});
$page = $this->page();

return trim("https://laravel.com/docs/{$this->version()}/{$page}#{$this->section($page)}", '#/');
}

/**
Expand All @@ -157,15 +157,15 @@ protected function url()
*/
protected function page()
{
return with($this->resolvePage(), function ($page) {
if ($page === null) {
$this->components->warn('Unable to determine the page you are trying to visit.');
$page = $this->resolvePage();

return '/';
}
if ($page === null) {
$this->components->warn('Unable to determine the page you are trying to visit.');

return $page;
});
return '/';
}

return $page;
}

/**
Expand Down Expand Up @@ -441,11 +441,11 @@ public function docs()
*/
protected function refreshDocs()
{
with($this->fetchDocs(), function ($response) {
if ($response->successful()) {
$this->cache->put("artisan.docs.{{$this->version()}}.index", $response->collect(), CarbonInterval::months(2));
}
});
$response = $this->fetchDocs();

if ($response->successful()) {
$this->cache->put("artisan.docs.{{$this->version()}}.index", $response->collect(), CarbonInterval::months(2));
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,22 +225,22 @@ protected function assertModelMissing($model)
*/
public function expectsDatabaseQueryCount($expected, $connection = null)
{
with($this->getConnection($connection), function ($connectionInstance) use ($expected, $connection) {
$actual = 0;

$connectionInstance->listen(function (QueryExecuted $event) use (&$actual, $connectionInstance, $connection) {
if (is_null($connection) || $connectionInstance === $event->connection) {
$actual++;
}
});

$this->beforeApplicationDestroyed(function () use (&$actual, $expected, $connectionInstance) {
$this->assertSame(
$expected,
$actual,
"Expected {$expected} database queries on the [{$connectionInstance->getName()}] connection. {$actual} occurred."
);
});
$connectionInstance = $this->getConnection($connection);

$actual = 0;

$connectionInstance->listen(function (QueryExecuted $event) use (&$actual, $connectionInstance, $connection) {
if (is_null($connection) || $connectionInstance === $event->connection) {
$actual++;
}
});

$this->beforeApplicationDestroyed(function () use (&$actual, $expected, $connectionInstance) {
$this->assertSame(
$expected,
$actual,
"Expected {$expected} database queries on the [{$connectionInstance->getName()}] connection. {$actual} occurred."
);
});

return $this;
Expand Down
12 changes: 7 additions & 5 deletions src/Illuminate/Mail/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,17 @@ function ($data) use ($mail, $options) {
*/
public function isEquivalent(Attachment $attachment, $options = [])
{
return with([
$newOptions = [
'as' => $options['as'] ?? $attachment->as,
'mime' => $options['mime'] ?? $attachment->mime,
], fn ($options) => $this->attachWith(
];

return $this->attachWith(
fn ($path) => [$path, ['as' => $this->as, 'mime' => $this->mime]],
fn ($data) => [$data(), ['as' => $this->as, 'mime' => $this->mime]],
) === $attachment->attachWith(
fn ($path) => [$path, $options],
fn ($data) => [$data(), $options],
));
fn ($path) => [$path, $newOptions],
fn ($data) => [$data(), $newOptions],
);
}
}
20 changes: 10 additions & 10 deletions src/Illuminate/Routing/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ protected function registerPsrRequest()
{
$this->app->bind(ServerRequestInterface::class, function ($app) {
if (class_exists(PsrHttpFactory::class)) {
return with((new PsrHttpFactory)
->createRequest($illuminateRequest = $app->make('request')), function (ServerRequestInterface $request) use ($illuminateRequest) {
if ($illuminateRequest->getContentTypeFormat() !== 'json' && $illuminateRequest->request->count() === 0) {
return $request;
}

return $request->withParsedBody(
array_merge($request->getParsedBody() ?? [], $illuminateRequest->getPayload()->all())
);
});
$illuminateRequest = $app->make('request');
$request = (new PsrHttpFactory)->createRequest($illuminateRequest);

if ($illuminateRequest->getContentTypeFormat() !== 'json' && $illuminateRequest->request->count() === 0) {
return $request;
}

return $request->withParsedBody(
array_merge($request->getParsedBody() ?? [], $illuminateRequest->getPayload()->all())
);
}

throw new BindingResolutionException('Unable to resolve PSR request. Please install the "symfony/psr-http-message-bridge" package.');
Expand Down
7 changes: 3 additions & 4 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,9 @@ public function validateBetween($attribute, $value, $parameters)
$this->requireParameterCount(2, $parameters, 'between');

try {
return with(
BigNumber::of($this->getSize($attribute, $value)),
fn ($size) => $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1]))
);
$size = BigNumber::of($this->getSize($attribute, $value));

return $size->isGreaterThanOrEqualTo($this->trim($parameters[0])) && $size->isLessThanOrEqualTo($this->trim($parameters[1]));
} catch (MathException) {
return false;
}
Expand Down
16 changes: 3 additions & 13 deletions tests/Foundation/Bootstrap/HandleExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ protected function setUp(): void
protected function handleExceptions()
{
return tap(new HandleExceptions(), function ($instance) {
with(new ReflectionClass($instance), function ($reflection) use ($instance) {
$reflection->getProperty('app')->setValue($instance, $this->app);
});
(new ReflectionClass($instance))->getProperty('app')->setValue($instance, $this->app);
});
}

Expand Down Expand Up @@ -381,11 +379,7 @@ public function testForgetApp()
{
$instance = $this->handleExceptions();

$appResolver = fn () => with(new ReflectionClass($instance), function ($reflection) use ($instance) {
$property = $reflection->getProperty('app');

return $property->getValue($instance);
});
$appResolver = fn () => (new ReflectionClass($instance))->getProperty('app')->getValue($instance);

$this->assertNotNull($appResolver());

Expand All @@ -398,11 +392,7 @@ public function testHandlerForgetsPreviousApp()
{
$instance = $this->handleExceptions();

$appResolver = fn () => with(new ReflectionClass($instance), function ($reflection) use ($instance) {
$property = $reflection->getProperty('app');

return $property->getValue($instance);
});
$appResolver = fn () => (new ReflectionClass($instance))->getProperty('app')->getValue($instance);

$this->assertSame($this->app, $appResolver());

Expand Down