Skip to content

Commit

Permalink
Anonymous class CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed May 2, 2021
1 parent eaca1cb commit cee4dae
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ protected function withoutExceptionHandling(array $except = [])
$this->originalExceptionHandler = app(ExceptionHandler::class);
}

$this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler, $except) implements ExceptionHandler {
$this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler, $except) implements ExceptionHandler
{
protected $except;
protected $originalHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public function withoutMiddleware($middleware = null)
}

foreach ((array) $middleware as $abstract) {
$this->app->instance($abstract, new class {
$this->app->instance($abstract, new class
{
public function handle($request, $next)
{
return $next($request);
Expand Down
3 changes: 2 additions & 1 deletion tests/Auth/AuthenticatableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public function testItReturnsStringAsRememberTokenWhenItWasSetToTrue()

public function testItReturnsNullWhenRememberTokenNameWasSetToEmpty()
{
$user = new class extends User {
$user = new class extends User
{
public function getRememberTokenName()
{
return '';
Expand Down
3 changes: 2 additions & 1 deletion tests/Console/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public function testCallingClassCommandResolveCommandViaApplicationResolution()

public function testGettingCommandArgumentsAndOptionsByClass()
{
$command = new class extends Command {
$command = new class extends Command
{
public function handle()
{
}
Expand Down
23 changes: 14 additions & 9 deletions tests/Database/DatabaseEloquentCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,17 +454,22 @@ public function testQueueableCollectionImplementationThrowsExceptionOnMultipleMo
public function testQueueableRelationshipsReturnsOnlyRelationsCommonToAllModels()
{
// This is needed to prevent loading non-existing relationships on polymorphic model collections (#26126)
$c = new Collection([new class {
public function getQueueableRelations()
$c = new Collection([
new class
{
return ['user'];
}
}, new class {
public function getQueueableRelations()
public function getQueueableRelations()
{
return ['user'];
}
},
new class
{
return ['user', 'comments'];
}
}]);
public function getQueueableRelations()
{
return ['user', 'comments'];
}
},
]);

$this->assertEquals(['user'], $c->getQueueableRelations());
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Database/DatabaseSoftDeletingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function testDeletedAtIsAddedToDateCasts()

public function testDeletedAtIsUniqueWhenAlreadyExists()
{
$model = new class extends SoftDeletingModel {
$model = new class extends SoftDeletingModel
{
protected $dates = ['deleted_at'];
};
$entries = array_filter($model->getDates(), function ($attribute) {
Expand All @@ -40,7 +41,8 @@ public function testDeletedAtIsCastToCarbonInstance()

public function testExistingCastOverridesAddedDateCast()
{
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel {
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel
{
protected $casts = ['deleted_at' => 'bool'];
};

Expand All @@ -49,7 +51,8 @@ public function testExistingCastOverridesAddedDateCast()

public function testExistingMutatorOverridesAddedDateCast()
{
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel {
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel
{
protected function getDeletedAtAttribute()
{
return 'expected';
Expand All @@ -61,7 +64,8 @@ protected function getDeletedAtAttribute()

public function testCastingToStringOverridesAutomaticDateCastingToRetainPreviousBehaviour()
{
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel {
$model = new class(['deleted_at' => '2018-12-29 13:59:39']) extends SoftDeletingModel
{
protected $casts = ['deleted_at' => 'string'];
};

Expand Down
6 changes: 4 additions & 2 deletions tests/Foundation/FoundationApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public function testServiceProvidersAreCorrectlyRegistered()
public function testClassesAreBoundWhenServiceProviderIsRegistered()
{
$app = new Application;
$app->register($provider = new class($app) extends ServiceProvider {
$app->register($provider = new class($app) extends ServiceProvider
{
public $bindings = [
AbstractClass::class => ConcreteClass::class,
];
Expand All @@ -62,7 +63,8 @@ public function testClassesAreBoundWhenServiceProviderIsRegistered()
public function testSingletonsAreCreatedWhenServiceProviderIsRegistered()
{
$app = new Application;
$app->register($provider = new class($app) extends ServiceProvider {
$app->register($provider = new class($app) extends ServiceProvider
{
public $singletons = [
AbstractClass::class => ConcreteClass::class,
];
Expand Down
3 changes: 2 additions & 1 deletion tests/Foundation/FoundationTestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function testAssertViewHas()

public function testAssertViewHasModel()
{
$model = new class extends Model {
$model = new class extends Model
{
public function is($model)
{
return $this == $model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public function testApplicationAllowsSomeURIs()
{
$app = $this->createMaintenanceApplication();

$middleware = new class($app) extends CheckForMaintenanceMode {
$middleware = new class($app) extends CheckForMaintenanceMode
{
public function __construct($app)
{
parent::__construct($app);
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Foundation/FoundationHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function testRescue()
return 'no need to rescue';
}, 'rescued!'), 'no need to rescue');

$testClass = new class {
$testClass = new class
{
public function test(int $a)
{
return $a;
Expand Down
27 changes: 18 additions & 9 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,8 @@ public function testKeysArePreservedInAnAnonymousColletionIfTheResourceIsFlagged

public function testLeadingMergeKeyedValueIsMergedCorrectly()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -811,7 +812,8 @@ public function work()

public function testLeadingMergeKeyedValueIsMergedCorrectlyWhenFirstValueIsMissing()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -835,7 +837,8 @@ public function work()

public function testLeadingMergeValueIsMergedCorrectly()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -860,7 +863,8 @@ public function work()

public function testMergeValuesMayBeMissing()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -885,7 +889,8 @@ public function work()

public function testInitialMergeValuesMayBeMissing()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -910,7 +915,8 @@ public function work()

public function testMergeValueCanMergeJsonSerializable()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand Down Expand Up @@ -941,7 +947,8 @@ public function work()

public function testMergeValueCanMergeCollectionOfJsonSerializable()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -967,7 +974,8 @@ public function work()

public function testAllMergeValuesMayBeMissing()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand All @@ -992,7 +1000,8 @@ public function work()

public function testNestedMerges()
{
$filter = new class {
$filter = new class
{
use ConditionallyLoadsAttributes;

public function work()
Expand Down
3 changes: 2 additions & 1 deletion tests/Integration/Queue/CallQueuedHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public function handle()
public function middleware()
{
return [
new class {
new class
{
public function handle($command, $next)
{
CallQueuedHandlerTestJobWithMiddleware::$middlewareCommand = $command;
Expand Down
3 changes: 2 additions & 1 deletion tests/Pagination/PaginatorLoadMorphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public function testCollectionLoadMorphCanChainOnThePaginator()
$items = m::mock(Collection::class);
$items->shouldReceive('loadMorph')->once()->with('parentable', $relations);

$p = (new class extends AbstractPaginator {
$p = (new class extends AbstractPaginator
{
//
})->setCollection($items);

Expand Down
6 changes: 4 additions & 2 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,17 @@ public function testHigherOrderUnique($collection)
public function testHigherOrderFilter($collection)
{
$c = new $collection([
new class {
new class
{
public $name = 'Alex';

public function active()
{
return true;
}
},
new class {
new class
{
public $name = 'John';

public function active()
Expand Down
9 changes: 6 additions & 3 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ public function testOptional()
{
$this->assertNull(optional(null)->something());

$this->assertEquals(10, optional(new class {
$this->assertEquals(10, optional(new class
{
public function something()
{
return 10;
Expand Down Expand Up @@ -463,10 +464,12 @@ public function testOptionalIsMacroable()

$this->assertNull(optional(null)->present()->something());

$this->assertSame('$10.00', optional(new class {
$this->assertSame('$10.00', optional(new class
{
public function present()
{
return new class {
return new class
{
public function something()
{
return '$10.00';
Expand Down
24 changes: 16 additions & 8 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2403,7 +2403,8 @@ public function testValidateEmail()
$this->assertFalse($v->passes());

$v = new Validator($trans, [
'x' => new class {
'x' => new class
{
public function __toString()
{
return 'aslsdlks';
Expand All @@ -2413,7 +2414,8 @@ public function __toString()
$this->assertFalse($v->passes());

$v = new Validator($trans, [
'x' => new class {
'x' => new class
{
public function __toString()
{
return '[email protected]';
Expand Down Expand Up @@ -4792,7 +4794,8 @@ public function testCustomValidationObject()
$this->getIlluminateArrayTranslator(),
['name' => 'taylor'],
[
'name' => new class implements Rule {
'name' => new class implements Rule
{
public function passes($attribute, $value)
{
return $value === 'taylor';
Expand All @@ -4814,7 +4817,8 @@ public function message()
['name' => 'adam'],
[
'name' => [
new class implements Rule {
new class implements Rule
{
public function passes($attribute, $value)
{
return $value === 'taylor';
Expand Down Expand Up @@ -4868,7 +4872,8 @@ public function message()
$this->getIlluminateArrayTranslator(),
['name' => 'taylor', 'states' => ['AR', 'TX'], 'number' => 9],
[
'states.*' => new class implements Rule {
'states.*' => new class implements Rule
{
public function passes($attribute, $value)
{
return in_array($value, ['AK', 'HI']);
Expand Down Expand Up @@ -4906,7 +4911,8 @@ function ($attribute, $value, $fail) {
$this->getIlluminateArrayTranslator(),
['name' => 42],
[
'name' => new class implements Rule {
'name' => new class implements Rule
{
public function passes($attribute, $value)
{
return $value === 'taylor';
Expand All @@ -4930,7 +4936,8 @@ public function message()
['name' => 42],
[
'name' => [
new class implements Rule {
new class implements Rule
{
public function passes($attribute, $value)
{
return $value === 'taylor';
Expand Down Expand Up @@ -4958,7 +4965,8 @@ public function testImplicitCustomValidationObjects()
$this->getIlluminateArrayTranslator(),
['name' => ''],
[
'name' => $rule = new class implements ImplicitRule {
'name' => $rule = new class implements ImplicitRule
{
public $called = false;

public function passes($attribute, $value)
Expand Down
Loading

0 comments on commit cee4dae

Please sign in to comment.