language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | laravel | framework | 6d5377bb0f04da3e9e233292ea7fc49e4ab02d3d.json | Apply fixes from StyleCI | tests/Support/SupportHelpersTest.php | @@ -600,6 +600,7 @@ public function testRetryWithPassingSleepCallback()
throw new RuntimeException;
}, function ($attempt, $exception) {
$this->assertInstanceOf(RuntimeException::class, $exception);
+
return $attempt * 100;
});
| false |
Other | laravel | framework | 105037b619bb1e180e79e2e0c634294d1859b406.json | Apply fixes from StyleCI | src/Illuminate/Foundation/Testing/DatabaseTransactions.php | @@ -20,7 +20,7 @@ public function beginDatabaseTransaction()
$connection->unsetEventDispatcher();
$connection->beginTransaction();
$connection->setEventDispatcher($dispatcher);
-
+
if ($this->app->resolved('db.transactions')) {
$this->app->make('db.transactions')->callbacksShouldIgnore(
$this->app->make('db.transactions')->getTransactions()->first() | false |
Other | laravel | framework | 21959000a2d64e1aae8d8c12d256c0a0234715f2.json | Add missing docblock (#42501) | src/Illuminate/Support/Facades/Http.php | @@ -21,6 +21,7 @@
* @method static \Illuminate\Http\Client\PendingRequest dd()
* @method static \Illuminate\Http\Client\PendingRequest dump()
* @method static \Illuminate\Http\Client\PendingRequest retry(int $times, int $sleepMilliseconds = 0, ?callable $when = null, bool $throw = true)
+ * @method static \Illuminate\Http\Client\ResponseSequence sequence(array $responses = [])
* @method static \Illuminate\Http\Client\PendingRequest sink(string|resource $to)
* @method static \Illuminate\Http\Client\PendingRequest stub(callable $callback)
* @method static \Illuminate\Http\Client\PendingRequest timeout(int $seconds) | false |
Other | laravel | framework | ffa6cca4285f87cf19b6dbc9986fb73fca04abd6.json | Introduce Arr::prependKeysWith helper (#42448)
* Adding new Arr helper to prepend all associative array key names with a provided prefix.
* Undoing incorrect delete of phpunit.xml.dist
* use Collections for mapping the keys.
* replace helper function by Collection class
* typo
* fix styleCI issues
* fix styleCI issues | src/Illuminate/Collections/Arr.php | @@ -466,6 +466,20 @@ public static function keyBy($array, $keyBy)
return Collection::make($array)->keyBy($keyBy)->all();
}
+ /**
+ * Prepend the key names of an associative array.
+ *
+ * @param array $array
+ * @param string $prependWith
+ * @return array
+ */
+ public static function prependKeysWith($array, $prependWith)
+ {
+ return Collection::make($array)->mapWithKeys(function ($item, $key) use ($prependWith) {
+ return [$prependWith.$key => $item];
+ })->all();
+ }
+
/**
* Get a subset of the items from the given array.
* | true |
Other | laravel | framework | ffa6cca4285f87cf19b6dbc9986fb73fca04abd6.json | Introduce Arr::prependKeysWith helper (#42448)
* Adding new Arr helper to prepend all associative array key names with a provided prefix.
* Undoing incorrect delete of phpunit.xml.dist
* use Collections for mapping the keys.
* replace helper function by Collection class
* typo
* fix styleCI issues
* fix styleCI issues | tests/Support/SupportArrTest.php | @@ -1076,4 +1076,25 @@ public function testKeyBy()
'498' => ['id' => '498', 'data' => 'hgi'],
], Arr::keyBy($array, 'id'));
}
+
+ public function testPrependKeysWith()
+ {
+ $array = [
+ 'id' => '123',
+ 'data' => '456',
+ 'list' => [1, 2, 3],
+ 'meta' => [
+ 'key' => 1,
+ ],
+ ];
+
+ $this->assertEquals([
+ 'test.id' => '123',
+ 'test.data' => '456',
+ 'test.list' => [1, 2, 3],
+ 'test.meta' => [
+ 'key' => 1,
+ ],
+ ], Arr::prependKeysWith($array, 'test.'));
+ }
} | true |
Other | laravel | framework | 55a6f1cdb4b107d31ca5e0d4b35cfd0f76dbb6d9.json | enhance docblocks of Validation Factory (#42407) | src/Illuminate/Validation/Factory.php | @@ -34,35 +34,35 @@ class Factory implements FactoryContract
/**
* All of the custom validator extensions.
*
- * @var array
+ * @var array<string, \Closure|string>
*/
protected $extensions = [];
/**
* All of the custom implicit validator extensions.
*
- * @var array
+ * @var array<string, \Closure|string>
*/
protected $implicitExtensions = [];
/**
* All of the custom dependent validator extensions.
*
- * @var array
+ * @var array<string, \Closure|string>
*/
protected $dependentExtensions = [];
/**
* All of the custom validator message replacers.
*
- * @var array
+ * @var array<string, \Closure|string>
*/
protected $replacers = [];
/**
* All of the fallback messages for custom rules.
*
- * @var array
+ * @var array<string, string>
*/
protected $fallbackMessages = [];
| false |
Other | laravel | framework | afb46417b352e6b6693af591497fe2752f3d83af.json | Update email.blade.php (#42388)
* Update email.blade.php
Change switch to match
* Update email.blade.php
* Update src/Illuminate/Notifications/resources/views/email.blade.php
Co-authored-by: Faissal Wahabali <fwahabali@gmail.com>
Co-authored-by: Faissal Wahabali <fwahabali@gmail.com> | src/Illuminate/Notifications/resources/views/email.blade.php | @@ -19,14 +19,10 @@
{{-- Action Button --}}
@isset($actionText)
<?php
- switch ($level) {
- case 'success':
- case 'error':
- $color = $level;
- break;
- default:
- $color = 'primary';
- }
+ $color = match ($level) {
+ 'success', 'error' => $level,
+ default => 'primary',
+ };
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }} | false |
Other | laravel | framework | dc724350ac1e9bf5491c6cc1e436b38f6f0973df.json | add missing onLastPage to CursorPaginator (#42301) | src/Illuminate/Pagination/CursorPaginator.php | @@ -121,6 +121,16 @@ public function onFirstPage()
return is_null($this->cursor) || ($this->cursor->pointsToPreviousItems() && ! $this->hasMore);
}
+ /**
+ * Determine if the paginator is on the last page.
+ *
+ * @return bool
+ */
+ public function onLastPage()
+ {
+ return ! $this->hasMorePages();
+ }
+
/**
* Get the instance as an array.
* | true |
Other | laravel | framework | dc724350ac1e9bf5491c6cc1e436b38f6f0973df.json | add missing onLastPage to CursorPaginator (#42301) | tests/Pagination/CursorPaginatorTest.php | @@ -78,6 +78,24 @@ public function testCanTransformPaginatorItems()
$this->assertSame([['id' => 6], ['id' => 7]], $p->items());
}
+ public function testLengthAwarePaginatorisOnFirstAndLastPage()
+ {
+ $paginator = new CursorPaginator([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]], 2, null, [
+ 'parameters' => ['id'],
+ ]);
+
+ $this->assertTrue($paginator->onFirstPage());
+ $this->assertFalse($paginator->onLastPage());
+
+ $cursor = new Cursor(['id' => 3]);
+ $paginator = new CursorPaginator([['id' => 3], ['id' => 4]], 2, $cursor, [
+ 'parameters' => ['id'],
+ ]);
+
+ $this->assertFalse($paginator->onFirstPage());
+ $this->assertTrue($paginator->onLastPage());
+ }
+
protected function getCursor($params, $isNext = true)
{
return (new Cursor($params, $isNext))->encode(); | true |
Other | laravel | framework | c51ef988d8c6d10d5613dc58f4fdd255edf70216.json | Fix issue with pusher channel (#42287) | src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php | @@ -4,6 +4,7 @@
use Illuminate\Broadcasting\BroadcastException;
use Illuminate\Support\Arr;
+use Illuminate\Support\Collection;
use Pusher\ApiErrorException;
use Pusher\Pusher;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
@@ -118,10 +119,12 @@ public function broadcast(array $channels, $event, array $payload = [])
$parameters = $socket !== null ? ['socket_id' => $socket] : [];
+ $channels = Collection::make($this->formatChannels($channels));
+
try {
- $this->pusher->trigger(
- $this->formatChannels($channels), $event, $payload, $parameters
- );
+ $channels->chunk(100)->each(function ($channels) use ($event, $payload, $parameters) {
+ $this->pusher->trigger($channels, $event, $payload, $parameters);
+ });
} catch (ApiErrorException $e) {
throw new BroadcastException(
sprintf('Pusher error: %s.', $e->getMessage()) | false |
Other | laravel | framework | e022b2cd73e2f32d90c2b1bfbdad80d6d21b6c43.json | remove unneeded check | src/Illuminate/Auth/DatabaseUserProvider.php | @@ -115,10 +115,6 @@ public function retrieveByCredentials(array $credentials)
$query = $this->connection->table($this->table);
foreach ($credentials as $key => $value) {
- if (str_contains($key, 'password')) {
- continue;
- }
-
if (is_array($value) || $value instanceof Arrayable) {
$query->whereIn($key, $value);
} elseif ($value instanceof Closure) { | false |
Other | laravel | framework | e3d6e82c095d29ef85bfd41e4f28f25093bf49b2.json | Apply fixes from StyleCI | tests/Auth/AuthDatabaseUserProviderTest.php | @@ -142,7 +142,7 @@ public function testRetrieveByCredentialsWithMultiplyPasswordsReturnsNull()
$provider = new DatabaseUserProvider($conn, $hasher, 'foo');
$user = $provider->retrieveByCredentials([
'password' => 'dayle',
- 'password2' => 'night'
+ 'password2' => 'night',
]);
$this->assertNull($user); | true |
Other | laravel | framework | e3d6e82c095d29ef85bfd41e4f28f25093bf49b2.json | Apply fixes from StyleCI | tests/Auth/AuthEloquentUserProviderTest.php | @@ -122,7 +122,7 @@ public function testRetrieveByCredentialsWithMultiplyPasswordsReturnsNull()
$provider = $this->getProviderMock();
$user = $provider->retrieveByCredentials([
'password' => 'dayle',
- 'password2' => 'night'
+ 'password2' => 'night',
]);
$this->assertNull($user); | true |
Other | laravel | framework | d323312a15d7f18fe04dfdb298340f234ad28ff1.json | Apply fixes from StyleCI | src/Illuminate/Database/Eloquent/Factories/Factory.php | @@ -465,7 +465,7 @@ protected function expandAttributes(array $definition)
}
$definition[$key] = $attribute;
-
+
return $attribute;
})
->all(); | false |
Other | laravel | framework | 6e0fb37ca7d432e95d1386bdb1dab56b9b36ffd7.json | Apply fixes from StyleCI | src/Illuminate/Foundation/Testing/Concerns/InteractsWithExceptionHandling.php | @@ -66,7 +66,8 @@ protected function withoutExceptionHandling(array $except = [])
$this->originalExceptionHandler = app(ExceptionHandler::class);
}
- $this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler, $except) implements ExceptionHandler {
+ $this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler, $except) implements ExceptionHandler
+ {
protected $except;
protected $originalHandler;
| false |
Other | laravel | framework | a880574f5ada4c9aa0c9353a8cfae3e71f981e7a.json | Apply fixes from StyleCI | tests/Foundation/Bootstrap/HandleExceptionsTest.php | @@ -7,7 +7,6 @@
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Bootstrap\HandleExceptions;
use Illuminate\Log\LogManager;
-use Illuminate\Support\Str;
use Mockery as m;
use Monolog\Handler\NullHandler;
use PHPUnit\Framework\TestCase;
@@ -52,7 +51,7 @@ public function testPhpDeprecations()
$logger->shouldReceive('channel')->with('deprecations')->andReturnSelf();
$logger->shouldReceive('warning')->with(
- m::on(fn(string $message) => (bool) preg_match(
+ m::on(fn (string $message) => (bool) preg_match(
<<<REGEXP
#ErrorException: str_contains\(\): Passing null to parameter \#2 \(\\\$needle\) of type string is deprecated in /home/user/laravel/routes/web\.php:17
Stack trace:
@@ -81,7 +80,7 @@ public function testUserDeprecations()
$logger->shouldReceive('channel')->with('deprecations')->andReturnSelf();
$logger->shouldReceive('warning')->with(
- m::on(fn(string $message) => (bool) preg_match(
+ m::on(fn (string $message) => (bool) preg_match(
<<<REGEXP
#ErrorException: str_contains\(\): Passing null to parameter \#2 \(\\\$needle\) of type string is deprecated in /home/user/laravel/routes/web\.php:17
Stack trace: | false |
Other | laravel | framework | 618114204c2be4e1e305cb1ed502d16e0ec1f0c7.json | fix docblock of database component (#42182) | src/Illuminate/Database/Connection.php | @@ -167,7 +167,7 @@ class Connection implements ConnectionInterface
/**
* All of the callbacks that should be invoked before a query is executed.
*
- * @var array
+ * @var \Closure[]
*/
protected $beforeExecutingCallbacks = [];
@@ -181,14 +181,14 @@ class Connection implements ConnectionInterface
/**
* Type mappings that should be registered with new Doctrine connections.
*
- * @var array
+ * @var array<string, string>
*/
protected $doctrineTypeMappings = [];
/**
* The connection resolvers.
*
- * @var array
+ * @var \Closure[]
*/
protected static $resolvers = [];
| true |
Other | laravel | framework | 618114204c2be4e1e305cb1ed502d16e0ec1f0c7.json | fix docblock of database component (#42182) | src/Illuminate/Database/ConnectionResolver.php | @@ -7,7 +7,7 @@ class ConnectionResolver implements ConnectionResolverInterface
/**
* All of the registered connections.
*
- * @var array
+ * @var \Illuminate\Database\ConnectionInterface[]
*/
protected $connections = [];
@@ -21,7 +21,7 @@ class ConnectionResolver implements ConnectionResolverInterface
/**
* Create a new connection resolver instance.
*
- * @param array $connections
+ * @param array<string, \Illuminate\Database\ConnectionInterface> $connections
* @return void
*/
public function __construct(array $connections = []) | true |
Other | laravel | framework | 618114204c2be4e1e305cb1ed502d16e0ec1f0c7.json | fix docblock of database component (#42182) | src/Illuminate/Database/DatabaseManager.php | @@ -38,14 +38,14 @@ class DatabaseManager implements ConnectionResolverInterface
/**
* The active connection instances.
*
- * @var array
+ * @var array<string, \Illuminate\Database\Connection>
*/
protected $connections = [];
/**
* The custom connection resolvers.
*
- * @var array
+ * @var array<string, callable>
*/
protected $extensions = [];
@@ -59,7 +59,7 @@ class DatabaseManager implements ConnectionResolverInterface
/**
* The custom Doctrine column types.
*
- * @var array
+ * @var array<string, array>
*/
protected $doctrineTypes = [];
@@ -369,7 +369,7 @@ public function setDefaultConnection($name)
/**
* Get all of the support drivers.
*
- * @return array
+ * @return string[]
*/
public function supportedDrivers()
{
@@ -379,7 +379,7 @@ public function supportedDrivers()
/**
* Get all of the drivers that are actually available.
*
- * @return array
+ * @return string[]
*/
public function availableDrivers()
{
@@ -415,7 +415,7 @@ public function forgetExtension($name)
/**
* Return all of the created connections.
*
- * @return array
+ * @return array<string, \Illuminate\Database\Connection>
*/
public function getConnections()
{ | true |
Other | laravel | framework | ad18afca429e8e2c5ba9eb00eceb0de1572a0d96.json | Add test for empty middleware groups (#42188) | tests/Integration/Routing/FluentRoutingTest.php | @@ -46,6 +46,21 @@ public function testMiddlewareRunWhenRegisteredAsArrayOrParams()
$this->assertSame('1_2', $this->get('before_after')->content());
$this->assertSame('1_2', $this->get('both_before')->content());
$this->assertSame('1_2', $this->get('both_after')->content());
+ $this->assertSame('1_2', $this->get('both_after')->content());
+ }
+
+ public function testEmptyMiddlewareGroupAreHandledGracefully()
+ {
+ $controller = function () {
+ return 'Hello World';
+ };
+
+ Route::middlewareGroup('public', []);
+
+ Route::middleware('public')
+ ->get('public', $controller);
+
+ $this->assertSame('Hello World', $this->get('public')->content());
}
}
| false |
Other | laravel | framework | 6741fa8ffb5ec4339eff98132518d6f6c501eca6.json | Fix deprecation with empty rules (#42213) | src/Illuminate/Validation/ValidationRuleParser.php | @@ -97,7 +97,7 @@ protected function explodeExplicitRule($rule, $attribute)
return array_map(
[$this, 'prepareRule'],
$rule,
- array_fill(array_key_first($rule), count($rule), $attribute)
+ array_fill((int) array_key_first($rule), count($rule), $attribute)
);
}
| true |
Other | laravel | framework | 6741fa8ffb5ec4339eff98132518d6f6c501eca6.json | Fix deprecation with empty rules (#42213) | tests/Validation/ValidationRuleParserTest.php | @@ -55,6 +55,13 @@ public function testEmptyRulesArePreserved()
], $rules);
}
+ public function testEmptyRulesCanBeExploded()
+ {
+ $parser = new ValidationRuleParser(['foo' => 'bar']);
+
+ $this->assertIsObject($parser->explode(['foo' => []]));
+ }
+
public function testConditionalRulesWithDefault()
{
$rules = ValidationRuleParser::filterConditionalRules([ | true |
Other | laravel | framework | f6e9f54385f167a17b25445f8d855e754a4f50d6.json | Fix deprecation issue with translator (#42216) | src/Illuminate/Translation/Translator.php | @@ -218,8 +218,8 @@ protected function makeReplacements($line, array $replace)
$shouldReplace = [];
foreach ($replace as $key => $value) {
- $shouldReplace[':'.Str::ucfirst($key)] = Str::ucfirst($value);
- $shouldReplace[':'.Str::upper($key)] = Str::upper($value);
+ $shouldReplace[':'.Str::ucfirst($key ?? '')] = Str::ucfirst($value ?? '');
+ $shouldReplace[':'.Str::upper($key ?? '')] = Str::upper($value ?? '');
$shouldReplace[':'.$key] = $value;
}
| true |
Other | laravel | framework | f6e9f54385f167a17b25445f8d855e754a4f50d6.json | Fix deprecation issue with translator (#42216) | tests/Translation/TranslationTranslatorTest.php | @@ -203,6 +203,14 @@ public function testGetJsonForNonExistingReturnsSameKeyAndReplaces()
$this->assertSame('foo baz', $t->get('foo :message', ['message' => 'baz']));
}
+ public function testEmptyFallbacks()
+ {
+ $t = new Translator($this->getLoader(), 'en');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', '*', '*')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'foo :message', '*')->andReturn([]);
+ $this->assertSame('foo ', $t->get('foo :message', ['message' => null]));
+ }
+
protected function getLoader()
{
return m::mock(Loader::class); | true |
Other | laravel | framework | 832d1df73034e298f86124feae695203521ed57e.json | Fix refresh during down (#42217) | src/Illuminate/Foundation/Console/stubs/maintenance-mode.stub | @@ -69,6 +69,10 @@ if (isset($data['retry'])) {
header('Retry-After: '.$data['retry']);
}
+if (isset($data['refresh'])) {
+ header('Refresh: '.$data['refresh']);
+}
+
echo $data['template'];
exit; | false |
Other | laravel | framework | 48fbd8dae0edbec88d7afe03cb8d6e500d2121d6.json | Update request.stub (#42154) | src/Illuminate/Foundation/Console/stubs/request.stub | @@ -19,7 +19,7 @@ class {{ class }} extends FormRequest
/**
* Get the validation rules that apply to the request.
*
- * @return array
+ * @return array<string, mixed>
*/
public function rules()
{ | false |
Other | laravel | framework | d787947998089e6eac4883d90418601fdb5c529d.json | Fix typo in Factory::state (#42144) | src/Illuminate/Database/Eloquent/Factories/Factory.php | @@ -467,7 +467,7 @@ protected function expandAttributes(array $definition)
/**
* Add a new state transformation to the model definition.
*
- * @param (callable(array<string, mixed>, \Illuminate\Database\Eloquent\Model|null=): array<string, mixed>)|array<string, mixed> $state
+ * @param (callable(array<string, mixed>, \Illuminate\Database\Eloquent\Model|null): array<string, mixed>)|array<string, mixed> $state
* @return static
*/
public function state($state) | false |
Other | laravel | framework | 6b87641b7a9db734059b557a3808b8ae18b200f1.json | throw deadlock exception (#42129) | src/Illuminate/Database/Concerns/ManagesTransactions.php | @@ -3,6 +3,7 @@
namespace Illuminate\Database\Concerns;
use Closure;
+use Illuminate\Database\DeadlockException;
use RuntimeException;
use Throwable;
@@ -87,7 +88,11 @@ protected function handleTransactionException(Throwable $e, $currentAttempt, $ma
$this->getName(), $this->transactions
);
- throw $e;
+ throw new DeadlockException(
+ $e->getMessage(),
+ $e->getCode(),
+ $e->getPrevious()
+ );
}
// If there was an exception we will rollback this transaction and then we
@@ -226,8 +231,7 @@ protected function handleCommitTransactionException(Throwable $e, $currentAttemp
{
$this->transactions = max(0, $this->transactions - 1);
- if ($this->causedByConcurrencyError($e) &&
- $currentAttempt < $maxAttempts) {
+ if ($this->causedByConcurrencyError($e) && $currentAttempt < $maxAttempts) {
return;
}
| true |
Other | laravel | framework | 6b87641b7a9db734059b557a3808b8ae18b200f1.json | throw deadlock exception (#42129) | src/Illuminate/Database/DeadlockException.php | @@ -0,0 +1,10 @@
+<?php
+
+namespace Illuminate\Database;
+
+use PDOException;
+
+class DeadlockException extends PDOException
+{
+ //
+} | true |
Other | laravel | framework | c9d34b7be0611d26f3e46669934cf542cc5e9e21.json | Add str() and string() to request object | src/Illuminate/Http/Concerns/InteractsWithInput.php | @@ -542,4 +542,28 @@ public function dump($keys = [])
return $this;
}
+
+ /**
+ * Retrieve input from the request as a stringable.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return \Illuminate\Support\Stringable
+ */
+ public function str($key, $default = null)
+ {
+ return $this->string($key, $default);
+ }
+
+ /**
+ * Retrieve input from the request as a stringable.
+ *
+ * @param string $key
+ * @param mixed $default
+ * @return \Illuminate\Support\Stringable
+ */
+ public function string($key, $default = null)
+ {
+ return str($this->input($key, $default));
+ }
} | false |
Other | laravel | framework | 10061f1fb7977bc6b66da690f1d4b34b3a924982.json | Apply fixes from StyleCI | tests/Filesystem/FilesystemAdapterTest.php | @@ -456,6 +456,6 @@ public function testGetAllFiles()
$filesystemAdapter = new FilesystemAdapter($this->filesystem, $this->adapter);
- $this->assertSame($filesystemAdapter->files(),['body.txt','existing.txt','file.txt','file1.txt']);
+ $this->assertSame($filesystemAdapter->files(), ['body.txt', 'existing.txt', 'file.txt', 'file1.txt']);
}
} | false |
Other | laravel | framework | d3634359a13a078839363cf34ab24d197ffe4a69.json | fix array keys from cached routes (#42078)
Introduced by https://github.com/laravel/framework/pull/35714.
Removed the slash to match the same array key as in
src/Illuminate/Routing/RouteCollection.php:60 | src/Illuminate/Routing/CompiledRouteCollection.php | @@ -252,11 +252,7 @@ public function getRoutesByMethod()
})
->map(function (Collection $routes) {
return $routes->mapWithKeys(function (Route $route) {
- if ($domain = $route->getDomain()) {
- return [$domain.'/'.$route->uri => $route];
- }
-
- return [$route->uri => $route];
+ return [$route->getDomain().$route->uri => $route];
})->all();
})
->all(); | true |
Other | laravel | framework | d3634359a13a078839363cf34ab24d197ffe4a69.json | fix array keys from cached routes (#42078)
Introduced by https://github.com/laravel/framework/pull/35714.
Removed the slash to match the same array key as in
src/Illuminate/Routing/RouteCollection.php:60 | tests/Integration/Routing/CompiledRouteCollectionTest.php | @@ -527,13 +527,13 @@ public function testRouteWithSamePathAndSameMethodButDiffDomainNameWithOptionsMe
$this->assertEquals([
'HEAD' => [
- 'foo.localhost/same/path' => $routes['foo_domain'],
- 'bar.localhost/same/path' => $routes['bar_domain'],
+ 'foo.localhostsame/path' => $routes['foo_domain'],
+ 'bar.localhostsame/path' => $routes['bar_domain'],
'same/path' => $routes['no_domain'],
],
'GET' => [
- 'foo.localhost/same/path' => $routes['foo_domain'],
- 'bar.localhost/same/path' => $routes['bar_domain'],
+ 'foo.localhostsame/path' => $routes['foo_domain'],
+ 'bar.localhostsame/path' => $routes['bar_domain'],
'same/path' => $routes['no_domain'],
],
], $this->collection()->getRoutesByMethod()); | true |
Other | laravel | framework | 7ae798c938b0a530af82b5bdb607230d3da4f7ca.json | remove unused private method (#42115) | src/Illuminate/Redis/Connections/PhpRedisConnection.php | @@ -553,19 +553,6 @@ public function disconnect()
$this->client->close();
}
- /**
- * Apply a prefix to the given key if necessary.
- *
- * @param string $key
- * @return string
- */
- private function applyPrefix($key)
- {
- $prefix = (string) $this->client->getOption(Redis::OPT_PREFIX);
-
- return $prefix.$key;
- }
-
/**
* Pass other method calls down to the underlying client.
* | false |
Other | laravel | framework | c4354923bc7642aa87827c45f4112c5bec8cff77.json | fix php 8.2 deprication (#42117) | src/Illuminate/Database/Eloquent/SoftDeletes.php | @@ -199,7 +199,7 @@ public function isForceDeleting()
*/
public function getDeletedAtColumn()
{
- return defined('static::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
+ return defined(static::class.'::DELETED_AT') ? static::DELETED_AT : 'deleted_at';
}
/** | false |
Other | laravel | framework | f1d20b859edb2b2868871e25bad21541b442b705.json | Apply fixes from StyleCI | src/Illuminate/Session/Store.php | @@ -189,7 +189,7 @@ protected function prepareErrorBagForSerialization()
foreach ($this->attributes['errors']->getBags() as $key => $value) {
$errors[$key] = [
'format' => $value->getFormat(),
- 'messages' => $value->getMessages()
+ 'messages' => $value->getMessages(),
];
}
| false |
Other | laravel | framework | 2fb344e80838297c358b6a5800601a9b0e1ece1b.json | Apply fixes from StyleCI | src/Illuminate/Database/Connection.php | @@ -20,7 +20,6 @@
use Illuminate\Database\Schema\Builder as SchemaBuilder;
use Illuminate\Support\Arr;
use Illuminate\Support\Traits\Macroable;
-use LogicException;
use PDO;
use PDOStatement;
use RuntimeException; | false |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | src/Illuminate/Database/Eloquent/Builder.php | @@ -498,6 +498,29 @@ public function findOrNew($id, $columns = ['*'])
return $this->newModelInstance();
}
+ /**
+ * Find a model by its primary key or call a callback.
+ *
+ * @param mixed $id
+ * @param \Closure|array $columns
+ * @param \Closure|null $callback
+ * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|static[]|static|mixed
+ */
+ public function findOr($id, $columns = ['*'], Closure $callback = null)
+ {
+ if ($columns instanceof Closure) {
+ $callback = $columns;
+
+ $columns = ['*'];
+ }
+
+ if (! is_null($model = $this->find($id, $columns))) {
+ return $model;
+ }
+
+ return $callback();
+ }
+
/**
* Get the first record matching the attributes or instantiate it.
* | true |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php | @@ -711,6 +711,37 @@ public function findOrFail($id, $columns = ['*'])
throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
}
+ /**
+ * Find a related model by its primary key or call a callback.
+ *
+ * @param mixed $id
+ * @param \Closure|array $columns
+ * @param \Closure|null $callback
+ * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|mixed
+ */
+ public function findOr($id, $columns = ['*'], Closure $callback = null)
+ {
+ if ($columns instanceof Closure) {
+ $callback = $columns;
+
+ $columns = ['*'];
+ }
+
+ $result = $this->find($id, $columns);
+
+ $id = $id instanceof Arrayable ? $id->toArray() : $id;
+
+ if (is_array($id)) {
+ if (count($result) === count(array_unique($id))) {
+ return $result;
+ }
+ } elseif (! is_null($result)) {
+ return $result;
+ }
+
+ return $callback();
+ }
+
/**
* Add a basic where clause to the query, and return the first result.
* | true |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php | @@ -388,6 +388,37 @@ public function findOrFail($id, $columns = ['*'])
throw (new ModelNotFoundException)->setModel(get_class($this->related), $id);
}
+ /**
+ * Find a related model by its primary key or call a callback.
+ *
+ * @param mixed $id
+ * @param \Closure|array $columns
+ * @param \Closure|null $callback
+ * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|mixed
+ */
+ public function findOr($id, $columns = ['*'], Closure $callback = null)
+ {
+ if ($columns instanceof Closure) {
+ $callback = $columns;
+
+ $columns = ['*'];
+ }
+
+ $result = $this->find($id, $columns);
+
+ $id = $id instanceof Arrayable ? $id->toArray() : $id;
+
+ if (is_array($id)) {
+ if (count($result) === count(array_unique($id))) {
+ return $result;
+ }
+ } elseif (! is_null($result)) {
+ return $result;
+ }
+
+ return $callback();
+ }
+
/**
* Get the results of the relationship.
* | true |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | tests/Database/DatabaseEloquentBuilderTest.php | @@ -154,6 +154,75 @@ public function testFindOrFailMethodWithManyUsingCollectionThrowsModelNotFoundEx
$builder->findOrFail(new Collection([1, 2]), ['column']);
}
+ public function testFindOrMethod()
+ {
+ $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]);
+ $model = $this->getMockModel();
+ $model->shouldReceive('getKeyType')->andReturn('int');
+ $builder->setModel($model);
+ $builder->getQuery()->shouldReceive('where')->with('foo_table.foo', '=', 1)->twice();
+ $builder->getQuery()->shouldReceive('where')->with('foo_table.foo', '=', 2)->once();
+ $builder->shouldReceive('first')->andReturn($model)->once();
+ $builder->shouldReceive('first')->with(['column'])->andReturn($model)->once();
+ $builder->shouldReceive('first')->andReturn(null)->once();
+
+ $this->assertSame($model, $builder->findOr(1, fn () => 'callback result'));
+ $this->assertSame($model, $builder->findOr(1, ['column'], fn () => 'callback result'));
+ $this->assertSame('callback result', $builder->findOr(2, fn () => 'callback result'));
+ }
+
+ public function testFindOrMethodWithMany()
+ {
+ $builder = m::mock(Builder::class.'[get]', [$this->getMockQueryBuilder()]);
+ $model1 = $this->getMockModel();
+ $model2 = $this->getMockModel();
+ $builder->setModel($model1);
+ $builder->getQuery()->shouldReceive('whereIn')->with('foo_table.foo', [1, 2])->twice();
+ $builder->getQuery()->shouldReceive('whereIn')->with('foo_table.foo', [1, 2, 3])->once();
+ $builder->shouldReceive('get')->andReturn(new Collection([$model1, $model2]))->once();
+ $builder->shouldReceive('get')->with(['column'])->andReturn(new Collection([$model1, $model2]))->once();
+ $builder->shouldReceive('get')->andReturn(null)->once();
+
+ $result = $builder->findOr([1, 2], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame($model1, $result[0]);
+ $this->assertSame($model2, $result[1]);
+
+ $result = $builder->findOr([1, 2], ['column'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame($model1, $result[0]);
+ $this->assertSame($model2, $result[1]);
+
+ $result = $builder->findOr([1, 2, 3], fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
+ public function testFindOrMethodWithManyUsingCollection()
+ {
+ $builder = m::mock(Builder::class.'[get]', [$this->getMockQueryBuilder()]);
+ $model1 = $this->getMockModel();
+ $model2 = $this->getMockModel();
+ $builder->setModel($model1);
+ $builder->getQuery()->shouldReceive('whereIn')->with('foo_table.foo', [1, 2])->twice();
+ $builder->getQuery()->shouldReceive('whereIn')->with('foo_table.foo', [1, 2, 3])->once();
+ $builder->shouldReceive('get')->andReturn(new Collection([$model1, $model2]))->once();
+ $builder->shouldReceive('get')->with(['column'])->andReturn(new Collection([$model1, $model2]))->once();
+ $builder->shouldReceive('get')->andReturn(null)->once();
+
+ $result = $builder->findOr(new Collection([1, 2]), fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame($model1, $result[0]);
+ $this->assertSame($model2, $result[1]);
+
+ $result = $builder->findOr(new Collection([1, 2]), ['column'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame($model1, $result[0]);
+ $this->assertSame($model2, $result[1]);
+
+ $result = $builder->findOr(new Collection([1, 2, 3]), fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
public function testFirstOrFailMethodThrowsModelNotFoundException()
{
$this->expectException(ModelNotFoundException::class); | true |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php | @@ -201,6 +201,80 @@ public function testFindOrFailWithManyUsingCollectionThrowsAnException()
HasManyThroughTestCountry::first()->posts()->findOrFail(new Collection([1, 2]));
}
+ public function testFindOrMethod()
+ {
+ HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us'])
+ ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us'])
+ ->posts()->create(['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com']);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(1, fn () => 'callback result');
+ $this->assertInstanceOf(HasManyThroughTestPost::class, $result);
+ $this->assertSame(1, $result->id);
+ $this->assertSame('A title', $result->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(1, ['posts.id'], fn () => 'callback result');
+ $this->assertInstanceOf(HasManyThroughTestPost::class, $result);
+ $this->assertSame(1, $result->id);
+ $this->assertNull($result->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(2, fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
+ public function testFindOrMethodWithMany()
+ {
+ HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us'])
+ ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us'])
+ ->posts()->createMany([
+ ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'],
+ ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'],
+ ]);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr([1, 2], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertSame('A title', $result[0]->title);
+ $this->assertSame('Another title', $result[1]->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr([1, 2], ['posts.id'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNull($result[0]->title);
+ $this->assertNull($result[1]->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr([1, 2, 3], fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
+ public function testFindOrMethodWithManyUsingCollection()
+ {
+ HasManyThroughTestCountry::create(['id' => 1, 'name' => 'United States of America', 'shortname' => 'us'])
+ ->users()->create(['id' => 1, 'email' => 'taylorotwell@gmail.com', 'country_short' => 'us'])
+ ->posts()->createMany([
+ ['id' => 1, 'title' => 'A title', 'body' => 'A body', 'email' => 'taylorotwell@gmail.com'],
+ ['id' => 2, 'title' => 'Another title', 'body' => 'Another body', 'email' => 'taylorotwell@gmail.com'],
+ ]);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(new Collection([1, 2]), fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertSame('A title', $result[0]->title);
+ $this->assertSame('Another title', $result[1]->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(new Collection([1, 2]), ['posts.id'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNull($result[0]->title);
+ $this->assertNull($result[1]->title);
+
+ $result = HasManyThroughTestCountry::first()->posts()->findOr(new Collection([1, 2, 3]), fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
public function testFirstRetrievesFirstRecord()
{
$this->seedData(); | true |
Other | laravel | framework | b062355f05f07f72119d868e065aac0c0c958ffd.json | Add a `findOr` method to Eloquent (#42092)
* Add a `findOr` method to Eloquent
* Linting | tests/Integration/Database/EloquentBelongsToManyTest.php | @@ -413,6 +413,77 @@ public function testFindOrNewMethod()
$this->assertInstanceOf(Tag::class, $post->tags()->findOrNew(666));
}
+ public function testFindOrMethod()
+ {
+ $post = Post::create(['title' => Str::random()]);
+ $post->tags()->create(['name' => Str::random()]);
+
+ $result = $post->tags()->findOr(1, fn () => 'callback result');
+ $this->assertInstanceOf(Tag::class, $result);
+ $this->assertSame(1, $result->id);
+ $this->assertNotNull($result->name);
+
+ $result = $post->tags()->findOr(1, ['id'], fn () => 'callback result');
+ $this->assertInstanceOf(Tag::class, $result);
+ $this->assertSame(1, $result->id);
+ $this->assertNull($result->name);
+
+ $result = $post->tags()->findOr(2, fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
+ public function testFindOrMethodWithMany()
+ {
+ $post = Post::create(['title' => Str::random()]);
+ $post->tags()->createMany([
+ ['name' => Str::random()],
+ ['name' => Str::random()],
+ ]);
+
+ $result = $post->tags()->findOr([1, 2], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNotNull($result[0]->name);
+ $this->assertNotNull($result[1]->name);
+
+ $result = $post->tags()->findOr([1, 2], ['id'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNull($result[0]->name);
+ $this->assertNull($result[1]->name);
+
+ $result = $post->tags()->findOr([1, 2, 3], fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
+ public function testFindOrMethodWithManyUsingCollection()
+ {
+ $post = Post::create(['title' => Str::random()]);
+ $post->tags()->createMany([
+ ['name' => Str::random()],
+ ['name' => Str::random()],
+ ]);
+
+ $result = $post->tags()->findOr(new Collection([1, 2]), fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNotNull($result[0]->name);
+ $this->assertNotNull($result[1]->name);
+
+ $result = $post->tags()->findOr(new Collection([1, 2]), ['id'], fn () => 'callback result');
+ $this->assertInstanceOf(Collection::class, $result);
+ $this->assertSame(1, $result[0]->id);
+ $this->assertSame(2, $result[1]->id);
+ $this->assertNull($result[0]->name);
+ $this->assertNull($result[1]->name);
+
+ $result = $post->tags()->findOr(new Collection([1, 2, 3]), fn () => 'callback result');
+ $this->assertSame('callback result', $result);
+ }
+
public function testFirstOrNewMethod()
{
$post = Post::create(['title' => Str::random()]); | true |
Other | laravel | framework | 8c737f054fe54076556870ae6a5b4745b554a063.json | add the beforeRefreshingDatabase function (#42073) | src/Illuminate/Foundation/Testing/RefreshDatabase.php | @@ -16,6 +16,8 @@ trait RefreshDatabase
*/
public function refreshDatabase()
{
+ $this->beforeRefreshingDatabase();
+
$this->usingInMemoryDatabase()
? $this->refreshInMemoryDatabase()
: $this->refreshTestDatabase();
@@ -126,6 +128,16 @@ protected function connectionsToTransact()
? $this->connectionsToTransact : [null];
}
+ /**
+ * Perform any work that should take place before the database has started refreshing.
+ *
+ * @return void
+ */
+ protected function beforeRefreshingDatabase()
+ {
+ // ...
+ }
+
/**
* Perform any work that should take place once the database has finished refreshing.
* | false |
Other | laravel | framework | 73f7cd4772584bcb5dc297c9350a722d26f1248a.json | Apply fixes from StyleCI | src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php | @@ -54,7 +54,7 @@ public function handle()
$executions[] = $execution = new Process([
PHP_BINARY,
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
- 'schedule:run'
+ 'schedule:run',
]);
$execution->start(); | false |
Other | laravel | framework | 6fea6c271086e2ad017a6078e1ee457a2b8c398e.json | Apply fixes from StyleCI | src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php | @@ -41,7 +41,7 @@ public function handle()
$executions[] = $execution = new Process([
PHP_BINARY,
defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
- 'schedule:run'
+ 'schedule:run',
]);
$execution->start(); | false |
Other | laravel | framework | b18678b80d6379edd15a841d90c7be8c7d20a734.json | Remove redundant collection (#42074) | src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php | @@ -62,7 +62,7 @@ protected function cleanArray(array $data, $keyPrefix = '')
$data[$key] = $this->cleanValue($keyPrefix.$key, $value);
}
- return collect($data)->all();
+ return $data;
}
/** | false |
Other | laravel | framework | 300c66f08d030f242ba4c719bddd63e1d7f5a200.json | Update docblock (#42029) | src/Illuminate/Foundation/Exceptions/Handler.php | @@ -54,7 +54,7 @@ class Handler implements ExceptionHandlerContract
/**
* A list of the exception types that are not reported.
*
- * @var string[]
+ * @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [];
@@ -108,7 +108,7 @@ class Handler implements ExceptionHandlerContract
/**
* A list of the inputs that are never flashed for validation exceptions.
*
- * @var string[]
+ * @var array<int, string>
*/
protected $dontFlash = [
'current_password', | false |
Other | laravel | framework | 57de940b4242a606ca5af61453bf401e369f460b.json | Update Container.php (#41992)
Optimize repeat | src/Illuminate/Container/Container.php | @@ -426,9 +426,7 @@ public function scoped($abstract, $concrete = null)
public function scopedIf($abstract, $concrete = null)
{
if (! $this->bound($abstract)) {
- $this->scopedInstances[] = $abstract;
-
- $this->singleton($abstract, $concrete);
+ $this->scoped($abstract, $concrete);
}
}
| false |
Other | laravel | framework | e9e805f36f767ace53791e88830042fcf69b7513.json | Update Blade.php (#41990) | src/Illuminate/Support/Facades/Blade.php | @@ -17,7 +17,7 @@
* @method static void compile(string|null $path = null)
* @method static void component(string $class, string|null $alias = null, string $prefix = '')
* @method static void components(array $components, string $prefix = '')
- * @method static void anonymousComponentNamespace(string $directory, string $prefix)
+ * @method static void anonymousComponentNamespace(string $directory, string $prefix = null)
* @method static void componentNamespace(string $prefix, string $directory = null)
* @method static void directive(string $name, callable $handler)
* @method static void extend(callable $compiler) | false |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Bus/DatabaseBatchRepository.php | @@ -286,9 +286,7 @@ public function pruneUnfinished(DateTimeInterface $before)
*/
public function transaction(Closure $callback)
{
- return $this->connection->transaction(function () use ($callback) {
- return $callback();
- });
+ return $this->connection->transaction(fn () => $callback());
}
/** | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Container/ContextualBindingBuilder.php | @@ -91,8 +91,6 @@ public function giveTagged($tag)
*/
public function giveConfig($key, $default = null)
{
- $this->give(function ($container) use ($key, $default) {
- return $container->get('config')->get($key, $default);
- });
+ $this->give(fn ($container) => $container->get('config')->get($key, $default));
}
} | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Database/Eloquent/Factories/Factory.php | @@ -296,9 +296,7 @@ public function createQuietly($attributes = [], ?Model $parent = null)
*/
public function lazy(array $attributes = [], ?Model $parent = null)
{
- return function () use ($attributes, $parent) {
- return $this->create($attributes, $parent);
- };
+ return fn () => $this->create($attributes, $parent);
}
/** | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Http/Request.php | @@ -726,8 +726,6 @@ public function __isset($key)
*/
public function __get($key)
{
- return Arr::get($this->all(), $key, function () use ($key) {
- return $this->route($key);
- });
+ return Arr::get($this->all(), $key, fn () => $this->route($key));
}
} | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Pagination/PaginationState.php | @@ -12,13 +12,9 @@ class PaginationState
*/
public static function resolveUsing($app)
{
- Paginator::viewFactoryResolver(function () use ($app) {
- return $app['view'];
- });
+ Paginator::viewFactoryResolver(fn () => $app['view']);
- Paginator::currentPathResolver(function () use ($app) {
- return $app['request']->url();
- });
+ Paginator::currentPathResolver(fn () => $app['request']->url());
Paginator::currentPageResolver(function ($pageName = 'page') use ($app) {
$page = $app['request']->input($pageName);
@@ -30,9 +26,7 @@ public static function resolveUsing($app)
return 1;
});
- Paginator::queryStringResolver(function () use ($app) {
- return $app['request']->query();
- });
+ Paginator::queryStringResolver(fn () => $app['request']->query());
CursorPaginator::currentCursorResolver(function ($cursorName = 'cursor') use ($app) {
return Cursor::fromEncoded($app['request']->input($cursorName)); | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Support/Env.php | @@ -96,8 +96,6 @@ public static function get($key, $default = null)
return $value;
})
- ->getOrCall(function () use ($default) {
- return value($default);
- });
+ ->getOrCall(fn () => value($default));
}
} | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Testing/ParallelRunner.php | @@ -135,9 +135,7 @@ protected function forEachProcess($callback)
{
collect(range(1, $this->options->processes()))->each(function ($token) use ($callback) {
tap($this->createApplication(), function ($app) use ($callback, $token) {
- ParallelTesting::resolveTokenUsing(function () use ($token) {
- return $token;
- });
+ ParallelTesting::resolveTokenUsing(fn () => $token);
$callback($app);
})->flush(); | true |
Other | laravel | framework | b94a68253d77944d68ba22f3391c83df479e1617.json | Use arrow functions (#41963) | src/Illuminate/Validation/Validator.php | @@ -381,9 +381,7 @@ protected function replacePlaceholderInString(string $value)
*/
public function after($callback)
{
- $this->after[] = function () use ($callback) {
- return $callback($this);
- };
+ $this->after[] = fn () => $callback($this);
return $this;
} | true |
Other | laravel | framework | 8a10e3f61e05c05829ca80ac23656b6bffe38aba.json | trim zwnbsp (#41949)
* trim zwnbsp
* fix zwnbsp
Co-authored-by: j <j@qq.com> | src/Illuminate/Foundation/Http/Middleware/TrimStrings.php | @@ -53,7 +53,7 @@ protected function transform($key, $value)
return $value;
}
- return is_string($value) ? preg_replace('~^\s+|\s+$~iu', '', $value) : $value;
+ return is_string($value) ? preg_replace('~^[\s]+|[\s]+$~iu', '', $value) : $value;
}
/** | true |
Other | laravel | framework | 8a10e3f61e05c05829ca80ac23656b6bffe38aba.json | trim zwnbsp (#41949)
* trim zwnbsp
* fix zwnbsp
Co-authored-by: j <j@qq.com> | tests/Foundation/Http/Middleware/TrimStringsTest.php | @@ -34,7 +34,9 @@ public function testTrimStringsNBSP()
$middleware = new TrimStrings;
$symfonyRequest = new SymfonyRequest([
// Here has some NBSP, but it still display to space.
+ // Please note, do not edit in browser
'abc' => ' 123 ',
+ 'zwnbsp' => ' ha ',
'xyz' => 'だ',
'foo' => 'ム',
'bar' => ' だ ',
@@ -45,6 +47,7 @@ public function testTrimStringsNBSP()
$middleware->handle($request, function (Request $request) {
$this->assertSame('123', $request->get('abc'));
+ $this->assertSame('ha', $request->get('zwnbsp'));
$this->assertSame('だ', $request->get('xyz'));
$this->assertSame('ム', $request->get('foo'));
$this->assertSame('だ', $request->get('bar')); | true |
Other | laravel | framework | 83be3c88bc242b757e957648a1dcb53fd9b3d497.json | Apply fixes from StyleCI | src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php | @@ -413,7 +413,6 @@ public function compileGetAllViews()
return "select name, type from sys.objects where type = 'V'";
}
-
/**
* Create the column definition for a char type.
* | true |
Other | laravel | framework | 83be3c88bc242b757e957648a1dcb53fd9b3d497.json | Apply fixes from StyleCI | src/Illuminate/Database/Schema/SqlServerBuilder.php | @@ -30,7 +30,7 @@ public function dropDatabaseIfExists($name)
);
}
- /**
+ /**
* Drop all tables from the database.
*
* @return void | true |
Other | laravel | framework | 83be3c88bc242b757e957648a1dcb53fd9b3d497.json | Apply fixes from StyleCI | tests/Integration/Database/SqlServer/DatabaseSqlServerSchemaBuilderTest.php | @@ -63,7 +63,7 @@ public function testGetAllTablesAndColumnListing()
public function testGetAllViews()
{
- DB::connection('sqlsrv')->statement(<<<SQL
+ DB::connection('sqlsrv')->statement(<<<'SQL'
CREATE VIEW users_view
AS
SELECT name,age from users;
@@ -76,7 +76,7 @@ public function testGetAllViews()
$this->assertEquals('users_view', $obj->name);
$this->assertEquals('V ', $obj->type);
- DB::connection('sqlsrv')->statement(<<<SQL
+ DB::connection('sqlsrv')->statement(<<<'SQL'
DROP VIEW IF EXISTS users_view;
SQL);
| true |
Other | laravel | framework | 83be3c88bc242b757e957648a1dcb53fd9b3d497.json | Apply fixes from StyleCI | tests/Integration/Database/Sqlite/DatabaseSqliteSchemaBuilderTest.php | @@ -70,7 +70,7 @@ public function testGetAllTablesAndColumnListing()
public function testGetAllViews()
{
- DB::connection('conn1')->statement(<<<SQL
+ DB::connection('conn1')->statement(<<<'SQL'
CREATE VIEW users_view
AS
SELECT name,age from users;
@@ -83,7 +83,7 @@ public function testGetAllViews()
$this->assertEquals('users_view', $obj->name);
$this->assertEquals('view', $obj->type);
- DB::connection('conn1')->statement(<<<SQL
+ DB::connection('conn1')->statement(<<<'SQL'
DROP VIEW IF EXISTS users_view;
SQL);
| true |
Other | laravel | framework | fab61079afd17483ec91e6a897a912fd3990d97e.json | add test (#41945) | tests/Database/DatabaseEloquentBuilderTest.php | @@ -1106,6 +1106,17 @@ public function testWithCountAndSelect()
$this->assertSame('select "id", (select count(*) from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id") as "foo_count" from "eloquent_builder_test_model_parent_stubs"', $builder->toSql());
}
+ public function testWithCountSecondRelationWithClosure()
+ {
+ $model = new EloquentBuilderTestModelParentStub;
+
+ $builder = $model->withCount(['address', 'foo' => function ($query) {
+ $query->where('active', false);
+ }]);
+
+ $this->assertSame('select "eloquent_builder_test_model_parent_stubs".*, (select count(*) from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id") as "address_count", (select count(*) from "eloquent_builder_test_model_close_related_stubs" where "eloquent_builder_test_model_parent_stubs"."foo_id" = "eloquent_builder_test_model_close_related_stubs"."id" and "active" = ?) as "foo_count" from "eloquent_builder_test_model_parent_stubs"', $builder->toSql());
+ }
+
public function testWithCountAndMergedWheres()
{
$model = new EloquentBuilderTestModelParentStub; | false |
Other | laravel | framework | 5790b491a698237aa76a0e1df6213b4cbcec0424.json | Use arrow functions (#41930) | src/Illuminate/Foundation/Exceptions/Handler.php | @@ -185,9 +185,7 @@ public function renderable(callable $renderUsing)
public function map($from, $to = null)
{
if (is_string($to)) {
- $to = function ($exception) use ($to) {
- return new $to('', 0, $exception);
- };
+ $to = fn ($exception) => new $to('', 0, $exception);
}
if (is_callable($from) && is_null($to)) {
@@ -263,9 +261,9 @@ public function report(Throwable $e)
throw $e;
}
- $level = Arr::first($this->levels, function ($level, $type) use ($e) {
- return $e instanceof $type;
- }, LogLevel::ERROR);
+ $level = Arr::first(
+ $this->levels, fn ($level, $type) => $e instanceof $type, LogLevel::ERROR
+ );
$logger->log(
$level,
@@ -299,9 +297,7 @@ protected function shouldntReport(Throwable $e)
{
$dontReport = array_merge($this->dontReport, $this->internalDontReport);
- return ! is_null(Arr::first($dontReport, function ($type) use ($e) {
- return $e instanceof $type;
- }));
+ return ! is_null(Arr::first($dontReport, fn ($type) => $e instanceof $type));
}
/**
@@ -705,9 +701,7 @@ protected function convertExceptionToArray(Throwable $e)
'exception' => get_class($e),
'file' => $e->getFile(),
'line' => $e->getLine(),
- 'trace' => collect($e->getTrace())->map(function ($trace) {
- return Arr::except($trace, ['args']);
- })->all(),
+ 'trace' => collect($e->getTrace())->map(fn ($trace) => Arr::except($trace, ['args']))->all(),
] : [
'message' => $this->isHttpException($e) ? $e->getMessage() : 'Server Error',
]; | false |
Other | laravel | framework | bd3ac842a4af4d86576234b08371ee54e1920772.json | Fix empty paths for server.php (#41933) | src/Illuminate/Foundation/resources/server.php | @@ -3,7 +3,7 @@
$publicPath = getcwd();
$uri = urldecode(
- parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
+ parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?? ''
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the | false |
Other | laravel | framework | 75bf702169d0d32ee9b0c4fbf3cbd6d7447829a3.json | Update Handler.php (#41935)
fix #41925 review comments | src/Illuminate/Foundation/Exceptions/Handler.php | @@ -68,7 +68,7 @@ class Handler implements ExceptionHandlerContract
/**
* A map of exceptions with their corresponding custom log levels.
*
- * @var array<string, string>
+ * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [];
@@ -220,7 +220,7 @@ public function ignore(string $class)
* Set the log level for the given exception type.
*
* @param class-string<\Throwable> $type
- * @param string $level
+ * @param \Psr\Log\LogLevel::* $level
* @return $this
*/
public function level($type, $level) | false |
Other | laravel | framework | 78cb588f9f391016632b3f96755c851a712a442f.json | use arrow function (#41895) | src/Illuminate/Routing/AbstractRouteCollection.php | @@ -79,9 +79,9 @@ protected function matchAgainstRoutes(array $routes, $request, $includingMethod
return $route->isFallback;
});
- return $routes->merge($fallbacks)->first(function (Route $route) use ($request, $includingMethod) {
- return $route->matches($request, $includingMethod);
- });
+ return $routes->merge($fallbacks)->first(
+ fn (Route $route) => $route->matches($request, $includingMethod)
+ );
}
/** | true |
Other | laravel | framework | 78cb588f9f391016632b3f96755c851a712a442f.json | use arrow function (#41895) | src/Illuminate/Routing/CreatesRegularExpressionRouteConstraints.php | @@ -72,8 +72,7 @@ public function whereIn($parameters, array $values)
protected function assignExpressionToParameters($parameters, $expression)
{
return $this->where(collect(Arr::wrap($parameters))
- ->mapWithKeys(function ($parameter) use ($expression) {
- return [$parameter => $expression];
- })->all());
+ ->mapWithKeys(fn ($parameter) => [$parameter => $expression])
+ ->all());
}
} | true |
Other | laravel | framework | 78cb588f9f391016632b3f96755c851a712a442f.json | use arrow function (#41895) | src/Illuminate/Routing/RouteDependencyResolverTrait.php | @@ -92,9 +92,7 @@ protected function transformDependency(ReflectionParameter $parameter, $paramete
*/
protected function alreadyInParameters($class, array $parameters)
{
- return ! is_null(Arr::first($parameters, function ($value) use ($class) {
- return $value instanceof $class;
- }));
+ return ! is_null(Arr::first($parameters, fn ($value) => $value instanceof $class));
}
/** | true |
Other | laravel | framework | 78cb588f9f391016632b3f96755c851a712a442f.json | use arrow function (#41895) | src/Illuminate/Routing/Router.php | @@ -695,9 +695,7 @@ protected function findRoute($request)
*/
protected function runRoute(Request $request, Route $route)
{
- $request->setRouteResolver(function () use ($route) {
- return $route;
- });
+ $request->setRouteResolver(fn () => $route);
$this->events->dispatch(new RouteMatched($route, $request));
@@ -723,11 +721,9 @@ protected function runRouteWithinStack(Route $route, Request $request)
return (new Pipeline($this->container))
->send($request)
->through($middleware)
- ->then(function ($request) use ($route) {
- return $this->prepareResponse(
- $request, $route->run()
- );
- });
+ ->then(fn ($request) => $this->prepareResponse(
+ $request, $route->run()
+ ));
}
/**
@@ -775,9 +771,9 @@ public function resolveMiddleware(array $middleware, array $excluded = [])
$reflection = new ReflectionClass($name);
- return collect($excluded)->contains(function ($exclude) use ($reflection) {
- return class_exists($exclude) && $reflection->isSubclassOf($exclude);
- });
+ return collect($excluded)->contains(
+ fn ($exclude) => class_exists($exclude) && $reflection->isSubclassOf($exclude)
+ );
})->values();
return $this->sortMiddleware($middleware); | true |
Other | laravel | framework | 644c9d8d6c63d37fcd0c9a917fff821a512e4e1d.json | improve unicode support on Str::squish() (#41877) | src/Illuminate/Support/Str.php | @@ -889,7 +889,7 @@ public static function snake($value, $delimiter = '_')
*/
public static function squish($value)
{
- return preg_replace('/\s+/', ' ', trim($value));
+ return preg_replace('~\s+~u', ' ', preg_replace('~^\s+|\s+$~u', '', $value));
}
/** | true |
Other | laravel | framework | 644c9d8d6c63d37fcd0c9a917fff821a512e4e1d.json | improve unicode support on Str::squish() (#41877) | tests/Support/SupportStrTest.php | @@ -547,6 +547,12 @@ public function testSquish()
php
framework
'));
+ $this->assertSame('laravel php framework', Str::squish(' laravel php framework '));
+ $this->assertSame('123', Str::squish(' 123 '));
+ $this->assertSame('だ', Str::squish('だ'));
+ $this->assertSame('ム', Str::squish('ム'));
+ $this->assertSame('だ', Str::squish(' だ '));
+ $this->assertSame('ム', Str::squish(' ム '));
}
public function testStudly() | true |
Other | laravel | framework | 644c9d8d6c63d37fcd0c9a917fff821a512e4e1d.json | improve unicode support on Str::squish() (#41877) | tests/Support/SupportStringableTest.php | @@ -620,6 +620,12 @@ public function testSquish()
with
spaces
')->squish());
+ $this->assertSame('laravel php framework', (string) $this->stringable(' laravel php framework ')->squish());
+ $this->assertSame('123', (string) $this->stringable(' 123 ')->squish());
+ $this->assertSame('だ', (string) $this->stringable('だ')->squish());
+ $this->assertSame('ム', (string) $this->stringable('ム')->squish());
+ $this->assertSame('だ', (string) $this->stringable(' だ ')->squish());
+ $this->assertSame('ム', (string) $this->stringable(' ム ')->squish());
}
public function testStart() | true |
Other | laravel | framework | 76a7b3cc7942eda2841518ca7877a5e009570b22.json | Fix seeder property for in-memory tests (#41869) | src/Illuminate/Database/Console/Migrations/MigrateCommand.php | @@ -24,6 +24,7 @@ class MigrateCommand extends BaseCommand
{--schema-path= : The path to a schema dump file}
{--pretend : Dump the SQL queries that would be run}
{--seed : Indicates if the seed task should be re-run}
+ {--seeder= : The class name of the root seeder}
{--step : Force the migrations to be run so they can be rolled back individually}';
/**
@@ -89,7 +90,10 @@ public function handle()
// seed task to re-populate the database, which is convenient when adding
// a migration and a seed at the same time, as it is only this command.
if ($this->option('seed') && ! $this->option('pretend')) {
- $this->call('db:seed', ['--force' => true]);
+ $this->call('db:seed', [
+ '--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder',
+ '--force' => true,
+ ]);
}
});
| true |
Other | laravel | framework | 76a7b3cc7942eda2841518ca7877a5e009570b22.json | Fix seeder property for in-memory tests (#41869) | src/Illuminate/Foundation/Testing/RefreshDatabase.php | @@ -56,6 +56,7 @@ protected function migrateUsing()
{
return [
'--seed' => $this->shouldSeed(),
+ '--seeder' => $this->seeder(),
];
}
| true |
Other | laravel | framework | 05dd0e064312bd6e1e193dde7309c363a35ec92d.json | Fix null name (#41870) | src/Illuminate/Mail/Message.php | @@ -220,7 +220,7 @@ protected function addAddresses($address, $name, $type)
if (is_array($address)) {
$type = lcfirst($type);
- $addresses = collect($address)->map(function (string|array $address, $key) {
+ $addresses = collect($address)->map(function ($address, $key) {
if (is_string($key) && is_string($address)) {
return new Address($key, $address);
}
@@ -229,6 +229,10 @@ protected function addAddresses($address, $name, $type)
return new Address($address['email'] ?? $address['address'], $address['name'] ?? null);
}
+ if (is_null($address)) {
+ return new Address($key);
+ }
+
return $address;
})->all();
| false |
Other | laravel | framework | 2f51de56f1a4d207c3bd82984a96882f9da606fe.json | update doc block | src/Illuminate/Database/Connection.php | @@ -342,7 +342,7 @@ public function selectOne($query, $bindings = [], $useReadPdo = true)
* @param bool $useReadPdo
* @return mixed
*
- * @throws MultipleColumnsSelectedException
+ * @throws \Illuminate\Database\MultipleColumnsSelectedException
*/
public function scalar($query, $bindings = [], $useReadPdo = true)
{ | false |
Other | laravel | framework | 9d3f03b0c53dfe78a30ebde7e022ce4de5a53192.json | Update maintainer action (#41839) | .github/workflows/pull-requests.yml | @@ -13,9 +13,11 @@ permissions:
jobs:
uneditable:
if: github.repository == 'laravel/framework'
+
runs-on: ubuntu-latest
+
steps:
- - uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
+ - uses: actions/github-script@v6
with:
script: |
const query = `
@@ -49,14 +51,21 @@ jobs:
return;
}
- if (!pullRequest.maintainerCanModify) {
+ if (! pullRequest.maintainerCanModify) {
console.log('PR not owned by Laravel and does not have maintainer edits enabled');
- await github.issues.createComment({
+ await github.rest.issues.createComment({
issue_number: pullNumber,
owner: 'laravel',
repo: 'framework',
- body: "Thanks for submitting a PR!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For information on how to do this, [see the relevant GitHub documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork)."
+ body: "Thanks for submitting a PR!\n\nIn order to review and merge PRs most efficiently, we require that all PRs grant maintainer edit access before we review them. For information on how to do this, [see the relevant GitHub documentation](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork). Additionally, GitHub doesn't allow maintainer permissions from organization accounts. Please resubmit this PR with maintainer permissions enabled."
+ });
+
+ await github.rest.pulls.update({
+ pull_number: pullNumber,
+ owner: 'laravel',
+ repo: 'framework',
+ state: 'closed'
});
}
} catch(e) { | false |
Other | laravel | framework | 2b5d80b51ec020641fdfb3d2be255385a9c337ea.json | Apply fixes from StyleCI | src/Illuminate/Bus/PendingBatch.php | @@ -295,7 +295,7 @@ public function dispatchAfterResponse()
/**
* Dispatch an existing batch.
*
- * @param \Illuminate\Bus\Batch $batch
+ * @param \Illuminate\Bus\Batch $batch
* @return void
*
* @throws \Throwable | false |
Other | laravel | framework | 71bb3970522c90c66b358ff464d5c3cd3bd5f781.json | Provide pending request to retry callback (#41779) | src/Illuminate/Http/Client/PendingRequest.php | @@ -719,7 +719,7 @@ public function send(string $method, string $url, array $options = [])
if (! $response->successful()) {
try {
- $shouldRetry = $this->retryWhenCallback ? call_user_func($this->retryWhenCallback, $response->toException()) : true;
+ $shouldRetry = $this->retryWhenCallback ? call_user_func($this->retryWhenCallback, $response->toException(), $this) : true;
} catch (Exception $exception) {
$shouldRetry = false;
| true |
Other | laravel | framework | 71bb3970522c90c66b358ff464d5c3cd3bd5f781.json | Provide pending request to retry callback (#41779) | tests/Http/HttpClientTest.php | @@ -1290,6 +1290,31 @@ public function testRequestExceptionIsNotThrownWithoutRetriesIfRetryNotNecessary
$this->factory->assertSentCount(1);
}
+ public function testRequestCanBeModifiedInRetryCallback()
+ {
+ $this->factory->fake([
+ '*' => $this->factory->sequence()
+ ->push(['error'], 500)
+ ->push(['ok'], 200),
+ ]);
+
+ $response = $this->factory
+ ->retry(2, 1000, function ($exception, $request) {
+ $this->assertInstanceOf(PendingRequest::class, $request);
+
+ $request->withHeaders(['Foo' => 'Bar']);
+
+ return true;
+ }, false)
+ ->get('http://foo.com/get');
+
+ $this->assertTrue($response->successful());
+
+ $this->factory->assertSent(function (Request $request) {
+ return $request->hasHeader('Foo') && $request->header('Foo') === ['Bar'];
+ });
+ }
+
public function testExceptionThrownInRetryCallbackWithoutRetrying()
{
$this->factory->fake([ | true |
Other | laravel | framework | 89c093f86ba0916724713208ee3b21194fba3e78.json | Apply fixes from StyleCI | tests/Integration/Database/DatabaseCustomCastsTest.php | @@ -49,7 +49,7 @@ public function test_custom_casting()
$this->assertEquals(['name' => 'Taylor'], $model->array_object->toArray());
$this->assertEquals(['name' => 'Taylor'], $model->array_object_json->toArray());
$this->assertEquals(['name' => 'Taylor'], $model->collection->toArray());
- $this->assertSame('Taylor', (string)$model->stringable);
+ $this->assertSame('Taylor', (string) $model->stringable);
$model->array_object['age'] = 34;
$model->array_object['meta']['title'] = 'Developer';
@@ -85,7 +85,7 @@ public function test_custom_casting_nullable_values()
$model = new TestEloquentModelWithCustomCastsNullable();
$model->array_object = null;
- $model->array_object_json = null;
+ $model->array_object_json = null;
$model->collection = collect();
$model->stringable = null;
@@ -96,7 +96,7 @@ public function test_custom_casting_nullable_values()
$this->assertEmpty($model->array_object);
$this->assertEmpty($model->array_object_json);
$this->assertEmpty($model->collection);
- $this->assertSame('', (string)$model->stringable);
+ $this->assertSame('', (string) $model->stringable);
$model->array_object['name'] = 'Taylor';
$model->array_object['meta']['title'] = 'Developer'; | false |
Other | laravel | framework | c4b15293eb57536a8cf26811ba84a148e061181f.json | add test for cache manager (#41781) | tests/Cache/CacheManagerTest.php | @@ -92,6 +92,104 @@ public function testItMakesRepositoryWhenContainerHasNoDispatcher()
$this->assertNotNull($repo->getEventDispatcher());
}
+ public function testItRefreshesDispatcherOnAllStores()
+ {
+ $userConfig = [
+ 'cache' => [
+ 'stores' => [
+ 'store_1' => [
+ 'driver' => 'array',
+ ],
+ 'store_2' => [
+ 'driver' => 'array',
+ ],
+ ],
+ ],
+ ];
+
+ $app = $this->getApp($userConfig);
+ $cacheManager = new CacheManager($app);
+ $repo1 = $cacheManager->store('store_1');
+ $repo2 = $cacheManager->store('store_2');
+
+ $this->assertNull($repo1->getEventDispatcher());
+ $this->assertNull($repo2->getEventDispatcher());
+
+ $dispatcher = new Event;
+ $app->bind(Dispatcher::class, fn () => $dispatcher);
+
+ $cacheManager->refreshEventDispatcher();
+
+ $this->assertNotSame($repo1, $repo2);
+ $this->assertSame($dispatcher, $repo1->getEventDispatcher());
+ $this->assertSame($dispatcher, $repo2->getEventDispatcher());
+ }
+
+ public function testItSetsDefaultDriverChangesGlobalConfig()
+ {
+ $userConfig = [
+ 'cache' => [
+ 'default' => 'store_1',
+ 'stores' => [
+ 'store_1' => [
+ 'driver' => 'array',
+ ],
+ 'store_2' => [
+ 'driver' => 'array',
+ ],
+ ],
+ ],
+ ];
+
+ $app = $this->getApp($userConfig);
+ $cacheManager = new CacheManager($app);
+
+ $cacheManager->setDefaultDriver('><((((@>');
+
+ $this->assertEquals('><((((@>', $app->get('config')->get('cache.default'));
+ }
+
+ public function testItPurgesMemoizedStoreObjects()
+ {
+ $userConfig = [
+ 'cache' => [
+ 'stores' => [
+ 'store_1' => [
+ 'driver' => 'array',
+ ],
+ 'store_2' => [
+ 'driver' => 'null',
+ ],
+ ],
+ ],
+ ];
+
+ $app = $this->getApp($userConfig);
+ $cacheManager = new CacheManager($app);
+
+ $repo1 = $cacheManager->store('store_1');
+ $repo2 = $cacheManager->store('store_1');
+
+ $repo3 = $cacheManager->store('store_2');
+ $repo4 = $cacheManager->store('store_2');
+ $repo5 = $cacheManager->store('store_2');
+
+ $this->assertSame($repo1, $repo2);
+ $this->assertSame($repo3, $repo4);
+ $this->assertSame($repo3, $repo5);
+ $this->assertNotSame($repo1, $repo5);
+
+ $cacheManager->purge('store_1');
+
+ // Make sure a now object is built this time.
+ $repo6 = $cacheManager->store('store_1');
+ $this->assertNotSame($repo1, $repo6);
+
+ // Make sure Purge does not delete all objects.
+ $repo7 = $cacheManager->store('store_2');
+ $this->assertSame($repo3, $repo7);
+ }
+
public function testForgetDriver()
{
$cacheManager = m::mock(CacheManager::class)
@@ -181,8 +279,8 @@ public function testThrowExceptionWhenUnknownStoreIsUsed()
protected function getApp(array $userConfig)
{
- $app = Container::getInstance();
- $app->bind('config', fn () => new Repository($userConfig));
+ $app = new Container;
+ $app->singleton('config', fn () => new Repository($userConfig));
return $app;
} | false |
Other | laravel | framework | d1683918a619c07305319e62f8c863c4ee7818c3.json | Apply fixes from StyleCI | src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php | @@ -481,7 +481,7 @@ public function whereBelongsTo($related, $relationshipName = null, $boolean = 'a
}
if ($relatedCollection->isEmpty()) {
- throw new InvalidArgumentException("Collection given to whereBelongsTo method may not be empty.");
+ throw new InvalidArgumentException('Collection given to whereBelongsTo method may not be empty.');
}
if ($relationshipName === null) { | false |
Other | laravel | framework | 1a81bc74ecac5c1f587b8af85fdd49a135e47a9d.json | Allow int as type for value in pluck (#41751) | src/Illuminate/Collections/Collection.php | @@ -701,7 +701,7 @@ public function last(callable $callback = null, $default = null)
/**
* Get the values of a given key.
*
- * @param string|array<array-key, string> $value
+ * @param string|int|array<array-key, string> $value
* @param string|null $key
* @return static<int, mixed>
*/ | false |
Other | laravel | framework | 98aa74abd91eefa7fd14cc5a649a6fa264bbdf97.json | fix nth where step <= offset (#41645)
Co-authored-by: Misha van Tol <misha.vantol@synetic.nl> | src/Illuminate/Collections/Collection.php | @@ -806,8 +806,8 @@ public function nth($step, $offset = 0)
$position = 0;
- foreach ($this->items as $item) {
- if ($position % $step === $offset) {
+ foreach ($this->slice($offset)->items as $item) {
+ if ($position % $step === 0) {
$new[] = $item;
}
| true |
Other | laravel | framework | 98aa74abd91eefa7fd14cc5a649a6fa264bbdf97.json | fix nth where step <= offset (#41645)
Co-authored-by: Misha van Tol <misha.vantol@synetic.nl> | src/Illuminate/Collections/LazyCollection.php | @@ -796,8 +796,8 @@ public function nth($step, $offset = 0)
return new static(function () use ($step, $offset) {
$position = 0;
- foreach ($this as $item) {
- if ($position % $step === $offset) {
+ foreach ($this->slice($offset) as $item) {
+ if ($position % $step === 0) {
yield $item;
}
| true |
Other | laravel | framework | 98aa74abd91eefa7fd14cc5a649a6fa264bbdf97.json | fix nth where step <= offset (#41645)
Co-authored-by: Misha van Tol <misha.vantol@synetic.nl> | tests/Support/SupportCollectionTest.php | @@ -2956,6 +2956,8 @@ public function testNth($collection)
$this->assertEquals(['b', 'f'], $data->nth(4, 1)->all());
$this->assertEquals(['c'], $data->nth(4, 2)->all());
$this->assertEquals(['d'], $data->nth(4, 3)->all());
+ $this->assertEquals(['c', 'e'], $data->nth(2, 2)->all());
+ $this->assertEquals(['c', 'd', 'e', 'f'], $data->nth(1, 2)->all());
}
/** | true |
Other | laravel | framework | 613b0e22c3d6601994d539fb4974b81a464ae54a.json | Add support for multiple new lines (#41638) | src/Illuminate/Support/Stringable.php | @@ -67,11 +67,12 @@ public function append(...$values)
/**
* Append a new line to the string.
*
+ * @param int $count
* @return $this
*/
- public function newLine()
+ public function newLine($count = 1)
{
- return $this->append(PHP_EOL);
+ return $this->append(str_repeat(PHP_EOL, $count));
}
/** | true |
Other | laravel | framework | 613b0e22c3d6601994d539fb4974b81a464ae54a.json | Add support for multiple new lines (#41638) | tests/Support/SupportStringableTest.php | @@ -422,6 +422,7 @@ public function testAscii()
public function testNewLine()
{
$this->assertSame('Laravel'.PHP_EOL, (string) $this->stringable('Laravel')->newLine());
+ $this->assertSame('foo'.PHP_EOL.PHP_EOL.'bar', (string) $this->stringable('foo')->newLine(2)->append('bar'));
}
public function testAsciiWithSpecificLocale() | true |
Other | laravel | framework | fb8d38c41cd68bafc2b34ade348935e7380bf958.json | Apply fixes from StyleCI | src/Illuminate/Collections/Enumerable.php | @@ -461,6 +461,7 @@ public function whereNotInStrict($key, $values);
* Filter the items, removing any items that don't match the given type(s).
*
* @template TWhereInstanceOf
+ *
* @param class-string<TWhereInstanceOf>|array<array-key, class-string<TWhereInstanceOf>> $type
* @return static<TKey, TWhereInstanceOf>
*/ | true |
Other | laravel | framework | fb8d38c41cd68bafc2b34ade348935e7380bf958.json | Apply fixes from StyleCI | src/Illuminate/Collections/Traits/EnumeratesValues.php | @@ -680,6 +680,7 @@ public function whereNotInStrict($key, $values)
* Filter the items, removing any items that don't match the given type(s).
*
* @template TWhereInstanceOf
+ *
* @param class-string<TWhereInstanceOf>|array<array-key, class-string<TWhereInstanceOf>> $type
* @return static<TKey, TWhereInstanceOf>
*/ | true |
Other | laravel | framework | 6e14167dd25827128e38429f4fa3c7985c497d89.json | Add withoutMiddleware docbloc (#41655) | src/Illuminate/Support/Facades/Route.php | @@ -30,6 +30,7 @@
* @method static \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
* @method static \Illuminate\Routing\RouteRegistrar scopeBindings()
* @method static \Illuminate\Routing\RouteRegistrar where(array $where)
+ * @method static \Illuminate\Routing\RouteRegistrar withoutMiddleware(array|string $middleware)
* @method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(\Closure|string|array $attributes, \Closure|string $routes)
* @method static \Illuminate\Routing\ResourceRegistrar resourceVerbs(array $verbs = [])
* @method static string|null currentRouteAction() | false |
Other | laravel | framework | 447f6203a3322d3af624df651627a7480df7f3a7.json | Ensure int type of getSeconds() output (#41623) | src/Illuminate/Cache/Repository.php | @@ -529,7 +529,7 @@ protected function getSeconds($ttl)
$duration = Carbon::now()->diffInRealSeconds($duration, false);
}
- return (int) $duration > 0 ? $duration : 0;
+ return (int) ($duration > 0 ? $duration : 0);
}
/** | false |
Other | laravel | framework | 6094c427834827b9932f848b6a37d788c181e814.json | Use the nullsafe operator in SessionGuard (#41561) | src/Illuminate/Auth/SessionGuard.php | @@ -685,9 +685,7 @@ protected function rehashUserPassword($password, $attribute)
*/
public function attempting($callback)
{
- if (isset($this->events)) {
- $this->events->listen(Events\Attempting::class, $callback);
- }
+ $this->events?->listen(Events\Attempting::class, $callback);
}
/**
@@ -699,11 +697,7 @@ public function attempting($callback)
*/
protected function fireAttemptEvent(array $credentials, $remember = false)
{
- if (isset($this->events)) {
- $this->events->dispatch(new Attempting(
- $this->name, $credentials, $remember
- ));
- }
+ $this->events?->dispatch(new Attempting($this->name, $credentials, $remember));
}
/**
@@ -714,11 +708,7 @@ protected function fireAttemptEvent(array $credentials, $remember = false)
*/
protected function fireValidatedEvent($user)
{
- if (isset($this->events)) {
- $this->events->dispatch(new Validated(
- $this->name, $user
- ));
- }
+ $this->events?->dispatch(new Validated($this->name, $user));
}
/**
@@ -730,11 +720,7 @@ protected function fireValidatedEvent($user)
*/
protected function fireLoginEvent($user, $remember = false)
{
- if (isset($this->events)) {
- $this->events->dispatch(new Login(
- $this->name, $user, $remember
- ));
- }
+ $this->events?->dispatch(new Login($this->name, $user, $remember));
}
/**
@@ -745,11 +731,7 @@ protected function fireLoginEvent($user, $remember = false)
*/
protected function fireAuthenticatedEvent($user)
{
- if (isset($this->events)) {
- $this->events->dispatch(new Authenticated(
- $this->name, $user
- ));
- }
+ $this->events?->dispatch(new Authenticated($this->name, $user));
}
/**
@@ -760,11 +742,7 @@ protected function fireAuthenticatedEvent($user)
*/
protected function fireOtherDeviceLogoutEvent($user)
{
- if (isset($this->events)) {
- $this->events->dispatch(new OtherDeviceLogout(
- $this->name, $user
- ));
- }
+ $this->events?->dispatch(new OtherDeviceLogout($this->name, $user));
}
/**
@@ -776,11 +754,7 @@ protected function fireOtherDeviceLogoutEvent($user)
*/
protected function fireFailedEvent($user, array $credentials)
{
- if (isset($this->events)) {
- $this->events->dispatch(new Failed(
- $this->name, $user, $credentials
- ));
- }
+ $this->events?->dispatch(new Failed($this->name, $user, $credentials));
}
/** | false |
Other | laravel | framework | 91dfbd0c3823069eb8e8d65752a6c85e81e5b4d8.json | use nullsafe operator in Connection (#41544) | src/Illuminate/Database/Connection.php | @@ -852,9 +852,7 @@ public function beforeExecuting(Closure $callback)
*/
public function listen(Closure $callback)
{
- if (isset($this->events)) {
- $this->events->listen(Events\QueryExecuted::class, $callback);
- }
+ $this->events?->listen(Events\QueryExecuted::class, $callback);
}
/**
@@ -865,11 +863,7 @@ public function listen(Closure $callback)
*/
protected function fireConnectionEvent($event)
{
- if (! isset($this->events)) {
- return;
- }
-
- return $this->events->dispatch(match ($event) {
+ return $this->events?->dispatch(match ($event) {
'beganTransaction' => new TransactionBeginning($this),
'committed' => new TransactionCommitted($this),
'rollingBack' => new TransactionRolledBack($this),
@@ -885,9 +879,7 @@ protected function fireConnectionEvent($event)
*/
protected function event($event)
{
- if (isset($this->events)) {
- $this->events->dispatch($event);
- }
+ $this->events?->dispatch($event);
}
/** | true |
Other | laravel | framework | 91dfbd0c3823069eb8e8d65752a6c85e81e5b4d8.json | use nullsafe operator in Connection (#41544) | src/Illuminate/Redis/Connections/Connection.php | @@ -132,9 +132,7 @@ public function command($method, array $parameters = [])
*/
protected function event($event)
{
- if (isset($this->events)) {
- $this->events->dispatch($event);
- }
+ $this->events?->dispatch($event);
}
/**
@@ -145,9 +143,7 @@ protected function event($event)
*/
public function listen(Closure $callback)
{
- if (isset($this->events)) {
- $this->events->listen(CommandExecuted::class, $callback);
- }
+ $this->events?->listen(CommandExecuted::class, $callback);
}
/** | true |
Other | laravel | framework | 4d770fd9a31ad02f724428ec0d15ca38a81cc3d1.json | Bugfix #41302 - Alternative (#41546)
* Bugfix #41302 - Alternative
This is an alternative option to PR #41502, and adds a match
for 'socket' ("socket error when (reading|writing)") to trigger
a reconnection.
I am not sure if this is valid in other languages, too.
My personal preference would be to remove the entire if and
ALWAYS reconnect on any Exception
Signed-Off-By: Rob Thomas xrobau@gmail.com
* Fix typo (used vim instead of my usual IDE) | src/Illuminate/Redis/Connections/PhpRedisConnection.php | @@ -531,7 +531,7 @@ public function command($method, array $parameters = [])
try {
return parent::command($method, $parameters);
} catch (RedisException $e) {
- if (str_contains($e->getMessage(), 'went away')) {
+ if (str_contains($e->getMessage(), 'went away') || str_contains($e->getMessage(), 'socket')) {
$this->client = $this->connector ? call_user_func($this->connector) : $this->client;
}
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.