Skip to content

Commit

Permalink
bc
Browse files Browse the repository at this point in the history
  • Loading branch information
chu121su12 committed Feb 15, 2023
1 parent 055741f commit 5fa2451
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 64 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,9 @@ public static function where($array, callable $callback)
*/
public static function whereNotNull($array)
{
return static::where($array, fn ($value) => ! is_null($value));
return static::where($array, function ($value) {
return ! is_null($value);
});
}

/**
Expand Down
28 changes: 20 additions & 8 deletions src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ public function avg($callback = null)
{
$callback = $this->valueRetriever($callback);

$items = $this
->map(fn ($value) => $callback($value))
->filter(fn ($value) => ! is_null($value));
$items = $this->map(function ($value) use ($callback) {
return $callback($value);
})->filter(function ($value) {
return ! is_null($value);
});

if ($count = $items->count()) {
return $items->sum() / $count;
Expand Down Expand Up @@ -353,10 +355,14 @@ public function duplicatesStrict($callback = null)
protected function duplicateComparator($strict)
{
if ($strict) {
return fn ($a, $b) => $a === $b;
return function ($a, $b) {
return $a === $b;
};
}

return fn ($a, $b) => $a == $b;
return function ($a, $b) {
return $a == $b;
};
}

/**
Expand Down Expand Up @@ -1159,7 +1165,9 @@ public function sliding($size = 2, $step = 1)
{
$chunks = floor(($this->count() - $size) / $step) + 1;

return static::times($chunks, fn ($number) => $this->slice(($number - 1) * $step, $size));
return static::times($chunks, function ($number) use ($size, $step) {
return $this->slice(($number - 1) * $step, $size);
});
}

/**
Expand Down Expand Up @@ -1640,9 +1648,13 @@ public function values()
*/
public function zip($items)
{
$arrayableItems = array_map(fn ($items) => $this->getArrayableItems($items), func_get_args());
$arrayableItems = array_map(function ($items) {
return $this->getArrayableItems($items);
}, func_get_args());

$params = array_merge([fn () => new static(func_get_args()), $this->items], $arrayableItems);
$params = array_merge([function () {
return new static(func_get_args());
}, $this->items], $arrayableItems);

return new static(array_map(...$params));
}
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ public function except($keys)
public function filter(callable $callback = null)
{
if (is_null($callback)) {
$callback = fn ($value) => (bool) $value;
$callback = function ($value) {
return (bool) $value;
};
}

return new static(function () use ($callback) {
Expand Down Expand Up @@ -1519,7 +1521,9 @@ public function takeWhile($value)
/** @var callable(TValue, TKey): bool $callback */
$callback = $this->useAsCallable($value) ? $value : $this->equality($value);

return $this->takeUntil(fn ($item, $key) => ! $callback($item, $key));
return $this->takeUntil(function ($item, $key) use ($callback) {
return ! $callback($item, $key);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/CacheEventMutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function exists(Event $event)
if ($this->cache->store($this->store)->getStore() instanceof LockProvider) {
return ! $this->cache->store($this->store)->getStore()
->lock($event->mutexName(), $event->expiresAt * 60)
->get(fn () => true);
->get(function () { return true; });
}

return $this->cache->store($this->store)->has($event->mutexName());
Expand Down
12 changes: 8 additions & 4 deletions src/Illuminate/Database/Console/Migrations/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ public function handle()
$this->components->twoColumnDetail('<fg=gray>Migration name</>', '<fg=gray>Batch / Status</>');

$migrations
->when($this->option('pending'), fn ($collection) => $collection->filter(function ($migration) {
return str($migration[1])->contains('Pending');
}))
->when($this->option('pending'), function ($collection) {
return $collection->filter(function ($migration) {
return str($migration[1])->contains('Pending');
});
})
->each(
function ($migration) { return $this->components->twoColumnDetail($migration[0], $migration[1]); }
function ($migration) {
return $this->components->twoColumnDetail($migration[0], $migration[1]);
}
);

$this->newLine();
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ public function push()
*/
public function pushQuietly()
{
return static::withoutEvents(fn () => $this->push());
return static::withoutEvents(function () {
return $this->push();
});
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Database/Eloquent/Relations/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,13 @@ public function createMany(/*iterable */$records)
* @param iterable $records
* @return \Illuminate\Database\Eloquent\Collection
*/
public function createManyQuietly(iterable $records)
public function createManyQuietly(/*iterable */$records)
{
return Model::withoutEvents(fn () => $this->createMany($records));
$records = backport_type_check('iterable', $records);

return Model::withoutEvents(function () use ($records) {
return $this->createMany($records);
});
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,10 @@ protected function resolvePath(/*string */$path)
return new $class;
}

$migration = static::$requiredPathCache[$path] ??= $this->files->getRequire($path);
if (! isset(static::$requiredPathCache[$path])) {
static::$requiredPathCache[$path] = $this->files->getRequire($path);
}
$migration = static::$requiredPathCache[$path];

if (is_object($migration)) {
return clone $migration;
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public function whereFullText(Builder $query, $where)
*/
protected function compileIndexHint(Builder $query, $indexHint)
{
return match ($indexHint->type) {
'hint' => "use index ({$indexHint->index})",
'force' => "force index ({$indexHint->index})",
default => "ignore index ({$indexHint->index})",
};
switch ($indexHint->type) {
case 'hint': return "use index ({$indexHint->index})";
case 'force': return "force index ({$indexHint->index})";
default: return "ignore index ({$indexHint->index})";
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,15 @@ protected function shouldntReport(/*Throwable */$e)
*/
public function stopIgnoring(string $exception)
{
$exception = backport_type_check('string', $exception);

$this->dontReport = collect($this->dontReport)
->reject(fn ($ignored) => $ignored === $exception)->values()->all();
->reject(function ($ignored) use ($exception) { return $ignored === $exception; })
->values()->all();

$this->internalDontReport = collect($this->internalDontReport)
->reject(fn ($ignored) => $ignored === $exception)->values()->all();
->reject(function ($ignored) use ($exception) { return $ignored === $exception; })
->values()->all();

return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Foundation/Testing/DatabaseTruncation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ protected function truncateTablesForConnection(ConnectionInterface $connection,
collect(static::$allTables[$name])
->when(
property_exists($this, 'tablesToTruncate'),
fn ($tables) => $tables->intersect($this->tablesToTruncate),
fn ($tables) => $tables->diff($this->exceptTables($name))
function ($tables) { return $tables->intersect($this->tablesToTruncate); },
function ($tables) { return $tables->diff($this->exceptTables($name)); }
)
->filter(fn ($table) => $connection->table($table)->exists())
->each(fn ($table) => $connection->table($table)->truncate());
->filter(function ($table) use ($connection) { return $connection->table($table)->exists(); })
->each(function ($table) use ($connection) { return $connection->table($table)->truncate(); });

$connection->setEventDispatcher($dispatcher);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected function createSesV2Transport(array $config)

return new SesV2Transport(
new SesV2Client($this->addSesCredentials($config)),
$config['options'] ?? []
isset($config['options']) ? $config['options'] : []
);
}

Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Mail/Transport/SesTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public function setOptions(array $options)
*
* @return string
*/
public function __toString(): string
#[\ReturnTypeWillChange]
public function __toString()/*: string*/
{
return 'ses';
}
Expand Down
9 changes: 6 additions & 3 deletions src/Illuminate/Mail/Transport/SesV2Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(SesV2Client $ses, $options = [])
/**
* {@inheritDoc}
*/
protected function doSend(SentMessage $message): void
protected function doSend(SentMessage $message)/*: void*/
{
$options = $this->options;

Expand Down Expand Up @@ -77,7 +77,9 @@ protected function doSend(SentMessage $message): void
)
);
} catch (AwsException $e) {
$reason = $e->getAwsErrorMessage() ?? $e->getMessage();
$awsReason = $e->getAwsErrorMessage();

$reason = isset($awsReason) ? $awsReason : $e->getMessage();

throw new Exception(
sprintf('Request to AWS SES V2 API failed. Reason: %s.', $reason),
Expand Down Expand Up @@ -128,7 +130,8 @@ public function setOptions(array $options)
*
* @return string
*/
public function __toString(): string
#[\ReturnTypeWillChange]
public function __toString()/*: string*/
{
return 'ses-v2';
}
Expand Down
20 changes: 12 additions & 8 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,23 +738,27 @@ public static function pluralStudly($value, $count = 2)
public static function password($length = 32, $letters = true, $numbers = true, $symbols = true, $spaces = false)
{
return (new Collection)
->when($letters, fn ($c) => $c->merge([
->when($letters, function ($c) { return $c->merge([
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
]))
->when($numbers, fn ($c) => $c->merge([
]); })
->when($numbers, function ($c) { return $c->merge([
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
]))
->when($symbols, fn ($c) => $c->merge([
]); })
->when($symbols, function ($c) { return $c->merge([
'~', '!', '#', '$', '%', '^', '&', '*', '(', ')', '-',
'_', '.', ',', '<', '>', '?', '/', '\\', '{', '}', '[',
']', '|', ':', ';',
]))
->when($spaces, fn ($c) => $c->merge([' ']))
->pipe(fn ($c) => Collection::times($length, fn () => $c[random_int(0, $c->count() - 1)]))
]); })
->when($spaces, function ($c) { return $c->merge([' ']); })
->pipe(function ($c) use ($length) {
return Collection::times($length, function () use ($c) {
return $c[random_int(0, $c->count() - 1)];
});
})
->implode('');
}

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Support/Testing/Fakes/BusFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function assertDispatchedTimes($command, $times = 1)
$callback = null;

if ($command instanceof Closure) {
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
list($command, $callback) = [$this->firstClosureParameterType($command), $command];
}

$count = $this->dispatched($command, $callback)->count() +
Expand Down Expand Up @@ -215,7 +215,7 @@ public function assertDispatchedSyncTimes($command, $times = 1)
$callback = null;

if ($command instanceof Closure) {
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
list($command, $callback) = [$this->firstClosureParameterType($command), $command];
}

$count = $this->dispatchedSync($command, $callback)->count();
Expand Down Expand Up @@ -280,7 +280,7 @@ public function assertDispatchedAfterResponseTimes($command, $times = 1)
$callback = null;

if ($command instanceof Closure) {
[$command, $callback] = [$this->firstClosureParameterType($command), $command];
list($command, $callback) = [$this->firstClosureParameterType($command), $command];
}

$count = $this->dispatchedAfterResponse($command, $callback)->count();
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Translation/MessageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ private function extractFromString($part, $number)
private function stripConditions($segments)
{
return collect($segments)
->map(fn ($part) => preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part))
->map(function ($part) {
return preg_replace('/^[\{\[]([^\[\]\{\}]*)[\}\]]/', '', $part);
})
->all();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public function testMacroable()/*: void*/
}

/** @test */
public function testUseConfigPath(): void
public function testUseConfigPath()/*: void*/
{
$app = new Application;
$app->useConfigPath(__DIR__.'/fixtures/config');
Expand Down
3 changes: 3 additions & 0 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class FoundationInteractsWithDatabaseTest_testExpectsDatabaseQueryCount_class_1 extends TestingTestCase
{
use \PHPUnit\Framework\PhpUnit8Assert;
use CreatesApplication;

public function testExpectsDatabaseQueryCount()
Expand All @@ -26,6 +27,7 @@ public function testExpectsDatabaseQueryCount()

class FoundationInteractsWithDatabaseTest_testExpectsDatabaseQueryCount_class_2 extends TestingTestCase
{
use \PHPUnit\Framework\PhpUnit8Assert;
use CreatesApplication;

public function testExpectsDatabaseQueryCount()
Expand All @@ -36,6 +38,7 @@ public function testExpectsDatabaseQueryCount()

class FoundationInteractsWithDatabaseTest_testExpectsDatabaseQueryCount_class_3 extends TestingTestCase
{
use \PHPUnit\Framework\PhpUnit8Assert;
use CreatesApplication;

public function testExpectsDatabaseQueryCount()
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Events/EventFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function testAssertListening()

public function testMissingMethodsAreForwarded()
{
Event::macro('foo', fn () => 'bar');
Event::macro('foo', function () { return 'bar'; });

$this->assertEquals('bar', Event::fake()->foo());
}
Expand Down
Loading

0 comments on commit 5fa2451

Please sign in to comment.