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 | bf43c1473c85befc501791bcbe7fa18e88a22f25.json | Remove unused imports | src/Illuminate/Foundation/Console/ViewCacheCommand.php | @@ -4,7 +4,6 @@
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\View;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
| true |
Other | laravel | framework | bf43c1473c85befc501791bcbe7fa18e88a22f25.json | Remove unused imports | src/Illuminate/Routing/Exceptions/InvalidSignatureException.php | @@ -2,7 +2,6 @@
namespace Illuminate\Routing\Exceptions;
-use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;
class InvalidSignatureException extends HttpException | true |
Other | laravel | framework | bf43c1473c85befc501791bcbe7fa18e88a22f25.json | Remove unused imports | tests/Database/DatabaseEloquentPolymorphicIntegrationTest.php | @@ -4,7 +4,6 @@
use PHPUnit\Framework\TestCase;
use Illuminate\Database\Connection;
-use Illuminate\Database\Query\Builder;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Model as Eloquent;
| true |
Other | laravel | framework | ec8fb5596b67de0edfcc8cc7c2167d6c184f080b.json | Simplify validators (#23635) | src/Illuminate/Foundation/Http/FormRequest.php | @@ -175,7 +175,7 @@ public function validated()
$rules = $this->container->call([$this, 'rules']);
return $this->only(collect($rules)->keys()->map(function ($rule) {
- return str_contains($rule, '.') ? explode('.', $rule)[0] : $rule;
+ return explode('.', $rule)[0];
})->unique()->toArray());
}
| true |
Other | laravel | framework | ec8fb5596b67de0edfcc8cc7c2167d6c184f080b.json | Simplify validators (#23635) | src/Illuminate/Foundation/Providers/FoundationServiceProvider.php | @@ -2,7 +2,6 @@
namespace Illuminate\Foundation\Providers;
-use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\AggregateServiceProvider;
@@ -42,7 +41,7 @@ public function registerRequestValidation()
validator()->validate($this->all(), $rules, ...$params);
return $this->only(collect($rules)->keys()->map(function ($rule) {
- return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule;
+ return explode('.', $rule)[0];
})->unique()->toArray());
});
} | true |
Other | laravel | framework | ec8fb5596b67de0edfcc8cc7c2167d6c184f080b.json | Simplify validators (#23635) | src/Illuminate/Foundation/Validation/ValidatesRequests.php | @@ -2,7 +2,6 @@
namespace Illuminate\Foundation\Validation;
-use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Validation\ValidationException;
@@ -58,7 +57,7 @@ public function validate(Request $request, array $rules,
protected function extractInputFromRules(Request $request, array $rules)
{
return $request->only(collect($rules)->keys()->map(function ($rule) {
- return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule;
+ return explode('.', $rule)[0];
})->unique()->toArray());
}
| true |
Other | laravel | framework | ec8fb5596b67de0edfcc8cc7c2167d6c184f080b.json | Simplify validators (#23635) | src/Illuminate/Validation/Validator.php | @@ -309,7 +309,7 @@ public function validate()
$data = collect($this->getData());
return $data->only(collect($this->getRules())->keys()->map(function ($rule) {
- return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule;
+ return explode('.', $rule)[0];
})->unique())->toArray();
}
| true |
Other | laravel | framework | 7affebd69bd212da4f7e0674b61c5df51d101b30.json | make return type a bit more precise (#23634) | src/Illuminate/Contracts/Broadcasting/ShouldBroadcast.php | @@ -2,12 +2,14 @@
namespace Illuminate\Contracts\Broadcasting;
+use Illuminate\Broadcasting\Channel;
+
interface ShouldBroadcast
{
/**
* Get the channels the event should broadcast on.
*
- * @return array
+ * @return Channel|Channel[]
*/
public function broadcastOn();
} | false |
Other | laravel | framework | bc4624cef6e60b8f711da971f7a466d574f484c6.json | add model factory after callbacks with states | src/Illuminate/Database/Eloquent/Factory.php | @@ -120,7 +120,22 @@ public function state($class, $state, $attributes)
*/
public function afterMaking($class, $callback)
{
- $this->afterMaking[$class][] = $callback;
+ $this->afterMaking[$class]['default'][] = $callback;
+
+ return $this;
+ }
+
+ /**
+ * Define a callback to run after making a model with given type.
+ *
+ * @param string $class
+ * @param string $state
+ * @param callable $callback
+ * @return $this
+ */
+ public function afterMakingState($class, $state, callable $callback)
+ {
+ $this->afterMaking[$class][$state][] = $callback;
return $this;
}
@@ -134,7 +149,22 @@ public function afterMaking($class, $callback)
*/
public function afterCreating($class, $callback)
{
- $this->afterCreating[$class][] = $callback;
+ $this->afterCreating[$class]['default'][] = $callback;
+
+ return $this;
+ }
+
+ /**
+ * Define a callback to run after creating a model with given type.
+ *
+ * @param string $class
+ * @param string $state
+ * @param callable $callback
+ * @return $this
+ */
+ public function afterCreatingState($class, $state, callable $callback)
+ {
+ $this->afterCreating[$class][$state][] = $callback;
return $this;
} | true |
Other | laravel | framework | bc4624cef6e60b8f711da971f7a466d574f484c6.json | add model factory after callbacks with states | src/Illuminate/Database/Eloquent/FactoryBuilder.php | @@ -300,6 +300,9 @@ protected function applyStates(array $definition, array $attributes = [])
{
foreach ($this->activeStates as $state) {
if (! isset($this->states[$this->class][$state])) {
+ if ($this->afterStateExists($state)) {
+ continue;
+ }
throw new InvalidArgumentException("Unable to locate [{$state}] state for [{$this->class}].");
}
@@ -366,13 +369,7 @@ protected function expandAttributes(array $attributes)
*/
public function callAfterMaking($models)
{
- $models->each(function ($model) {
- if (isset($this->afterMaking[$this->class])) {
- foreach ($this->afterMaking[$this->class] as $callback) {
- $callback($model, $this->faker);
- }
- }
- });
+ $this->callAfter($this->afterMaking, $models);
}
/**
@@ -383,12 +380,52 @@ public function callAfterMaking($models)
*/
public function callAfterCreating($models)
{
- $models->each(function ($model) {
- if (isset($this->afterCreating[$this->class])) {
- foreach ($this->afterCreating[$this->class] as $callback) {
- $callback($model, $this->faker);
- }
+ $this->callAfter($this->afterCreating, $models);
+ }
+
+ /**
+ * Call after callbacks for each model and state.
+ *
+ * @param array $afterCallbacks
+ * @param \Illuminate\Support\Collection $models
+ * @return void
+ */
+ protected function callAfter(array $afterCallbacks, $models)
+ {
+ $states = array_merge([$this->name], $this->activeStates);
+
+ $models->each(function ($model) use ($states, $afterCallbacks) {
+ foreach ($states as $state) {
+ $this->callAfterCallbacks($afterCallbacks, $model, $state);
}
});
}
+
+ /**
+ * Call after callbacks for each model and state.
+ *
+ * @param array $afterCallbacks
+ * @param Model $model
+ * @param string $state
+ * @return void
+ */
+ protected function callAfterCallbacks(array $afterCallbacks, $model, $state)
+ {
+ if (!isset($afterCallbacks[$this->class][$state])) {
+ return;
+ }
+
+ foreach ($afterCallbacks[$this->class][$state] as $callback) {
+ $callback($model, $this->faker);
+ }
+ }
+
+ /**
+ * @param string $state
+ * @return bool
+ */
+ protected function afterStateExists($state)
+ {
+ return isset($this->afterMaking[$this->class][$state]) || isset($this->afterCreating[$this->class][$state]);
+ }
} | true |
Other | laravel | framework | bc4624cef6e60b8f711da971f7a466d574f484c6.json | add model factory after callbacks with states | tests/Integration/Database/EloquentFactoryBuilderTest.php | @@ -51,6 +51,14 @@ protected function getEnvironmentSetUp($app)
$user->setRelation('profile', $profile);
});
+ $factory->afterMakingState(FactoryBuildableUser::class, 'with_callable_server', function (FactoryBuildableUser $user, Generator $faker) {
+ $server = factory(FactoryBuildableServer::class)
+ ->states('callable')
+ ->make(['user_id' => $user->id]);
+
+ $user->servers->push($server);
+ });
+
$factory->define(FactoryBuildableTeam::class, function (Generator $faker) {
return [
'name' => $faker->name,
@@ -81,6 +89,12 @@ protected function getEnvironmentSetUp($app)
];
});
+ $factory->afterCreatingState(FactoryBuildableUser::class, 'with_callable_server', function(FactoryBuildableUser $user, Generator $faker){
+ $server = factory(FactoryBuildableServer::class)
+ ->states('callable')
+ ->create(['user_id' => $user->id]);
+ });
+
$factory->state(FactoryBuildableServer::class, 'inline', ['status' => 'inline']);
$app->singleton(Factory::class, function ($app) use ($factory) {
@@ -234,6 +248,15 @@ public function creating_models_with_after_callback()
$this->assertTrue($team->users->contains($team->owner));
}
+ /** @test **/
+ public function creating_models_with_after_callback_states()
+ {
+ $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->create();
+
+ $this->assertNotNull($user->profile);
+ $this->assertNotNull($user->servers->where('status', 'callable')->first());
+ }
+
/** @test */
public function making_models_with_a_custom_connection()
{
@@ -251,6 +274,15 @@ public function making_models_with_after_callback()
$this->assertNotNull($user->profile);
}
+
+ /** @test **/
+ public function making_models_with_after_callback_states()
+ {
+ $user = factory(FactoryBuildableUser::class)->states('with_callable_server')->make();
+
+ $this->assertNotNull($user->profile);
+ $this->assertNotNull($user->servers->where('status', 'callable')->first());
+ }
}
class FactoryBuildableUser extends Model | true |
Other | laravel | framework | 87838b56581bca1d5bc52f6d38de8bf1d52ace11.json | Allow higher order groupBy (#23608)
collect()->groupBy->computed() instead of
relying on a Closure value retriever. | src/Illuminate/Support/Collection.php | @@ -33,8 +33,9 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
* @var array
*/
protected static $proxies = [
- 'average', 'avg', 'contains', 'each', 'every', 'filter', 'first', 'flatMap', 'keyBy',
- 'map', 'max', 'min', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum', 'unique',
+ 'average', 'avg', 'contains', 'each', 'every', 'filter', 'first',
+ 'flatMap', 'groupBy', 'keyBy', 'map', 'max', 'min', 'partition',
+ 'reject', 'sortBy', 'sortByDesc', 'sum', 'unique',
];
/** | true |
Other | laravel | framework | 87838b56581bca1d5bc52f6d38de8bf1d52ace11.json | Allow higher order groupBy (#23608)
collect()->groupBy->computed() instead of
relying on a Closure value retriever. | tests/Support/SupportCollectionTest.php | @@ -2397,6 +2397,26 @@ public function testSplitEmptyCollection()
);
}
+ public function testHigherOrderCollectionGroupBy()
+ {
+ $collection = collect([
+ new TestSupportCollectionHigherOrderItem,
+ new TestSupportCollectionHigherOrderItem('TAYLOR'),
+ new TestSupportCollectionHigherOrderItem('foo'),
+ ]);
+
+ $this->assertEquals([
+ 'taylor' => [$collection[0]],
+ 'TAYLOR' => [$collection[1]],
+ 'foo' => [$collection[2]],
+ ], $collection->groupBy->name->toArray());
+
+ $this->assertEquals([
+ 'TAYLOR' => [$collection[0], $collection[1]],
+ 'FOO' => [$collection[2]],
+ ], $collection->groupBy->uppercase()->toArray());
+ }
+
public function testHigherOrderCollectionMap()
{
$person1 = (object) ['name' => 'Taylor'];
@@ -2647,11 +2667,16 @@ public function testGetWithNullReturnsNull()
class TestSupportCollectionHigherOrderItem
{
- public $name = 'taylor';
+ public $name;
+
+ public function __construct($name = 'taylor')
+ {
+ $this->name = $name;
+ }
public function uppercase()
{
- $this->name = strtoupper($this->name);
+ return $this->name = strtoupper($this->name);
}
}
| true |
Other | laravel | framework | 1f62d23c65c92a7ece0ceec2a99965adceb42d66.json | Remove unneeded parameter (#23583) | src/Illuminate/Routing/Middleware/ValidateSignature.php | @@ -18,7 +18,7 @@ class ValidateSignature
*/
public function handle($request, Closure $next)
{
- if ($request->hasValidSignature($request)) {
+ if ($request->hasValidSignature()) {
return $next($request);
}
| false |
Other | laravel | framework | 03e550fe04f395a59ac40ef683450c6c5a30842d.json | Apply fixes from StyleCI (#23558) | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -21,9 +21,9 @@
use Illuminate\Foundation\Console\EventMakeCommand;
use Illuminate\Foundation\Console\ModelMakeCommand;
use Illuminate\Foundation\Console\RouteListCommand;
+use Illuminate\Foundation\Console\ViewCacheCommand;
use Illuminate\Foundation\Console\ViewClearCommand;
use Illuminate\Session\Console\SessionTableCommand;
-use Illuminate\Foundation\Console\ViewCacheCommand;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand; | false |
Other | laravel | framework | 669b118bba3e8feb4d9b97a50a88602bde471464.json | Remove extra period from docblock (#23543) | src/Illuminate/Auth/TokenGuard.php | @@ -36,7 +36,7 @@ class TokenGuard implements Guard
*
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Http\Request $request
- * @param. string $inputKey
+ * @param string $inputKey
* @param string $storageKey
* @return void
*/ | false |
Other | laravel | framework | 8913981ce443ed0d57518800fe407ae4be5567b7.json | Apply fixes from StyleCI (#23546) | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -23,9 +23,9 @@
use Illuminate\Foundation\Console\RouteListCommand;
use Illuminate\Foundation\Console\ViewClearCommand;
use Illuminate\Session\Console\SessionTableCommand;
+use Illuminate\Foundation\Console\BladeCacheCommand;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
-use Illuminate\Foundation\Console\BladeCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Foundation\Console\ChannelMakeCommand; | false |
Other | laravel | framework | 9fd1273ad79a46bb3aa006129109c6bc72766e4b.json | add blade cache command | src/Illuminate/Foundation/Console/BladeCacheCommand.php | @@ -0,0 +1,83 @@
+<?php
+
+namespace Illuminate\Foundation\Console;
+
+use Illuminate\Console\Command;
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\View;
+use Symfony\Component\Finder\Finder;
+use Symfony\Component\Finder\SplFileInfo;
+
+class BladeCacheCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'blade:cache';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Compile all of the application's Blade templates";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $this->paths()->each(function ($path) {
+ $this->compileViews($this->bladeFilesIn([$path]));
+ });
+
+ $this->info('Blade templates cached successfully!');
+ }
+
+ /**
+ * Compile the given view files.
+ *
+ * @param \Illuminate\Support\Collection $views
+ * @return void
+ */
+ protected function compileViews(Collection $views)
+ {
+ $compiler = $this->laravel['blade.compiler'];
+
+ $views->map(function (SplFileInfo $file) use ($compiler) {
+ $compiler->compile($file->getRealPath());
+ });
+ }
+
+ /**
+ * Get the Blade files in the given path.
+ *
+ * @param array $paths
+ * @return \Illuminate\Support\Collection
+ */
+ protected function bladeFilesIn(array $paths)
+ {
+ return collect(Finder::create()->
+ in($paths)
+ ->exclude('vendor')
+ ->name('*.blade.php')->files());
+ }
+
+ /**
+ * Get all of the possible view paths.
+ *
+ * @return \Illuminate\Support\Collection
+ */
+ protected function paths()
+ {
+ $finder = $this->laravel['view']->getFinder();
+
+ return collect($finder->getPaths())->merge(
+ collect($finder->getHints())->flatten()
+ );
+ }
+} | true |
Other | laravel | framework | 9fd1273ad79a46bb3aa006129109c6bc72766e4b.json | add blade cache command | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -25,6 +25,7 @@
use Illuminate\Session\Console\SessionTableCommand;
use Illuminate\Foundation\Console\PolicyMakeCommand;
use Illuminate\Foundation\Console\RouteCacheCommand;
+use Illuminate\Foundation\Console\BladeCacheCommand;
use Illuminate\Foundation\Console\RouteClearCommand;
use Illuminate\Console\Scheduling\ScheduleRunCommand;
use Illuminate\Foundation\Console\ChannelMakeCommand;
@@ -83,6 +84,7 @@ class ArtisanServiceProvider extends ServiceProvider
* @var array
*/
protected $commands = [
+ 'BladeCache' => 'command.blade.cache',
'CacheClear' => 'command.cache.clear',
'CacheForget' => 'command.cache.forget',
'ClearCompiled' => 'command.clear-compiled',
@@ -208,6 +210,18 @@ protected function registerAuthMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerBladeCacheCommand()
+ {
+ $this->app->singleton('command.blade.cache', function ($app) {
+ return new BladeCacheCommand;
+ });
+ }
+
/**
* Register the command.
* | true |
Other | laravel | framework | 8eaa147fab01a92fdf1f520e58440512c84b744b.json | Apply fixes from StyleCI (#23539) | src/Illuminate/Support/Testing/Fakes/QueueFake.php | @@ -85,7 +85,7 @@ public function assertPushedWithChain($job, $expectedChain = [], $callback = nul
PHPUnit::assertTrue(
collect($expectedChain)->isNotEmpty(),
- "The expected chain can not be empty."
+ 'The expected chain can not be empty.'
);
$this->isChainOfObjects($expectedChain)
@@ -111,7 +111,7 @@ protected function assertPushedWithChainOfObjects($job, $expectedChain, $callbac
$this->pushed($job, $callback)->filter(function ($job) use ($chain) {
return $job->chained == $chain;
})->isNotEmpty(),
- "The expected chain was not pushed."
+ 'The expected chain was not pushed.'
);
}
| true |
Other | laravel | framework | 8eaa147fab01a92fdf1f520e58440512c84b744b.json | Apply fixes from StyleCI (#23539) | tests/Support/SupportTestingQueueFakeTest.php | @@ -106,26 +106,26 @@ public function testAssertPushedUsingBulk()
public function testAssertPushedWithChainUsingClassesOrObjectsArray()
{
$this->fake->push(new JobWithChainStub([
- new JobStub
+ new JobStub,
]));
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
- JobStub::class
+ JobStub::class,
]);
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
- new JobStub
+ new JobStub,
]);
}
public function testAssertPushedWithChainSameJobDifferentChains()
{
$this->fake->push(new JobWithChainStub([
- new JobStub
+ new JobStub,
]));
$this->fake->push(new JobWithChainStub([
new JobStub,
- new JobStub
+ new JobStub,
]));
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
@@ -134,23 +134,23 @@ public function testAssertPushedWithChainSameJobDifferentChains()
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
JobStub::class,
- JobStub::class
+ JobStub::class,
]);
}
public function testAssertPushedWithChainUsingCallback()
{
$this->fake->push(new JobWithChainAndParameterStub('first', [
new JobStub,
- new JobStub
+ new JobStub,
]));
$this->fake->push(new JobWithChainAndParameterStub('second', [
- new JobStub
+ new JobStub,
]));
$this->fake->assertPushedWithChain(JobWithChainAndParameterStub::class, [
- JobStub::class
+ JobStub::class,
], function ($job) {
return $job->parameter == 'second';
});
@@ -178,7 +178,7 @@ public function testAssertPushedWithChainErrorHandling()
}
$this->fake->push(new JobWithChainStub([
- new JobStub
+ new JobStub,
]));
try {
@@ -191,7 +191,7 @@ public function testAssertPushedWithChainErrorHandling()
try {
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
new JobStub,
- new JobStub
+ new JobStub,
]);
$this->fail();
} catch (ExpectationFailedException $e) {
@@ -201,7 +201,7 @@ public function testAssertPushedWithChainErrorHandling()
try {
$this->fake->assertPushedWithChain(JobWithChainStub::class, [
JobStub::class,
- JobStub::class
+ JobStub::class,
]);
$this->fail();
} catch (ExpectationFailedException $e) {
@@ -222,7 +222,7 @@ class JobWithChainStub
{
use Queueable;
- function __construct($chain)
+ public function __construct($chain)
{
$this->chain($chain);
}
@@ -239,7 +239,7 @@ class JobWithChainAndParameterStub
public $parameter;
- function __construct($parameter, $chain)
+ public function __construct($parameter, $chain)
{
$this->parameter = $parameter;
$this->chain($chain);
@@ -249,4 +249,4 @@ public function handle()
{
//
}
-}
\ No newline at end of file
+} | true |
Other | laravel | framework | ec5764c94ef567fe19644d137e3ce689dd47cdb4.json | remove Blade defaults (#23532)
current Blade functionality allows the user to define a default value if the first value is not set.
`{{ $name or 'Andrew' }}`
This feature was added in an early version of Laravel to be a shorthand for
`isset($name) ? $name : 'Andrew'`
PHP7 has introduced the null coalesce operator (`??`) which performs this exact functionality.
`$name ?? 'Andrew'`
While the 'or' feature was good when it was needed, it could produce unexpected results when the characters 'or' appeared anywhere in the Blade expression. This was solved with extensive regex, but was still somewhat error prone.
Now that Laravel requires PHP 7.1, we can utilize the null coalesce operator and remove the 'or' feature. User upgrade process will be a find and replace, and the number of characters will be identical.
```
{{ $name or 'Andrew' }}
{{ $name ?? 'Andrew' }}
``` | src/Illuminate/View/Compilers/Concerns/CompilesEchos.php | @@ -46,7 +46,7 @@ protected function compileRawEchos($value)
$callback = function ($matches) {
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
- return $matches[1] ? substr($matches[0], 1) : "<?php echo {$this->compileEchoDefaults($matches[2])}; ?>{$whitespace}";
+ return $matches[1] ? substr($matches[0], 1) : "<?php echo {$matches[2]}; ?>{$whitespace}";
};
return preg_replace_callback($pattern, $callback, $value);
@@ -65,7 +65,7 @@ protected function compileRegularEchos($value)
$callback = function ($matches) {
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
- $wrapped = sprintf($this->echoFormat, $this->compileEchoDefaults($matches[2]));
+ $wrapped = sprintf($this->echoFormat, $matches[2]);
return $matches[1] ? substr($matches[0], 1) : "<?php echo {$wrapped}; ?>{$whitespace}";
};
@@ -86,20 +86,9 @@ protected function compileEscapedEchos($value)
$callback = function ($matches) {
$whitespace = empty($matches[3]) ? '' : $matches[3].$matches[3];
- return $matches[1] ? $matches[0] : "<?php echo e({$this->compileEchoDefaults($matches[2])}); ?>{$whitespace}";
+ return $matches[1] ? $matches[0] : "<?php echo e({$matches[2]}); ?>{$whitespace}";
};
return preg_replace_callback($pattern, $callback, $value);
}
-
- /**
- * Compile the default values for the echo statement.
- *
- * @param string $value
- * @return string
- */
- public function compileEchoDefaults($value)
- {
- return preg_replace('/^(?=\$)(.+?)(?:\s+or\s+)(.+?)$/si', 'isset($1) ? $1 : $2', $value);
- }
} | true |
Other | laravel | framework | ec5764c94ef567fe19644d137e3ce689dd47cdb4.json | remove Blade defaults (#23532)
current Blade functionality allows the user to define a default value if the first value is not set.
`{{ $name or 'Andrew' }}`
This feature was added in an early version of Laravel to be a shorthand for
`isset($name) ? $name : 'Andrew'`
PHP7 has introduced the null coalesce operator (`??`) which performs this exact functionality.
`$name ?? 'Andrew'`
While the 'or' feature was good when it was needed, it could produce unexpected results when the characters 'or' appeared anywhere in the Blade expression. This was solved with extensive regex, but was still somewhat error prone.
Now that Laravel requires PHP 7.1, we can utilize the null coalesce operator and remove the 'or' feature. User upgrade process will be a find and replace, and the number of characters will be identical.
```
{{ $name or 'Andrew' }}
{{ $name ?? 'Andrew' }}
``` | tests/View/Blade/BladeEchoTest.php | @@ -11,8 +11,6 @@ public function testEchosAreCompiled()
$this->assertEquals('<?php echo $name; ?>', $this->compiler->compileString('{!!
$name
!!}'));
- $this->assertEquals('<?php echo isset($name) ? $name : \'foo\'; ?>',
- $this->compiler->compileString('{!! $name or \'foo\' !!}'));
$this->assertEquals('<?php echo e($name); ?>', $this->compiler->compileString('{{{$name}}}'));
$this->assertEquals('<?php echo e($name); ?>', $this->compiler->compileString('{{$name}}'));
@@ -25,30 +23,6 @@ public function testEchosAreCompiled()
$this->assertEquals("<?php echo e(\$name); ?>\n\n", $this->compiler->compileString("{{ \$name }}\n"));
$this->assertEquals("<?php echo e(\$name); ?>\r\n\r\n", $this->compiler->compileString("{{ \$name }}\r\n"));
- $this->assertEquals('<?php echo e(isset($name) ? $name : "foo"); ?>',
- $this->compiler->compileString('{{ $name or "foo" }}'));
- $this->assertEquals('<?php echo e(isset($user->name) ? $user->name : "foo"); ?>',
- $this->compiler->compileString('{{ $user->name or "foo" }}'));
- $this->assertEquals('<?php echo e(isset($name) ? $name : "foo"); ?>',
- $this->compiler->compileString('{{$name or "foo"}}'));
- $this->assertEquals('<?php echo e(isset($name) ? $name : "foo"); ?>', $this->compiler->compileString('{{
- $name or "foo"
- }}'));
-
- $this->assertEquals('<?php echo e(isset($name) ? $name : \'foo\'); ?>',
- $this->compiler->compileString('{{ $name or \'foo\' }}'));
- $this->assertEquals('<?php echo e(isset($name) ? $name : \'foo\'); ?>',
- $this->compiler->compileString('{{$name or \'foo\'}}'));
- $this->assertEquals('<?php echo e(isset($name) ? $name : \'foo\'); ?>', $this->compiler->compileString('{{
- $name or \'foo\'
- }}'));
-
- $this->assertEquals('<?php echo e(isset($age) ? $age : 90); ?>', $this->compiler->compileString('{{ $age or 90 }}'));
- $this->assertEquals('<?php echo e(isset($age) ? $age : 90); ?>', $this->compiler->compileString('{{$age or 90}}'));
- $this->assertEquals('<?php echo e(isset($age) ? $age : 90); ?>', $this->compiler->compileString('{{
- $age or 90
- }}'));
-
$this->assertEquals('<?php echo e("Hello world or foo"); ?>',
$this->compiler->compileString('{{ "Hello world or foo" }}'));
$this->assertEquals('<?php echo e("Hello world or foo"); ?>', | true |
Other | laravel | framework | 9f1fc50d5069914eaa33aa20950aa8187179ef34.json | Fix typo in test method name | tests/Cache/ClearCommandTest.php | @@ -119,7 +119,7 @@ public function testClearWithStoreArgumentAndTagsOption()
$this->runCommand($command, ['store' => 'redis', '--tags' => 'foo']);
}
- public function testClearWillClearsRealTimeFacades()
+ public function testClearWillClearRealTimeFacades()
{
$command = new ClearCommandTestStub(
$cacheManager = m::mock('Illuminate\Cache\CacheManager'), | false |
Other | laravel | framework | 7371846bab898dcc6a910b8eff514cc4140c1141.json | Use static instead of self | src/Illuminate/Database/Eloquent/Model.php | @@ -214,12 +214,12 @@ public static function withoutTouching($callback)
{
$currentClass = static::class;
- self::$ignoreOnTouch[] = $currentClass;
+ static::$ignoreOnTouch[] = $currentClass;
try {
call_user_func($callback);
} finally {
- self::$ignoreOnTouch = array_values(array_diff(self::$ignoreOnTouch, [$currentClass]));
+ static::$ignoreOnTouch = array_values(array_diff(static::$ignoreOnTouch, [$currentClass]));
}
}
@@ -230,7 +230,7 @@ public static function withoutTouching($callback)
*/
public function shouldTouch()
{
- foreach (self::$ignoreOnTouch as $ignoredClass) {
+ foreach (static::$ignoreOnTouch as $ignoredClass) {
if ($this instanceof $ignoredClass) {
return false;
} | false |
Other | laravel | framework | 4e0754d3b9d869c0fd23574ee725c67ac834b2dd.json | Add ArrayAccess test for Request object | tests/Http/HttpRequestTest.php | @@ -325,6 +325,34 @@ public function testInputMethod()
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $request['file']);
}
+ public function testArrayAccess()
+ {
+ $request = Request::create('/', 'GET', ['name' => null, 'foo' => ['bar' => null, 'baz' => '']]);
+ $request->setRouteResolver(function () use ($request) {
+ $route = new Route('GET', '/foo/bar/{id}/{name}', []);
+ $route->bind($request);
+ $route->setParameter('id', 'foo');
+ $route->setParameter('name', 'Taylor');
+
+ return $route;
+ });
+
+ $this->assertFalse(isset($request['non-existant']));
+ $this->assertNull($request['non-existant']);
+
+ $this->assertTrue(isset($request['name']));
+ $this->assertEquals(null, $request['name']);
+ $this->assertNotEquals('Taylor', $request['name']);
+
+ $this->assertTrue(isset($request['foo.bar']));
+ $this->assertEquals(null, $request['foo.bar']);
+ $this->assertTrue(isset($request['foo.baz']));
+ $this->assertEquals('', $request['foo.baz']);
+
+ $this->assertTrue(isset($request['id']));
+ $this->assertEquals('foo', $request['id']);
+ }
+
public function testAllMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]); | false |
Other | laravel | framework | 04091833c1d22406828862ef9d58519882342b61.json | remove test that isnt written properly | src/Illuminate/Queue/Queue.php | @@ -17,13 +17,6 @@ abstract class Queue
*/
protected $container;
- /**
- * The encrypter implementation.
- *
- * @var \Illuminate\Contracts\Encryption\Encrypter
- */
- protected $encrypter;
-
/**
* The connection name for the queue.
* | true |
Other | laravel | framework | 04091833c1d22406828862ef9d58519882342b61.json | remove test that isnt written properly | tests/Support/SupportTestingStorageFakeTest.php | @@ -1,41 +0,0 @@
-<?php
-
-namespace Illuminate\Tests\Support;
-
-use PHPUnit\Framework\TestCase;
-use Illuminate\Foundation\Application;
-use Illuminate\Support\Facades\Storage;
-use Illuminate\Filesystem\FilesystemManager;
-use PHPUnit\Framework\ExpectationFailedException;
-
-class StorageFakeTest extends TestCase
-{
- protected $fake;
-
- protected function setUp()
- {
- parent::setUp();
- $app = new Application;
- $app['path.storage'] = __DIR__;
- $app['filesystem'] = new FilesystemManager($app);
- Storage::setFacadeApplication($app);
- Storage::fake('testing');
- $this->fake = Storage::disk('testing');
- }
-
- public function testAssertExists()
- {
- $this->expectException(ExpectationFailedException::class);
-
- $this->fake->assertExists('letter.txt');
- }
-
- public function testAssertMissing()
- {
- $this->fake->put('letter.txt', 'hi');
-
- $this->expectException(ExpectationFailedException::class);
-
- $this->fake->assertMissing('letter.txt');
- }
-} | true |
Other | laravel | framework | 2115cf6274f4da1681311700b12416d637517340.json | Add cursor to ConnectionInterface (#23525) | src/Illuminate/Database/ConnectionInterface.php | @@ -27,18 +27,30 @@ public function raw($value);
*
* @param string $query
* @param array $bindings
+ * @param bool $useReadPdo
* @return mixed
*/
- public function selectOne($query, $bindings = []);
+ public function selectOne($query, $bindings = [], $useReadPdo = true);
/**
* Run a select statement against the database.
*
* @param string $query
* @param array $bindings
+ * @param bool $useReadPdo
* @return array
*/
- public function select($query, $bindings = []);
+ public function select($query, $bindings = [], $useReadPdo = true);
+
+ /**
+ * Run a select statement against the database and returns a generator.
+ *
+ * @param string $query
+ * @param array $bindings
+ * @param bool $useReadPdo
+ * @return \Generator
+ */
+ public function cursor($query, $bindings = [], $useReadPdo = true);
/**
* Run an insert statement against the database. | false |
Other | laravel | framework | 0252d09aa8d764d460ef9172fe919e66e8c21ee4.json | Apply StyleCI Fixes | src/Illuminate/Validation/Rules/Unique.php | @@ -36,7 +36,7 @@ public function ignore($id, $idColumn = null)
}
$this->ignore = $id;
- $this->idColumn = $idColumn?? 'id';
+ $this->idColumn = $idColumn ?? 'id';
return $this;
}
@@ -50,7 +50,7 @@ public function ignore($id, $idColumn = null)
*/
public function ignoreModel($model, $idColumn = null)
{
- $this->idColumn = $idColumn?? $model->getKeyName();
+ $this->idColumn = $idColumn ?? $model->getKeyName();
$this->ignore = $model->{$this->idColumn};
return $this;
@@ -67,7 +67,7 @@ public function __toString()
$this->table,
$this->column,
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
- $this->idColumn?? 'NULL',
+ $this->idColumn ?? 'NULL',
$this->formatWheres()
), ',');
} | true |
Other | laravel | framework | 0252d09aa8d764d460ef9172fe919e66e8c21ee4.json | Apply StyleCI Fixes | tests/Support/framework/testing/disks/testing/letter.txt | @@ -0,0 +1 @@
+hi
\ No newline at end of file | true |
Other | laravel | framework | 0252d09aa8d764d460ef9172fe919e66e8c21ee4.json | Apply StyleCI Fixes | tests/Validation/ValidationUniqueRuleTest.php | @@ -2,8 +2,8 @@
namespace Illuminate\Tests\Validation;
-use Illuminate\Database\Eloquent\Model;
use PHPUnit\Framework\TestCase;
+use Illuminate\Database\Eloquent\Model;
class ValidationUniqueRuleTest extends TestCase
{
@@ -23,9 +23,8 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,NULL,id_column,foo,bar', (string) $rule);
-
$model = new EloquentModelStub(['id_column' => 1]);
-
+
$rule = new \Illuminate\Validation\Rules\Unique('table', 'column');
$rule->ignore($model);
$rule->where('foo', 'bar'); | true |
Other | laravel | framework | 9cda938d168d8aceaab1ca0409eafce484458f0b.json | Ignore a given model during a unique check. | src/Illuminate/Validation/Rules/Unique.php | @@ -2,6 +2,8 @@
namespace Illuminate\Validation\Rules;
+use Illuminate\Database\Eloquent\Model;
+
class Unique
{
use DatabaseRule;
@@ -18,7 +20,7 @@ class Unique
*
* @var string
*/
- protected $idColumn = 'id';
+ protected $idColumn;
/**
* Ignore the given ID during the unique check.
@@ -27,10 +29,29 @@ class Unique
* @param string $idColumn
* @return $this
*/
- public function ignore($id, $idColumn = 'id')
+ public function ignore($id, $idColumn = null)
{
+ if ($id instanceof Model) {
+ return $this->ignoreModel($id, $idColumn);
+ }
+
$this->ignore = $id;
- $this->idColumn = $idColumn;
+ $this->idColumn = $idColumn?? 'id';
+
+ return $this;
+ }
+
+ /**
+ * Ignore the given model during the unique check.
+ *
+ * @param Model $model
+ * @param string|null $idColumn
+ * @return $this
+ */
+ public function ignoreModel($model, $idColumn = null)
+ {
+ $this->idColumn = $idColumn?? $model->getKeyName();
+ $this->ignore = $model->{$this->idColumn};
return $this;
}
@@ -46,7 +67,7 @@ public function __toString()
$this->table,
$this->column,
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
- $this->idColumn,
+ $this->idColumn?? 'NULL',
$this->formatWheres()
), ',');
} | true |
Other | laravel | framework | 9cda938d168d8aceaab1ca0409eafce484458f0b.json | Ignore a given model during a unique check. | tests/Validation/ValidationUniqueRuleTest.php | @@ -2,6 +2,7 @@
namespace Illuminate\Tests\Validation;
+use Illuminate\Database\Eloquent\Model;
use PHPUnit\Framework\TestCase;
class ValidationUniqueRuleTest extends TestCase
@@ -10,7 +11,7 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
{
$rule = new \Illuminate\Validation\Rules\Unique('table');
$rule->where('foo', 'bar');
- $this->assertEquals('unique:table,NULL,NULL,id,foo,bar', (string) $rule);
+ $this->assertEquals('unique:table,NULL,NULL,NULL,foo,bar', (string) $rule);
$rule = new \Illuminate\Validation\Rules\Unique('table', 'column');
$rule->ignore('Taylor, Otwell', 'id_column');
@@ -21,5 +22,24 @@ public function testItCorrectlyFormatsAStringVersionOfTheRule()
$rule->ignore(null, 'id_column');
$rule->where('foo', 'bar');
$this->assertEquals('unique:table,column,NULL,id_column,foo,bar', (string) $rule);
+
+
+ $model = new EloquentModelStub(['id_column' => 1]);
+
+ $rule = new \Illuminate\Validation\Rules\Unique('table', 'column');
+ $rule->ignore($model);
+ $rule->where('foo', 'bar');
+ $this->assertEquals('unique:table,column,"1",id_column,foo,bar', (string) $rule);
+
+ $rule = new \Illuminate\Validation\Rules\Unique('table', 'column');
+ $rule->ignore($model, 'id_column');
+ $rule->where('foo', 'bar');
+ $this->assertEquals('unique:table,column,"1",id_column,foo,bar', (string) $rule);
}
}
+
+class EloquentModelStub extends Model
+{
+ protected $primaryKey = 'id_column';
+ protected $guarded = [];
+} | true |
Other | laravel | framework | a3889bc48c89baaca8c274fd3f0f561e8799e3f5.json | Remove unused conditional | src/Illuminate/Database/Eloquent/Model.php | @@ -661,7 +661,7 @@ protected function performUpdate(Builder $query)
// First we need to create a fresh query instance and touch the creation and
// update timestamp on the model which are maintained by us for developer
// convenience. Then we will just continue saving the model instances.
- if ($this->usesTimestamps() && $this->shouldTouch()) {
+ if ($this->usesTimestamps()) {
$this->updateTimestamps();
}
| false |
Other | laravel | framework | 9f3b5e822b963433b400f07a1e9db52ae525660f.json | Apply StyleCI Fixes | tests/Database/DatabaseEloquentModelTest.php | @@ -1291,7 +1291,7 @@ public function testModelObserversCanBeAttachedToModelsThroughCallingObserveMeth
$events->shouldReceive('forget');
EloquentModelStub::observe([
'Illuminate\Tests\Database\EloquentTestObserverStub',
- 'Illuminate\Tests\Database\EloquentTestAnotherObserverStub'
+ 'Illuminate\Tests\Database\EloquentTestAnotherObserverStub',
]);
EloquentModelStub::flushEventListeners();
} | false |
Other | laravel | framework | 5403d02c8f479855eeaaeb39935c0effc1b412bb.json | add more test variations | tests/Http/HttpRequestTest.php | @@ -304,6 +304,12 @@ public function testFilledAnyMethod()
$this->assertTrue($request->filledAny(['name']));
$this->assertTrue($request->filledAny('name'));
+ $this->assertFalse($request->filledAny(['age']));
+ $this->assertFalse($request->filledAny('age'));
+
+ $this->assertFalse($request->filledAny(['foo']));
+ $this->assertFalse($request->filledAny('foo'));
+
$this->assertTrue($request->filledAny(['age', 'name']));
$this->assertTrue($request->filledAny('age', 'name'));
@@ -312,6 +318,9 @@ public function testFilledAnyMethod()
$this->assertFalse($request->filledAny('age', 'city'));
$this->assertFalse($request->filledAny('age', 'city'));
+
+ $this->assertFalse($request->filledAny('foo', 'bar'));
+ $this->assertFalse($request->filledAny('foo', 'bar'));
}
public function testInputMethod() | false |
Other | laravel | framework | 4bb96d1f8a415023632064e9ec114ed32fe2ae0d.json | fix doc block | src/Illuminate/Http/Concerns/InteractsWithInput.php | @@ -131,7 +131,7 @@ public function filled($key)
return true;
}
- /**
+ /**
* Determine if the request contains a non-empty value for any of the given inputs.
*
* @param string|array $keys | false |
Other | laravel | framework | 591d2194b731804c438301a82522190c4397581c.json | add new tests | tests/Integration/Database/EloquentFactoryBuilderTest.php | @@ -38,6 +38,32 @@ protected function getEnvironmentSetUp($app)
];
});
+ $factory->define(FactoryBuildableProfile::class, function (Generator $faker) {
+ return [
+ 'user_id' => function () {
+ return factory(FactoryBuildableUser::class)->create()->id;
+ }
+ ];
+ });
+
+ $factory->after(FactoryBuildableUser::class, 'make', function (FactoryBuildableUser $user, Generator $faker) {
+ $profile =factory(FactoryBuildableProfile::class)->make(['user_id' => $user->id]);
+ $user->setRelation('profile', $profile);
+ });
+
+ $factory->define(FactoryBuildableTeam::class, function (Generator $faker) {
+ return [
+ 'name' => $faker->name,
+ 'owner_id' => function () {
+ return factory(FactoryBuildableUser::class)->create()->id;
+ },
+ ];
+ });
+
+ $factory->after(FactoryBuildableTeam::class, function (FactoryBuildableTeam $team, Generator $faker) {
+ $team->users()->attach($team->owner);
+ });
+
$factory->define(FactoryBuildableServer::class, function (Generator $faker) {
return [
'name' => $faker->name,
@@ -72,6 +98,23 @@ public function setUp()
$table->string('email');
});
+ Schema::create('profiles', function ($table) {
+ $table->increments('id');
+ $table->unsignedInteger('user_id');
+ });
+
+ Schema::create('teams', function ($table) {
+ $table->increments('id');
+ $table->string('name');
+ $table->string('owner_id');
+ });
+
+ Schema::create('team_users', function ($table) {
+ $table->increments('id');
+ $table->unsignedInteger('team_id');
+ $table->unsignedInteger('user_id');
+ });
+
Schema::connection('alternative-connection')->create('users', function ($table) {
$table->increments('id');
$table->string('name');
@@ -183,6 +226,14 @@ public function creating_models_on_custom_connection()
$this->assertTrue($user->is($dbUser));
}
+ /** @test **/
+ public function creating_models_with_after_callback()
+ {
+ $team = factory(FactoryBuildableTeam::class)->create();
+
+ $this->assertTrue($team->users->contains($team->owner));
+ }
+
/** @test */
public function making_models_with_a_custom_connection()
{
@@ -192,6 +243,14 @@ public function making_models_with_a_custom_connection()
$this->assertEquals('alternative-connection', $user->getConnectionName());
}
+
+ /** @test **/
+ public function making_models_with_after_callback()
+ {
+ $user = factory(FactoryBuildableUser::class)->make();
+
+ $this->assertNotNull($user->profile);
+ }
}
class FactoryBuildableUser extends Model
@@ -204,6 +263,45 @@ public function servers()
{
return $this->hasMany(FactoryBuildableServer::class, 'user_id');
}
+
+ public function profile()
+ {
+ return $this->hasOne(FactoryBuildableProfile::class, 'user_id');
+ }
+}
+
+class FactoryBuildableProfile extends Model
+{
+ public $table = 'profiles';
+ public $timestamps = false;
+ protected $guarded = ['id'];
+
+ public function user()
+ {
+ return $this->belongsTo(FactoryBuildableUser::class, 'user_id');
+ }
+}
+
+class FactoryBuildableTeam extends Model
+{
+ public $table = 'teams';
+ public $timestamps = false;
+ protected $guarded = ['id'];
+
+ public function owner()
+ {
+ return $this->belongsTo(FactoryBuildableUser::class, 'owner_id');
+ }
+
+ public function users()
+ {
+ return $this->belongsToMany(
+ FactoryBuildableUser::class,
+ 'team_users',
+ 'team_id',
+ 'user_id'
+ );
+ }
}
class FactoryBuildableServer extends Model | false |
Other | laravel | framework | d15cfe3c57e53467445f6ca599091ac13ccd2356.json | fix existing tests | src/Illuminate/Database/Eloquent/FactoryBuilder.php | @@ -193,8 +193,9 @@ public function make(array $attributes = [])
{
if ($this->amount === null) {
$instance = $this->makeInstance($attributes);
+ $this->applyAfter(collect([$instance]), 'make');
- return $this->applyAfter(collect([$instance]), 'make');
+ return $instance;
}
if ($this->amount < 1) {
@@ -204,8 +205,9 @@ public function make(array $attributes = [])
$instances = (new $this->class)->newCollection(array_map(function () use ($attributes) {
return $this->makeInstance($attributes);
}, range(1, $this->amount)));
+ $this->applyAfter($instances, 'make');
- return $this->applyAfter($instances, 'make');
+ return $instances;
}
/**
@@ -346,7 +348,7 @@ protected function expandAttributes(array $attributes)
/**
* Run after callback on a collection of models.
*
- * @param \Illuminate\Support\Collection $results
+ * @param \Illuminate\Support\Collection $models
* @param string $action
* @return void
*/
@@ -359,7 +361,5 @@ public function applyAfter($models, $action)
call_user_func_array($this->after[$this->class][$action], [$model, $this->faker]);
});
-
- return $models;
}
} | false |
Other | laravel | framework | 91ee51fefc510f2ed20701579e9d6b40abaf82d6.json | update doc block | src/Illuminate/Support/Arr.php | @@ -541,7 +541,7 @@ public static function set(&$array, $key, $value)
* Shuffle the given array and return the result.
*
* @param array $array
- * @param int $seed
+ * @param int|null $seed
* @return array
*/
public static function shuffle($array, $seed = null) | false |
Other | laravel | framework | 43851636c4b5bf87ea81f6bfb108bc14db445446.json | add seed to Arr::shuffle() | src/Illuminate/Support/Arr.php | @@ -541,11 +541,20 @@ public static function set(&$array, $key, $value)
* Shuffle the given array and return the result.
*
* @param array $array
+ * @param int $seed
* @return array
*/
- public static function shuffle($array)
+ public static function shuffle($array, $seed = null)
{
- shuffle($array);
+ if (is_null($seed)) {
+ shuffle($array);
+ } else {
+ srand($seed);
+
+ usort($array, function () {
+ return rand(-1, 1);
+ });
+ }
return $array;
} | true |
Other | laravel | framework | 43851636c4b5bf87ea81f6bfb108bc14db445446.json | add seed to Arr::shuffle() | src/Illuminate/Support/Collection.php | @@ -1360,19 +1360,7 @@ public function shift()
*/
public function shuffle($seed = null)
{
- $items = $this->items;
-
- if (is_null($seed)) {
- shuffle($items);
- } else {
- srand($seed);
-
- usort($items, function () {
- return rand(-1, 1);
- });
- }
-
- return new static($items);
+ return new static(Arr::shuffle($this->items, $seed));
}
/** | true |
Other | laravel | framework | 43851636c4b5bf87ea81f6bfb108bc14db445446.json | add seed to Arr::shuffle() | tests/Support/SupportArrTest.php | @@ -498,6 +498,14 @@ public function testSet()
$this->assertEquals(['products' => ['desk' => ['price' => 200]]], $array);
}
+ public function testShuffleWithSeed()
+ {
+ $this->assertEquals(
+ Arr::shuffle(range(0, 100, 10), 1234),
+ Arr::shuffle(range(0, 100, 10), 1234)
+ );
+ }
+
public function testSort()
{
$unsorted = [ | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | composer.json | @@ -110,22 +110,22 @@
"suggest": {
"ext-pcntl": "Required to use all features of the queue worker.",
"ext-posix": "Required to use all features of the queue worker.",
- "aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (~3.0).",
- "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.6).",
- "fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
- "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (~6.0).",
- "laravel/tinker": "Required to use the tinker console command (~1.0).",
- "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).",
- "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).",
- "league/flysystem-cached-adapter": "Required to use Flysystem caching (~1.0).",
- "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (~1.0).",
- "nexmo/client": "Required to use the Nexmo transport (~1.0).",
- "pda/pheanstalk": "Required to use the beanstalk queue driver (~3.0).",
- "predis/predis": "Required to use the redis cache and queue drivers (~1.0).",
- "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~3.0).",
+ "aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (^3.0).",
+ "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
+ "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
+ "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).",
+ "laravel/tinker": "Required to use the tinker console command (^1.0).",
+ "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
+ "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (^1.0).",
+ "league/flysystem-cached-adapter": "Required to use Flysystem caching (^1.0).",
+ "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).",
+ "nexmo/client": "Required to use the Nexmo transport (^1.0).",
+ "pda/pheanstalk": "Required to use the beanstalk queue driver (^3.0).",
+ "predis/predis": "Required to use the redis cache and queue drivers (^1.0).",
+ "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0).",
"symfony/css-selector": "Required to use some of the crawler integration testing tools (^4.1).",
"symfony/dom-crawler": "Required to use most of the crawler integration testing tools (^4.1).",
- "symfony/psr-http-message-bridge": "Required to psr7 bridging features (~1.0)."
+ "symfony/psr-http-message-bridge": "Required to psr7 bridging features (^1.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Broadcasting/composer.json | @@ -32,7 +32,7 @@
}
},
"suggest": {
- "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~3.0)."
+ "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^3.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Console/composer.json | @@ -30,8 +30,8 @@
}
},
"suggest": {
- "dragonmantank/cron-expression": "Required to use scheduling component (~2.0).",
- "guzzlehttp/guzzle": "Required to use the ping methods on schedules (~6.0).",
+ "dragonmantank/cron-expression": "Required to use scheduling component (^2.0).",
+ "guzzlehttp/guzzle": "Required to use the ping methods on schedules (^6.0).",
"symfony/process": "Required to use scheduling component (^4.1)."
},
"config": { | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Database/composer.json | @@ -31,8 +31,8 @@
}
},
"suggest": {
- "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.6).",
- "fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).",
+ "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
+ "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
"illuminate/console": "Required to use the database commands (5.7.*).",
"illuminate/events": "Required to use the observers with Eloquent (5.7.*).",
"illuminate/filesystem": "Required to use the migrations (5.7.*).", | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Filesystem/composer.json | @@ -30,10 +30,10 @@
}
},
"suggest": {
- "league/flysystem": "Required to use the Flysystem local and FTP drivers (~1.0).",
- "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).",
- "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).",
- "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (~1.0)."
+ "league/flysystem": "Required to use the Flysystem local and FTP drivers (^1.0).",
+ "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).",
+ "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (^1.0).",
+ "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Mail/composer.json | @@ -34,8 +34,8 @@
}
},
"suggest": {
- "aws/aws-sdk-php": "Required to use the SES mail driver (~3.0).",
- "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers (~6.0)."
+ "aws/aws-sdk-php": "Required to use the SES mail driver (^3.0).",
+ "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers (^6.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Notifications/composer.json | @@ -36,9 +36,9 @@
}
},
"suggest": {
- "guzzlehttp/guzzle": "Required to use the Slack transport (~6.0)",
+ "guzzlehttp/guzzle": "Required to use the Slack transport (^6.0)",
"illuminate/database": "Required to use the database transport (5.7.*).",
- "nexmo/client": "Required to use the Nexmo transport (~1.0)."
+ "nexmo/client": "Required to use the Nexmo transport (^1.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Queue/composer.json | @@ -37,9 +37,9 @@
"suggest": {
"ext-pcntl": "Required to use all features of the queue worker.",
"ext-posix": "Required to use all features of the queue worker.",
- "aws/aws-sdk-php": "Required to use the SQS queue driver (~3.0).",
+ "aws/aws-sdk-php": "Required to use the SQS queue driver (^3.0).",
"illuminate/redis": "Required to use the Redis queue driver (5.7.*).",
- "pda/pheanstalk": "Required to use the Beanstalk queue driver (~3.0)."
+ "pda/pheanstalk": "Required to use the Beanstalk queue driver (^3.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | c6241441b93113d6c87b83d4e71f7a1d82b2fddc.json | Update suggestion constraints | src/Illuminate/Routing/composer.json | @@ -38,7 +38,7 @@
},
"suggest": {
"illuminate/console": "Required to use the make commands (5.7.*).",
- "symfony/psr-http-message-bridge": "Required to psr7 bridging features (~1.0)."
+ "symfony/psr-http-message-bridge": "Required to psr7 bridging features (^1.0)."
},
"config": {
"sort-packages": true | true |
Other | laravel | framework | 9457b28b470036582a215599b7cb84616a41f297.json | fix broken constraint | src/Illuminate/Support/composer.json | @@ -18,7 +18,7 @@
"ext-mbstring": "*",
"doctrine/inflector": "~1.1",
"illuminate/contracts": "5.5.*",
- "nesbot/carbon": "^1.24.1",
+ "nesbot/carbon": "^1.24.1"
},
"replace": {
"tightenco/collect": "<5.5.33" | false |
Other | laravel | framework | 84cc466c0e78140b15aade306dee6cea3dac5b59.json | Fix style issue | tests/Database/DatabaseEloquentRelationTest.php | @@ -192,7 +192,7 @@ public function testIgnoredModelsStateIsResetWhenThereAreExceptions()
$this->fail('Exception was not thrown');
} catch (\Exception $exception) {
-
+ // Does nothing.
}
$this->assertTrue($related->shouldTouch()); | false |
Other | laravel | framework | fe1cbdf3b51ce1235b8c91f5e603f1e9306e4f6f.json | Add optimize and optimize:clear commands | src/Illuminate/Foundation/Console/OptimizeClearCommand.php | @@ -0,0 +1,37 @@
+<?php
+
+namespace Illuminate\Foundation\Console;
+
+use Illuminate\Console\Command;
+
+class OptimizeClearCommand extends Command
+{
+ /**
+ * The console command name.
+ *
+ * @var string
+ */
+ protected $name = 'optimize:clear';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Clear all caches (routes, config, views, compiled class)';
+
+ /**
+ * Execute the console command.
+ *
+ * @return void
+ */
+ public function handle()
+ {
+ $this->call('cache:clear');
+ $this->call('route:clear');
+ $this->call('view:clear');
+ $this->call('clear-compiled');
+
+ $this->info('Config, routes and view cache cleared successfully!');
+ }
+} | true |
Other | laravel | framework | fe1cbdf3b51ce1235b8c91f5e603f1e9306e4f6f.json | Add optimize and optimize:clear commands | src/Illuminate/Foundation/Console/OptimizeCommand.php | @@ -0,0 +1,37 @@
+<?php
+
+namespace Illuminate\Foundation\Console;
+
+use Illuminate\Console\Command;
+
+class OptimizeCommand extends Command
+{
+ /**
+ * The console command name.
+ *
+ * @var string
+ */
+ protected $name = 'optimize';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Optimize everything (cache routes, config)';
+
+ /**
+ * Execute the console command.
+ *
+ * @return void
+ */
+ public function handle()
+ {
+ $this->call('cache:clear');
+ $this->call('config:cache');
+ $this->call('route:clear');
+ $this->call('route:cache');
+
+ $this->info('Config and routes cached successfully!');
+ }
+} | true |
Other | laravel | framework | fe1cbdf3b51ce1235b8c91f5e603f1e9306e4f6f.json | Add optimize and optimize:clear commands | src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php | @@ -16,6 +16,7 @@
use Illuminate\Foundation\Console\JobMakeCommand;
use Illuminate\Database\Console\Seeds\SeedCommand;
use Illuminate\Foundation\Console\MailMakeCommand;
+use Illuminate\Foundation\Console\OptimizeCommand;
use Illuminate\Foundation\Console\RuleMakeCommand;
use Illuminate\Foundation\Console\TestMakeCommand;
use Illuminate\Foundation\Console\EventMakeCommand;
@@ -43,6 +44,7 @@
use Illuminate\Foundation\Console\ClearCompiledCommand;
use Illuminate\Foundation\Console\EventGenerateCommand;
use Illuminate\Foundation\Console\ExceptionMakeCommand;
+use Illuminate\Foundation\Console\OptimizeClearCommand;
use Illuminate\Foundation\Console\VendorPublishCommand;
use Illuminate\Console\Scheduling\ScheduleFinishCommand;
use Illuminate\Database\Console\Seeds\SeederMakeCommand;
@@ -99,6 +101,8 @@ class ArtisanServiceProvider extends ServiceProvider
'MigrateReset' => 'command.migrate.reset',
'MigrateRollback' => 'command.migrate.rollback',
'MigrateStatus' => 'command.migrate.status',
+ 'Optimize' => 'command.optimize',
+ 'OptimizeClear' => 'command.optimize.clear',
'PackageDiscover' => 'command.package.discover',
'Preset' => 'command.preset',
'QueueFailed' => 'command.queue.failed',
@@ -587,6 +591,30 @@ protected function registerNotificationMakeCommand()
});
}
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerOptimizeCommand()
+ {
+ $this->app->singleton('command.optimize', function ($app) {
+ return new OptimizeCommand;
+ });
+ }
+
+ /**
+ * Register the command.
+ *
+ * @return void
+ */
+ protected function registerOptimizeClearCommand()
+ {
+ $this->app->singleton('command.optimize.clear', function ($app) {
+ return new OptimizeClearCommand;
+ });
+ }
+
/**
* Register the command.
* | true |
Other | laravel | framework | b3a5608ff60a3679d51536a65bb525bdc2390fbc.json | remove set state | src/Illuminate/Support/Carbon.php | @@ -45,15 +45,4 @@ public static function serializeUsing($callback)
{
static::$serializer = $callback;
}
-
- /**
- * Create a new Carbon instance based on the given state array.
- *
- * @param array $array
- * @return static
- */
- public static function __set_state(array $array)
- {
- return static::instance(parent::__set_state($array));
- }
} | false |
Other | laravel | framework | b17f5337affb28802c861e8f8af4fb1d5bec2582.json | fix shaky test | tests/Integration/Http/ThrottleRequestsTest.php | @@ -27,7 +27,7 @@ public function getEnvironmentSetUp($app)
public function test_lock_opens_immediately_after_decay()
{
- Carbon::setTestNow(null);
+ Carbon::setTestNow(Carbon::create(2018, 1, 1, 0, 0, 0));
Route::get('/', function () {
return 'yes';
@@ -43,9 +43,7 @@ public function test_lock_opens_immediately_after_decay()
$this->assertEquals(2, $response->headers->get('X-RateLimit-Limit'));
$this->assertEquals(0, $response->headers->get('X-RateLimit-Remaining'));
- Carbon::setTestNow(
- Carbon::now()->addSeconds(58)
- );
+ Carbon::setTestNow(Carbon::create(2018, 1, 1, 0, 0, 58));
try {
$this->withoutExceptionHandling()->get('/'); | false |
Other | laravel | framework | 0fa361d0e2e111a1a684606a675b414ebd471257.json | add attachFromStorage to mailables | src/Illuminate/Mail/Mailable.php | @@ -15,6 +15,7 @@
use Illuminate\Contracts\Translation\Translator;
use Illuminate\Contracts\Mail\Mailer as MailerContract;
use Illuminate\Contracts\Mail\Mailable as MailableContract;
+use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory;
class Mailable implements MailableContract, Renderable
{
@@ -703,6 +704,38 @@ public function attach($file, array $options = [])
return $this;
}
+ /**
+ * Attach a file to the message from storage.
+ *
+ * @param string $path
+ * @param string $name
+ * @param array $options
+ * @return $this
+ */
+ public function attachFromStorage($path, $name = null, array $options = [])
+ {
+ return $this->attachFromStorageDisk(null, $path, $name, $options);
+ }
+
+ /**
+ * Attach a file to the message from storage.
+ *
+ * @param string $disk
+ * @param string $path
+ * @param string $name
+ * @param array $options
+ * @return $this
+ */
+ public function attachFromStorageDisk($disk, $path, $name = null, array $options = [])
+ {
+ $storage = Container::getInstance()->make(FilesystemFactory::class)->disk($disk);
+
+ return $this->attachData(
+ $storage->get($path), $name ?? basename($path),
+ array_merge(['mime' => $storage->mimeType($path)], $options)
+ );
+ }
+
/**
* Attach in-memory data as an attachment.
* | false |
Other | laravel | framework | ca74f37573b8c223c010414fe1910d4596544db2.json | Drop index before columns | src/Illuminate/Database/Schema/Blueprint.php | @@ -416,11 +416,11 @@ public function dropRememberToken()
*/
public function dropMorphs($name, $indexName = null)
{
- $this->dropColumn("{$name}_type", "{$name}_id");
-
$indexName = $indexName ?: $this->createIndexName('index', ["{$name}_type", "{$name}_id"]);
$this->dropIndex($indexName);
+
+ $this->dropColumn("{$name}_type", "{$name}_id");
}
/** | true |
Other | laravel | framework | ca74f37573b8c223c010414fe1910d4596544db2.json | Drop index before columns | tests/Database/DatabaseMySqlSchemaGrammarTest.php | @@ -265,8 +265,8 @@ public function testDropMorphs()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(2, $statements);
- $this->assertEquals('alter table `photos` drop `imageable_type`, drop `imageable_id`', $statements[0]);
- $this->assertEquals('alter table `photos` drop index `photos_imageable_type_imageable_id_index`', $statements[1]);
+ $this->assertEquals('alter table `photos` drop index `photos_imageable_type_imageable_id_index`', $statements[0]);
+ $this->assertEquals('alter table `photos` drop `imageable_type`, drop `imageable_id`', $statements[1]);
}
public function testRenameTable() | true |
Other | laravel | framework | ca74f37573b8c223c010414fe1910d4596544db2.json | Drop index before columns | tests/Database/DatabasePostgresSchemaGrammarTest.php | @@ -180,8 +180,8 @@ public function testDropMorphs()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(2, $statements);
- $this->assertEquals('alter table "photos" drop column "imageable_type", drop column "imageable_id"', $statements[0]);
- $this->assertEquals('drop index "photos_imageable_type_imageable_id_index"', $statements[1]);
+ $this->assertEquals('drop index "photos_imageable_type_imageable_id_index"', $statements[0]);
+ $this->assertEquals('alter table "photos" drop column "imageable_type", drop column "imageable_id"', $statements[1]);
}
public function testRenameTable() | true |
Other | laravel | framework | ca74f37573b8c223c010414fe1910d4596544db2.json | Drop index before columns | tests/Database/DatabaseSqlServerSchemaGrammarTest.php | @@ -190,8 +190,8 @@ public function testDropMorphs()
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
$this->assertCount(2, $statements);
- $this->assertEquals('alter table "photos" drop column "imageable_type", "imageable_id"', $statements[0]);
- $this->assertEquals('drop index "photos_imageable_type_imageable_id_index" on "photos"', $statements[1]);
+ $this->assertEquals('drop index "photos_imageable_type_imageable_id_index" on "photos"', $statements[0]);
+ $this->assertEquals('alter table "photos" drop column "imageable_type", "imageable_id"', $statements[1]);
}
public function testRenameTable() | true |
Other | laravel | framework | 692f792dc09885ec6191c4aa92ec3859711a3c32.json | Add dropMorphs to Blueprint | src/Illuminate/Database/Schema/Blueprint.php | @@ -407,6 +407,18 @@ public function dropRememberToken()
$this->dropColumn('remember_token');
}
+ /**
+ * Indicate that the polymorphic columns should be dropped.
+ *
+ * @param string $name
+ *
+ * @return void
+ */
+ public function dropMorphs($name)
+ {
+ $this->dropColumn("{$name}_type", "{$name}_id");
+ }
+
/**
* Rename the table to a given name.
* | true |
Other | laravel | framework | 692f792dc09885ec6191c4aa92ec3859711a3c32.json | Add dropMorphs to Blueprint | tests/Database/DatabaseMySqlSchemaGrammarTest.php | @@ -258,6 +258,16 @@ public function testDropTimestampsTz()
$this->assertEquals('alter table `users` drop `created_at`, drop `updated_at`', $statements[0]);
}
+ public function testDropMorphs()
+ {
+ $blueprint = new Blueprint('photos');
+ $blueprint->dropMorphs('imageable');
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table `photos` drop `imageable_type`, drop `imageable_id`', $statements[0]);
+ }
+
public function testRenameTable()
{
$blueprint = new Blueprint('users'); | true |
Other | laravel | framework | 692f792dc09885ec6191c4aa92ec3859711a3c32.json | Add dropMorphs to Blueprint | tests/Database/DatabasePostgresSchemaGrammarTest.php | @@ -173,6 +173,16 @@ public function testDropTimestampsTz()
$this->assertEquals('alter table "users" drop column "created_at", drop column "updated_at"', $statements[0]);
}
+ public function testDropMorphs()
+ {
+ $blueprint = new Blueprint('photos');
+ $blueprint->dropMorphs('imageable');
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "photos" drop column "imageable_type", drop column "imageable_id"', $statements[0]);
+ }
+
public function testRenameTable()
{
$blueprint = new Blueprint('users'); | true |
Other | laravel | framework | 692f792dc09885ec6191c4aa92ec3859711a3c32.json | Add dropMorphs to Blueprint | tests/Database/DatabaseSqlServerSchemaGrammarTest.php | @@ -183,6 +183,16 @@ public function testDropTimestampsTz()
$this->assertEquals('alter table "users" drop column "created_at", "updated_at"', $statements[0]);
}
+ public function testDropMorphs()
+ {
+ $blueprint = new Blueprint('photos');
+ $blueprint->dropMorphs('imageable');
+ $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
+
+ $this->assertCount(1, $statements);
+ $this->assertEquals('alter table "photos" drop column "imageable_type", "imageable_id"', $statements[0]);
+ }
+
public function testRenameTable()
{
$blueprint = new Blueprint('users'); | true |
Other | laravel | framework | 20e84191d5ef21eb5c015908c11eabf8e81d6212.json | regenerate the token on session regeneration | src/Illuminate/Session/Store.php | @@ -475,7 +475,9 @@ public function invalidate()
*/
public function regenerate($destroy = false)
{
- return $this->migrate($destroy);
+ return tap($this->migrate($destroy), function () {
+ $this->regenerateToken();
+ });
}
/** | false |
Other | laravel | framework | a73812999ad2bcb5926cbdd296c723d9635e304c.json | Remove attribute filling from pivot model | src/Illuminate/Database/Eloquent/Relations/Pivot.php | @@ -80,7 +80,7 @@ public static function fromAttributes(Model $parent, $attributes, $table, $exist
*/
public static function fromRawAttributes(Model $parent, $attributes, $table, $exists = false)
{
- $instance = static::fromAttributes($parent, $attributes, $table, $exists);
+ $instance = static::fromAttributes($parent, [], $table, $exists);
$instance->setRawAttributes($attributes, true);
| true |
Other | laravel | framework | a73812999ad2bcb5926cbdd296c723d9635e304c.json | Remove attribute filling from pivot model | tests/Database/DatabaseEloquentPivotTest.php | @@ -37,14 +37,14 @@ public function testMutatorsAreCalledFromConstructor()
$this->assertTrue($pivot->getMutatorCalled());
}
- public function testFromRawAttributesDoesNotDoubleMutate()
+ public function testFromRawAttributesDoesNotMutate()
{
$parent = m::mock('Illuminate\Database\Eloquent\Model[getConnectionName]');
$parent->shouldReceive('getConnectionName')->once()->andReturn('connection');
- $pivot = DatabaseEloquentPivotTestJsonCastStub::fromRawAttributes($parent, ['foo' => json_encode(['name' => 'Taylor'])], 'table', true);
+ $pivot = DatabaseEloquentPivotTestMutatorStub::fromRawAttributes($parent, ['foo' => 'bar'], 'table', true);
- $this->assertEquals(['name' => 'Taylor'], $pivot->foo);
+ $this->assertFalse($pivot->getMutatorCalled());
}
public function testPropertiesUnchangedAreNotDirty()
@@ -135,10 +135,3 @@ public function getMutatorCalled()
return $this->mutatorCalled;
}
}
-
-class DatabaseEloquentPivotTestJsonCastStub extends \Illuminate\Database\Eloquent\Relations\Pivot
-{
- protected $casts = [
- 'foo' => 'json',
- ];
-} | true |
Other | laravel | framework | ab526b7d8fc565314f20c840c7398096b9ec9b94.json | Add dispatchNow to Dispatchable Trait. | src/Illuminate/Foundation/Bus/Dispatchable.php | @@ -2,6 +2,8 @@
namespace Illuminate\Foundation\Bus;
+use Illuminate\Contracts\Bus\Dispatcher;
+
trait Dispatchable
{
/**
@@ -14,6 +16,16 @@ public static function dispatch()
return new PendingDispatch(new static(...func_get_args()));
}
+ /**
+ * Dispatch a command to its appropriate handler in the current process.
+ *
+ * @return mixed
+ */
+ public static function dispatchNow()
+ {
+ return app(Dispatcher::class)->dispatchNow(new static(...func_get_args()));
+ }
+
/**
* Set the jobs that should run if this job is successful.
* | false |
Other | laravel | framework | 557177cbe6241f04e4b1e0e1d4b7633635aa4e2d.json | Provide access to validated dataset | src/Illuminate/Validation/Validator.php | @@ -296,7 +296,7 @@ public function fails()
/**
* Run the validator's rules against its data.
*
- * @return void
+ * @return array
*
* @throws \Illuminate\Validation\ValidationException
*/
@@ -305,6 +305,8 @@ public function validate()
if ($this->fails()) {
throw new ValidationException($this);
}
+
+ return $this->getDataForRules();
}
/**
@@ -725,6 +727,20 @@ public function getData()
return $this->data;
}
+ /**
+ * Get the data under validation only for the loaded rules.
+ *
+ * @return array
+ */
+ public function getDataForRules()
+ {
+ $ruleKeys = collect($this->getRules())->keys()->map(function ($rule) {
+ return explode('.', $rule, 2)[0];
+ })->unique()->toArray();
+
+ return collect($this->getData())->only($ruleKeys)->toArray();
+ }
+
/**
* Set the data under validation.
* | true |
Other | laravel | framework | 557177cbe6241f04e4b1e0e1d4b7633635aa4e2d.json | Provide access to validated dataset | tests/Validation/ValidationValidatorTest.php | @@ -3874,6 +3874,30 @@ public function message()
$this->assertTrue($rule->called);
}
+ public function testGetDataForRules()
+ {
+ $post = ['first'=>'john', 'last'=>'doe', 'type' => 'admin'];
+
+ $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required']);
+ $data = $v->getDataForRules();
+
+ $this->assertSame($data, ['first'=>'john']);
+
+ $v->sometimes('last', 'required', function () {
+ return true;
+ });
+ $data = $v->getDataForRules();
+
+ $this->assertSame($data, ['first'=>'john', 'last'=>'doe']);
+
+ $v->sometimes('type', 'required', function () {
+ return false;
+ });
+ $data = $v->getDataForRules();
+
+ $this->assertSame($data, ['first'=>'john', 'last'=>'doe']);
+ }
+
protected function getTranslator()
{
return m::mock('Illuminate\Contracts\Translation\Translator'); | true |
Other | laravel | framework | d217a2094cf0cbc9ab1a15aeab7c19533e08178c.json | Fix Failing Build (#23386)
Travis CI is failing on "PHP Fatal error: Cannot redeclare Illuminate\Tests\Database\DatabaseQueryBuilderTest::testWhereTimePostgres() in /home/travis/build/laravel/framework/tests/Database/DatabaseQueryBuilderTest.php on line 391"
Looks like a redundant function. | tests/Database/DatabaseQueryBuilderTest.php | @@ -340,14 +340,6 @@ public function testWhereTimeOperatorOptionalMySql()
$this->assertEquals([0 => '22:00'], $builder->getBindings());
}
- public function testWhereTimePostgres()
- {
- $builder = $this->getPostgresBuilder();
- $builder->select('*')->from('users')->whereTime('created_at', '>=', '22:00');
- $this->assertEquals('select * from "users" where "created_at"::time >= ?', $builder->toSql());
- $this->assertEquals([0 => '22:00'], $builder->getBindings());
- }
-
public function testWhereTimeOperatorOptionalPostgres()
{
$builder = $this->getPostgresBuilder(); | false |
Other | laravel | framework | e5763e16cb9170140d2c26697e34bda57b56e62d.json | Add getNextRunDate timezone argument (#23350)
CronExpression getNextRunDate supports a timezone argument to output the datetime in the specified timezone | src/Illuminate/Console/Scheduling/Event.php | @@ -668,7 +668,7 @@ public function nextRunDate($currentTime = 'now', $nth = 0, $allowCurrentDate =
{
return Carbon::instance(CronExpression::factory(
$this->getExpression()
- )->getNextRunDate($currentTime, $nth, $allowCurrentDate));
+ )->getNextRunDate($currentTime, $nth, $allowCurrentDate, $this->timezone));
}
/** | false |
Other | laravel | framework | c71213673fff3a83471ade4535087c77d2d2f4d9.json | Check the instance of the thrown exception | tests/Integration/Http/ThrottleRequestsTest.php | @@ -7,6 +7,7 @@
use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Middleware\ThrottleRequests;
+use Illuminate\Http\Exceptions\ThrottleRequestsException;
/**
* @group integration
@@ -49,6 +50,7 @@ public function test_lock_opens_immediately_after_decay()
try {
$this->withoutExceptionHandling()->get('/');
} catch (Throwable $e) {
+ $this->assertTrue($e instanceof ThrottleRequestsException);
$this->assertEquals(429, $e->getStatusCode());
$this->assertEquals(2, $e->getHeaders()['X-RateLimit-Limit']);
$this->assertEquals(0, $e->getHeaders()['X-RateLimit-Remaining']); | false |
Other | laravel | framework | 816f893c30152e95b14c4ae9d345f53168e5a20e.json | use secure version of parsedown | composer.json | @@ -20,7 +20,7 @@
"ext-openssl": "*",
"doctrine/inflector": "~1.1",
"dragonmantank/cron-expression": "~2.0",
- "erusev/parsedown": "~1.6",
+ "erusev/parsedown": "~1.7",
"league/flysystem": "~1.0",
"monolog/monolog": "~1.12",
"nesbot/carbon": "^1.22.1", | false |
Other | laravel | framework | 5b2923eb8d3dee5ebe65102a4ad2cbbf02b3b40b.json | add test for translator fallback (#23325) | tests/Translation/TranslationTranslatorTest.php | @@ -66,6 +66,16 @@ public function testGetMethodProperlyLoadsAndRetrievesItemWithLongestReplacement
$this->assertEquals('foo', $t->get('foo::bar.foo'));
}
+ public function testGetMethodProperlyLoadsAndRetrievesItemForFallback()
+ {
+ $t = new \Illuminate\Translation\Translator($this->getLoader(), 'en');
+ $t->setFallback('lv');
+ $t->getLoader()->shouldReceive('load')->once()->with('en', 'bar', 'foo')->andReturn([]);
+ $t->getLoader()->shouldReceive('load')->once()->with('lv', 'bar', 'foo')->andReturn(['foo' => 'foo', 'baz' => 'breeze :foo']);
+ $this->assertEquals('breeze bar', $t->get('foo::bar.baz', ['foo' => 'bar'], 'en'));
+ $this->assertEquals('foo', $t->get('foo::bar.foo'));
+ }
+
public function testGetMethodProperlyLoadsAndRetrievesItemForGlobalNamespace()
{
$t = new \Illuminate\Translation\Translator($this->getLoader(), 'en'); | false |
Other | laravel | framework | ebbefd8723125d094a09c940ff27919b9ae9f2d1.json | Apply fixes from StyleCI (#23278) | tests/Integration/Database/EloquentPaginateTest.php | @@ -26,7 +26,7 @@ public function test_pagination_on_top_of_columns()
{
for ($i = 1; $i <= 50; $i++) {
Post::create([
- 'title' => 'Title ' . $i,
+ 'title' => 'Title '.$i,
]);
}
| false |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/Connectors/ConnectionFactory.php | @@ -283,6 +283,6 @@ protected function createConnection($driver, $connection, $database, $prefix = '
return new SqlServerConnection($connection, $database, $prefix, $config);
}
- throw new InvalidArgumentException("Unsupported driver [$driver]");
+ throw new InvalidArgumentException("Unsupported driver [{$driver}]");
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/DatabaseManager.php | @@ -137,7 +137,7 @@ protected function configuration($name)
$connections = $this->app['config']['database.connections'];
if (is_null($config = Arr::get($connections, $name))) {
- throw new InvalidArgumentException("Database [$name] not configured.");
+ throw new InvalidArgumentException("Database [{$name}] not configured.");
}
return $config; | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/Eloquent/Builder.php | @@ -1308,9 +1308,9 @@ public static function __callStatic($method, $parameters)
}
if (! isset(static::$macros[$method])) {
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
if (static::$macros[$method] instanceof Closure) { | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php | @@ -411,7 +411,9 @@ protected function getRelationshipFromMethod($method)
$relation = $this->$method();
if (! $relation instanceof Relation) {
- throw new LogicException(get_class($this).'::'.$method.' must return a relationship instance.');
+ throw new LogicException(sprintf(
+ '%s::%s must return a relationship instance.', static::class, $method
+ ));
}
return tap($relation->getResults(), function ($results) use ($method) { | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/Query/Builder.php | @@ -2519,8 +2519,8 @@ public function __call($method, $parameters)
return $this->dynamicWhere($method, $parameters);
}
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Database/Query/JsonExpression.php | @@ -40,6 +40,6 @@ protected function getJsonBindingParameter($value)
return '?';
}
- throw new InvalidArgumentException('JSON value is of illegal type: '.$type);
+ throw new InvalidArgumentException("JSON value is of illegal type: {$type}");
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Filesystem/FilesystemAdapter.php | @@ -665,7 +665,7 @@ protected function parseVisibility($visibility)
return AdapterInterface::VISIBILITY_PRIVATE;
}
- throw new InvalidArgumentException('Unknown visibility: '.$visibility);
+ throw new InvalidArgumentException("Unknown visibility: {$visibility}");
}
/** | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Http/RedirectResponse.php | @@ -231,8 +231,8 @@ public function __call($method, $parameters)
return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
}
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Mail/Mailable.php | @@ -746,8 +746,8 @@ public function __call($method, $parameters)
return $this->with(Str::snake(substr($method, 4)), $parameters[0]);
}
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Notifications/Channels/BroadcastChannel.php | @@ -70,8 +70,6 @@ protected function getData($notifiable, Notification $notification)
return $notification->toArray($notifiable);
}
- throw new RuntimeException(
- 'Notification is missing toArray method.'
- );
+ throw new RuntimeException('Notification is missing toArray method.');
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Notifications/Channels/DatabaseChannel.php | @@ -44,8 +44,6 @@ protected function getData($notifiable, Notification $notification)
return $notification->toArray($notifiable);
}
- throw new RuntimeException(
- 'Notification is missing toDatabase / toArray method.'
- );
+ throw new RuntimeException('Notification is missing toDatabase / toArray method.');
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Redis/RedisManager.php | @@ -83,9 +83,7 @@ public function resolve($name = null)
return $this->resolveCluster($name);
}
- throw new InvalidArgumentException(
- "Redis connection [{$name}] not configured."
- );
+ throw new InvalidArgumentException("Redis connection [{$name}] not configured.");
}
/** | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Routing/Controller.php | @@ -65,8 +65,8 @@ public function callAction($method, $parameters)
*/
public function __call($method, $parameters)
{
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Routing/Middleware/ThrottleRequests.php | @@ -99,9 +99,7 @@ protected function resolveRequestSignature($request)
return sha1($route->getDomain().'|'.$request->ip());
}
- throw new RuntimeException(
- 'Unable to generate the request signature. Route unavailable.'
- );
+ throw new RuntimeException('Unable to generate the request signature. Route unavailable.');
}
/** | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Routing/RouteRegistrar.php | @@ -175,8 +175,8 @@ public function __call($method, $parameters)
return $this->attribute($method, $parameters[0]);
}
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Support/Manager.php | @@ -57,7 +57,9 @@ public function driver($driver = null)
$driver = $driver ?: $this->getDefaultDriver();
if (is_null($driver)) {
- throw new InvalidArgumentException('Unable to resolve NULL driver for ['.get_class($this).'].');
+ throw new InvalidArgumentException(sprintf(
+ 'Unable to resolve NULL driver for [%s].', static::class
+ ));
}
// If the given driver has not been created before, we will create the instances | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Support/Traits/Macroable.php | @@ -71,9 +71,9 @@ public static function hasMacro($name)
public static function __callStatic($method, $parameters)
{
if (! static::hasMacro($method)) {
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
if (static::$macros[$method] instanceof Closure) {
@@ -95,9 +95,9 @@ public static function __callStatic($method, $parameters)
public function __call($method, $parameters)
{
if (! static::hasMacro($method)) {
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
$macro = static::$macros[$method]; | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/Validation/Validator.php | @@ -1137,8 +1137,8 @@ public function __call($method, $parameters)
return $this->callExtension($rule, $parameters);
}
- $class = static::class;
-
- throw new BadMethodCallException("Method {$class}::{$method} does not exist.");
+ throw new BadMethodCallException(sprintf(
+ 'Method %s::%s does not exist.', static::class, $method
+ ));
}
} | true |
Other | laravel | framework | ba0fa733243fd9b5abac67e40c9a1f7ba2ca0391.json | unify exception formatting (#23266) | src/Illuminate/View/Engines/EngineResolver.php | @@ -54,6 +54,6 @@ public function resolve($engine)
return $this->resolved[$engine] = call_user_func($this->resolvers[$engine]);
}
- throw new InvalidArgumentException("Engine $engine not found.");
+ throw new InvalidArgumentException("Engine [{$engine}] not found.");
}
} | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.