Skip to content

Commit 8bee6ad

Browse files
lucasmichotLucas Michot
andauthored
[13.x] Enforce static calls (laravel#59704)
* Enfoce static calls * StyleCI fix --------- Co-authored-by: Lucas Michot <lucas@zaiple.com>
1 parent 8cb59f7 commit 8bee6ad

16 files changed

Lines changed: 278 additions & 278 deletions

File tree

src/Illuminate/Bus/UniqueLock.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function acquire($job)
4343
? ($job->uniqueVia() ?? $this->cache)
4444
: $this->cache;
4545

46-
return (bool) $cache->lock($this->getKey($job), $uniqueFor)->get();
46+
return (bool) $cache->lock(self::getKey($job), $uniqueFor)->get();
4747
}
4848

4949
/**
@@ -58,7 +58,7 @@ public function release($job)
5858
? ($job->uniqueVia() ?? $this->cache)
5959
: $this->cache;
6060

61-
$cache->lock($this->getKey($job))->forceRelease();
61+
$cache->lock(self::getKey($job))->forceRelease();
6262
}
6363

6464
/**

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public function mutexName()
827827
}
828828

829829
return 'framework'.DIRECTORY_SEPARATOR.'schedule-'.
830-
sha1($this->expression.$this->normalizeCommand($this->command ?? ''));
830+
sha1($this->expression.self::normalizeCommand($this->command ?? ''));
831831
}
832832

833833
/**

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public function fillForInsert(array $values)
529529
$values = [$values];
530530
}
531531

532-
$this->model->unguarded(function () use (&$values) {
532+
$this->model::unguarded(function () use (&$values) {
533533
foreach ($values as $key => $rowValues) {
534534
$values[$key] = tap(
535535
$this->newModelInstance($rowValues),
@@ -1244,7 +1244,7 @@ public function createQuietly(array $attributes = [])
12441244
*/
12451245
public function forceCreate(array $attributes)
12461246
{
1247-
return $this->model->unguarded(function () use ($attributes) {
1247+
return $this->model::unguarded(function () use ($attributes) {
12481248
return $this->newModelInstance()->create($attributes);
12491249
});
12501250
}

src/Illuminate/Database/Eloquent/SoftDeletes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static function forceDestroy($ids)
104104

105105
$count = 0;
106106

107-
foreach ($instance->withTrashed()->whereIn($key, $ids)->get() as $model) {
107+
foreach ($instance::withTrashed()->whereIn($key, $ids)->get() as $model) {
108108
if ($model->forceDelete()) {
109109
$count++;
110110
}

src/Illuminate/Foundation/Console/ChannelListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function forCli($channels)
7878
return mb_strlen($channelName);
7979
});
8080

81-
$terminalWidth = $this->getTerminalWidth();
81+
$terminalWidth = self::getTerminalWidth();
8282

8383
$channelCount = $this->determineChannelCountOutput($channels, $terminalWidth);
8484

src/Illuminate/Foundation/Console/RouteListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ protected function forCli($routes)
399399

400400
$maxMethod = mb_strlen($routes->max('method'));
401401

402-
$terminalWidth = $this->getTerminalWidth();
402+
$terminalWidth = self::getTerminalWidth();
403403

404404
$routeCount = $this->determineRouteCountOutput($routes, $terminalWidth);
405405

src/Illuminate/Http/Concerns/InteractsWithContentTypes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function accepts($contentTypes)
8080

8181
$type = strtolower($type);
8282

83-
if ($this->matchesType($accept, $type) || $accept === strtok($type, '/').'/*') {
83+
if (self::matchesType($accept, $type) || $accept === strtok($type, '/').'/*') {
8484
return true;
8585
}
8686
}
@@ -121,7 +121,7 @@ public function prefers($contentTypes)
121121

122122
$type = strtolower($type);
123123

124-
if ($this->matchesType($type, $accept) || $accept === strtok($type, '/').'/*') {
124+
if (self::matchesType($type, $accept) || $accept === strtok($type, '/').'/*') {
125125
return $contentType;
126126
}
127127
}

tests/Database/DatabaseEloquentModelTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ public function testUpdateProcess()
821821
$query->shouldReceive('update')->once()->with(['name' => 'taylor'])->andReturn(1);
822822
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
823823
$model->expects($this->once())->method('updateTimestamps');
824-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
824+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
825825
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
826826
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(true);
827827
$events->shouldReceive('dispatch')->once()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
@@ -843,7 +843,7 @@ public function testUpdateProcessDoesntOverrideTimestamps()
843843
$query->shouldReceive('where')->once()->with('id', '=', 1);
844844
$query->shouldReceive('update')->once()->with(['created_at' => 'foo', 'updated_at' => 'bar'])->andReturn(1);
845845
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
846-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
846+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
847847
$events->shouldReceive('until');
848848
$events->shouldReceive('dispatch');
849849

@@ -860,7 +860,7 @@ public function testSaveIsCanceledIfSavingEventReturnsFalse()
860860
$model = $this->getMockBuilder(EloquentModelStub::class)->onlyMethods(['newModelQuery'])->getMock();
861861
$query = m::mock(Builder::class);
862862
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
863-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
863+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
864864
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(false);
865865
$model->exists = true;
866866

@@ -872,7 +872,7 @@ public function testUpdateIsCanceledIfUpdatingEventReturnsFalse()
872872
$model = $this->getMockBuilder(EloquentModelStub::class)->onlyMethods(['newModelQuery'])->getMock();
873873
$query = m::mock(Builder::class);
874874
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
875-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
875+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
876876
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
877877
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(false);
878878
$model->exists = true;
@@ -886,7 +886,7 @@ public function testEventsCanBeFiredWithCustomEventObjects()
886886
$model = $this->getMockBuilder(EloquentModelEventObjectStub::class)->onlyMethods(['newModelQuery'])->getMock();
887887
$query = m::mock(Builder::class);
888888
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
889-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
889+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
890890
$events->shouldReceive('until')->once()->with(m::type(EloquentModelSavingEventStub::class))->andReturn(false);
891891
$model->exists = true;
892892

@@ -919,7 +919,7 @@ public function testUpdateUsesOldPrimaryKey()
919919
$query->shouldReceive('update')->once()->with(['id' => 2, 'foo' => 'bar'])->andReturn(1);
920920
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
921921
$model->expects($this->once())->method('updateTimestamps');
922-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
922+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
923923
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
924924
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(true);
925925
$events->shouldReceive('dispatch')->once()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
@@ -1065,7 +1065,7 @@ public function testInsertProcess()
10651065
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
10661066
$model->expects($this->once())->method('updateTimestamps');
10671067

1068-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1068+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
10691069
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
10701070
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
10711071
$events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($model), $model);
@@ -1085,7 +1085,7 @@ public function testInsertProcess()
10851085
$model->expects($this->once())->method('updateTimestamps');
10861086
$model->setIncrementing(false);
10871087

1088-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1088+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
10891089
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
10901090
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
10911091
$events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($model), $model);
@@ -1104,7 +1104,7 @@ public function testInsertIsCanceledIfCreatingEventReturnsFalse()
11041104
$query = m::mock(Builder::class);
11051105
$query->shouldReceive('getConnection')->once();
11061106
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
1107-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1107+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
11081108
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
11091109
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(false);
11101110

@@ -1123,7 +1123,7 @@ public function testInsertOrIgnoreProcessWithIncrementing()
11231123
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
11241124
$model->expects($this->once())->method('updateTimestamps');
11251125

1126-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1126+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
11271127
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
11281128
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
11291129
$events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($model), $model);
@@ -1148,7 +1148,7 @@ public function testInsertOrIgnoreProcessWithConflict()
11481148
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
11491149
$model->expects($this->once())->method('updateTimestamps');
11501150

1151-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1151+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
11521152
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
11531153
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
11541154

@@ -1171,7 +1171,7 @@ public function testInsertOrIgnoreProcessWithNonIncrementing()
11711171
$model->expects($this->once())->method('updateTimestamps');
11721172
$model->setIncrementing(false);
11731173

1174-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1174+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
11751175
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
11761176
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
11771177
$events->shouldReceive('dispatch')->once()->with('eloquent.created: '.get_class($model), $model);
@@ -1196,7 +1196,7 @@ public function testInsertOrIgnoreProcessWithNamedUnique()
11961196
$model->expects($this->once())->method('newModelQuery')->willReturn($query);
11971197
$model->expects($this->once())->method('updateTimestamps');
11981198

1199-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
1199+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
12001200
$events->shouldReceive('until')->once()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
12011201
$events->shouldReceive('until')->once()->with('eloquent.creating: '.get_class($model), $model)->andReturn(true);
12021202

@@ -2638,7 +2638,7 @@ public function testReplicatingEventIsFiredWhenReplicatingModel()
26382638
{
26392639
$model = new EloquentModelStub;
26402640

2641-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2641+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
26422642
$events->shouldReceive('dispatch')->once()->with('eloquent.replicating: '.get_class($model), m::on(function ($m) use ($model) {
26432643
return $model->is($m);
26442644
}));
@@ -2655,7 +2655,7 @@ public function testReplicateQuietlyCreatesANewModelInstanceWithSameAttributeVal
26552655
$model->updated_at = new DateTime;
26562656
$replicated = $model->replicateQuietly();
26572657

2658-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2658+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
26592659
$events->shouldReceive('dispatch')->never()->with('eloquent.replicating: '.get_class($model), $model)->andReturn(true);
26602660

26612661
$this->assertNull($replicated->id);
@@ -2698,7 +2698,7 @@ public function testIncrementQuietlyOnExistingModelCallsQueryAndSetsAttributeAnd
26982698
$query->shouldReceive('where')->andReturn($query);
26992699
$query->shouldReceive('increment');
27002700

2701-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2701+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
27022702
$events->shouldReceive('until')->never()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
27032703
$events->shouldReceive('until')->never()->with('eloquent.updating: '.get_class($model), $model)->andReturn(true);
27042704
$events->shouldReceive('dispatch')->never()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
@@ -2725,7 +2725,7 @@ public function testDecrementQuietlyOnExistingModelCallsQueryAndSetsAttributeAnd
27252725
$query->shouldReceive('where')->andReturn($query);
27262726
$query->shouldReceive('decrement');
27272727

2728-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2728+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
27292729
$events->shouldReceive('until')->never()->with('eloquent.saving: '.get_class($model), $model)->andReturn(true);
27302730
$events->shouldReceive('until')->never()->with('eloquent.updating: '.get_class($model), $model)->andReturn(true);
27312731
$events->shouldReceive('dispatch')->never()->with('eloquent.updated: '.get_class($model), $model)->andReturn(true);
@@ -2811,7 +2811,7 @@ public function testIncrementEachFiresModelEvents()
28112811
$query->shouldReceive('where')->andReturn($query);
28122812
$query->shouldReceive('incrementEach')->andReturn(1);
28132813

2814-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2814+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
28152815
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(true);
28162816
$events->shouldReceive('dispatch')->once()->with('eloquent.updated: '.get_class($model), $model);
28172817

@@ -2828,7 +2828,7 @@ public function testIncrementEachReturnsFalseWhenUpdatingEventCancelled()
28282828

28292829
$model->shouldReceive('newQueryWithoutScopes')->never();
28302830

2831-
$model->setEventDispatcher($events = m::mock(Dispatcher::class));
2831+
$model::setEventDispatcher($events = m::mock(Dispatcher::class));
28322832
$events->shouldReceive('until')->once()->with('eloquent.updating: '.get_class($model), $model)->andReturn(false);
28332833

28342834
$result = $model->publicIncrementEach(['foo' => 1]);

0 commit comments

Comments
 (0)