Skip to content

Commit 8765ffe

Browse files
authored
[8.x] Fixes for PHP 8.1 (#37101)
* fix PHP 8.1 deprecations (broadcasting) * fix PHP 8.1 deprecations (cache) * remove returns after never-return method call * fix PHP 8.1 deprecations (bus) * fix PHP 8.1 deprecations (database) * fix PHP 8.1 deprecations (validation) * use strict comparison * fix PHP 8.1 deprecations (mail) * fix PHP 8.1 deprecations (routing)
1 parent a011109 commit 8765ffe

File tree

11 files changed

+36
-25
lines changed

11 files changed

+36
-25
lines changed

src/Illuminate/Broadcasting/Broadcasters/RedisBroadcaster.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class RedisBroadcaster extends Broadcaster
2020
/**
2121
* The Redis connection to use for broadcasting.
2222
*
23-
* @var string
23+
* @var ?string
2424
*/
25-
protected $connection;
25+
protected $connection = null;
2626

2727
/**
2828
* The Redis key prefix.
2929
*
3030
* @var string
3131
*/
32-
protected $prefix;
32+
protected $prefix = '';
3333

3434
/**
3535
* Create a new broadcaster instance.

src/Illuminate/Cache/Console/ClearCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected function cache()
116116
*/
117117
protected function tags()
118118
{
119-
return array_filter(explode(',', $this->option('tags')));
119+
return array_filter(explode(',', $this->option('tags') ?? ''));
120120
}
121121

122122
/**

src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ public function setUpRedis()
3636

3737
if (! extension_loaded('redis')) {
3838
$this->markTestSkipped('The redis extension is not installed. Please install the extension to enable '.__CLASS__);
39-
40-
return;
4139
}
4240

4341
if (static::$connectionFailedOnceWithDefaultsSkip) {
4442
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
45-
46-
return;
4743
}
4844

4945
foreach ($this->redisDriverProvider() as $driver) {

src/Illuminate/Mail/MailManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function createTransport(array $config)
168168
return call_user_func($this->customCreators[$transport], $config);
169169
}
170170

171-
if (trim($transport) === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
171+
if (trim($transport ?? '') === '' || ! method_exists($this, $method = 'create'.ucfirst($transport).'Transport')) {
172172
throw new InvalidArgumentException("Unsupported mail transport [{$transport}].");
173173
}
174174

src/Illuminate/Routing/AbstractRouteCollection.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ protected function addToSymfonyRoutesCollection(SymfonyRouteCollection $symfonyR
199199
{
200200
$name = $route->getName();
201201

202-
if (Str::endsWith($name, '.') &&
203-
! is_null($symfonyRoutes->get($name))) {
202+
if (
203+
! is_null($name)
204+
&& Str::endsWith($name, '.')
205+
&& ! is_null($symfonyRoutes->get($name))
206+
) {
204207
$name = null;
205208
}
206209

src/Illuminate/Validation/Concerns/FormatsMessages.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function getMessage($attribute, $rule)
5454
// messages out of the translator service for this validation rule.
5555
$key = "validation.{$lowerRule}";
5656

57-
if ($key != ($value = $this->translator->get($key))) {
57+
if ($key !== ($value = $this->translator->get($key))) {
5858
return $value;
5959
}
6060

src/Illuminate/Validation/Concerns/ReplacesAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function replaceMax($message, $attribute, $rule, $parameters)
115115
*/
116116
protected function replaceMultipleOf($message, $attribute, $rule, $parameters)
117117
{
118-
return str_replace(':value', $parameters[0], $message);
118+
return str_replace(':value', $parameters[0] ?? '', $message);
119119
}
120120

121121
/**

src/Illuminate/Validation/ValidationRuleParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public static function parse($rule)
214214
*/
215215
protected static function parseArrayRule(array $rule)
216216
{
217-
return [Str::studly(trim(Arr::get($rule, 0))), array_slice($rule, 1)];
217+
return [Str::studly(trim(Arr::get($rule, 0, ''))), array_slice($rule, 1)];
218218
}
219219

220220
/**

tests/Bus/BusBatchTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function test_options_unserialize_on_postgres($serialize, $options)
377377
'failed_jobs' => '',
378378
'failed_job_ids' => '[]',
379379
'options' => $serialize,
380-
'created_at' => null,
380+
'created_at' => now()->timestamp,
381381
'cancelled_at' => null,
382382
'finished_at' => null,
383383
]);

tests/Database/DatabaseMigrationMakeCommandTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public function testBasicCreateDumpsAutoload()
2727
$app = new Application;
2828
$app->useDatabasePath(__DIR__);
2929
$command->setLaravel($app);
30-
$creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true);
30+
$creator->shouldReceive('create')->once()
31+
->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true)
32+
->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php');
3133
$composer->shouldReceive('dumpAutoloads')->once();
3234

3335
$this->runCommand($command, ['name' => 'create_foo']);
@@ -42,7 +44,9 @@ public function testBasicCreateGivesCreatorProperArguments()
4244
$app = new Application;
4345
$app->useDatabasePath(__DIR__);
4446
$command->setLaravel($app);
45-
$creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true);
47+
$creator->shouldReceive('create')->once()
48+
->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true)
49+
->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php');
4650

4751
$this->runCommand($command, ['name' => 'create_foo']);
4852
}
@@ -56,7 +60,9 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenNameIsStudlyCase()
5660
$app = new Application;
5761
$app->useDatabasePath(__DIR__);
5862
$command->setLaravel($app);
59-
$creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true);
63+
$creator->shouldReceive('create')->once()
64+
->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'foo', true)
65+
->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php');
6066

6167
$this->runCommand($command, ['name' => 'CreateFoo']);
6268
}
@@ -70,7 +76,9 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenTableIsSet()
7076
$app = new Application;
7177
$app->useDatabasePath(__DIR__);
7278
$command->setLaravel($app);
73-
$creator->shouldReceive('create')->once()->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true);
79+
$creator->shouldReceive('create')->once()
80+
->with('create_foo', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true)
81+
->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_foo.php');
7482

7583
$this->runCommand($command, ['name' => 'create_foo', '--create' => 'users']);
7684
}
@@ -84,7 +92,9 @@ public function testBasicCreateGivesCreatorProperArgumentsWhenCreateTablePattern
8492
$app = new Application;
8593
$app->useDatabasePath(__DIR__);
8694
$command->setLaravel($app);
87-
$creator->shouldReceive('create')->once()->with('create_users_table', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true);
95+
$creator->shouldReceive('create')->once()
96+
->with('create_users_table', __DIR__.DIRECTORY_SEPARATOR.'migrations', 'users', true)
97+
->andReturn(__DIR__.'/migrations/2021_04_23_110457_create_users_table.php');
8898

8999
$this->runCommand($command, ['name' => 'create_users_table']);
90100
}
@@ -98,7 +108,9 @@ public function testCanSpecifyPathToCreateMigrationsIn()
98108
$app = new Application;
99109
$command->setLaravel($app);
100110
$app->setBasePath('/home/laravel');
101-
$creator->shouldReceive('create')->once()->with('create_foo', '/home/laravel/vendor/laravel-package/migrations', 'users', true);
111+
$creator->shouldReceive('create')->once()
112+
->with('create_foo', '/home/laravel/vendor/laravel-package/migrations', 'users', true)
113+
->andReturn('/home/laravel/vendor/laravel-package/migrations/2021_04_23_110457_create_foo.php');
102114
$this->runCommand($command, ['name' => 'create_foo', '--path' => 'vendor/laravel-package/migrations', '--create' => 'users']);
103115
}
104116

tests/Validation/ValidationValidatorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ public function testValidatePassword()
770770
$container->shouldReceive('make')->with('hash')->andReturn($hasher);
771771

772772
$trans = $this->getTranslator();
773-
$trans->shouldReceive('get');
773+
$trans->shouldReceive('get')->andReturnArg(0);
774774

775775
$v = new Validator($trans, ['password' => 'foo'], ['password' => 'password']);
776776
$v->setContainer($container);
@@ -794,7 +794,7 @@ public function testValidatePassword()
794794
$container->shouldReceive('make')->with('hash')->andReturn($hasher);
795795

796796
$trans = $this->getTranslator();
797-
$trans->shouldReceive('get');
797+
$trans->shouldReceive('get')->andReturnArg(0);
798798

799799
$v = new Validator($trans, ['password' => 'foo'], ['password' => 'password']);
800800
$v->setContainer($container);
@@ -818,7 +818,7 @@ public function testValidatePassword()
818818
$container->shouldReceive('make')->with('hash')->andReturn($hasher);
819819

820820
$trans = $this->getTranslator();
821-
$trans->shouldReceive('get');
821+
$trans->shouldReceive('get')->andReturnArg(0);
822822

823823
$v = new Validator($trans, ['password' => 'foo'], ['password' => 'password']);
824824
$v->setContainer($container);
@@ -842,7 +842,7 @@ public function testValidatePassword()
842842
$container->shouldReceive('make')->with('hash')->andReturn($hasher);
843843

844844
$trans = $this->getTranslator();
845-
$trans->shouldReceive('get');
845+
$trans->shouldReceive('get')->andReturnArg(0);
846846

847847
$v = new Validator($trans, ['password' => 'foo'], ['password' => 'password:custom']);
848848
$v->setContainer($container);

0 commit comments

Comments
 (0)