Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] When should return the callback value rather than the conditionable object #44724

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Conditionable/Traits/Conditionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function when($value, callable $callback = null, callable $default = null
}

if ($value) {
return $callback($this, $value) ?? $this;
return $callback($this, $value);
} elseif ($default) {
return $default($this, $value) ?? $this;
return $default($this, $value);
}

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ public function updateQuietly(array $attributes = [], array $options = [])
* @param array $extra
* @return int
*/
protected function incrementQuietly($column, $amount = 1, array $extra = [])
public function incrementQuietly($column, $amount = 1, array $extra = [])
{
return static::withoutEvents(function () use ($column, $amount, $extra) {
return $this->incrementOrDecrement($column, $amount, $extra, 'increment');
Expand All @@ -944,7 +944,7 @@ protected function incrementQuietly($column, $amount = 1, array $extra = [])
* @param array $extra
* @return int
*/
protected function decrementQuietly($column, $amount = 1, array $extra = [])
public function decrementQuietly($column, $amount = 1, array $extra = [])
{
return static::withoutEvents(function () use ($column, $amount, $extra) {
return $this->incrementOrDecrement($column, $amount, $extra, 'decrement');
Expand Down
18 changes: 4 additions & 14 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1783,10 +1783,10 @@ public function testIncrementQuietlyOnExistingModelCallsQueryAndSetsAttributeAnd
$events->shouldReceive('dispatch')->never()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('dispatch')->never()->with('eloquent.saved: '.get_class($model), $model)->andReturn(true);

$model->publicIncrementQuietly('foo', 1);
$model->incrementQuietly('foo', 1);
$this->assertFalse($model->isDirty());

$model->publicIncrementQuietly('foo', 1, ['category' => 1]);
$model->incrementQuietly('foo', 1, ['category' => 1]);
$this->assertEquals(4, $model->foo);
$this->assertEquals(1, $model->category);
$this->assertTrue($model->isDirty('category'));
Expand All @@ -1810,10 +1810,10 @@ public function testDecrementQuietlyOnExistingModelCallsQueryAndSetsAttributeAnd
$events->shouldReceive('dispatch')->never()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
$events->shouldReceive('dispatch')->never()->with('eloquent.saved: '.get_class($model), $model)->andReturn(true);

$model->publicDecrementQuietly('foo', 1);
$model->decrementQuietly('foo', 1);
$this->assertFalse($model->isDirty());

$model->publicDecrementQuietly('foo', 1, ['category' => 1]);
$model->decrementQuietly('foo', 1, ['category' => 1]);
$this->assertEquals(2, $model->foo);
$this->assertEquals(1, $model->category);
$this->assertTrue($model->isDirty('category'));
Expand Down Expand Up @@ -2367,16 +2367,6 @@ public function publicIncrement($column, $amount = 1, $extra = [])
return $this->increment($column, $amount, $extra);
}

public function publicIncrementQuietly($column, $amount = 1, $extra = [])
{
return $this->incrementQuietly($column, $amount, $extra);
}

public function publicDecrementQuietly($column, $amount = 1, $extra = [])
{
return $this->decrementQuietly($column, $amount, $extra);
}

public function belongsToStub()
{
return $this->belongsTo(EloquentModelSaveStub::class);
Expand Down
Loading