1
0
mirror of https://github.com/flarum/core.git synced 2025-07-23 17:51:24 +02:00

fix(core): don't pass null to functions where that's deprecated (#3405)

Should fix remaining PHP 8.1 deprecation warnings/
This commit is contained in:
Alexander Skvortsov
2022-04-24 16:26:18 -04:00
committed by GitHub
parent 290bc19922
commit ffc9f9f5a4
5 changed files with 14 additions and 7 deletions

View File

@@ -60,7 +60,7 @@ class UpdateUserController extends AbstractShowController
// Require the user's current password if they are attempting to change
// their own email address.
if (isset($data['attributes']['email']) && $actor->id == $id) {
$password = Arr::get($request->getParsedBody(), 'meta.password');
$password = (string) Arr::get($request->getParsedBody(), 'meta.password');
if (! $actor->checkPassword($password)) {
throw new NotAuthenticatedException;

View File

@@ -112,7 +112,8 @@ class AccessToken extends AbstractModel
// We truncate user agent so it fits in the database column
// The length is hard-coded as the column length
// It seems like MySQL or Laravel already truncates values, but we'll play safe and do it ourselves
$this->last_user_agent = substr(Arr::get($request->getServerParams(), 'HTTP_USER_AGENT'), 0, 255);
$agent = Arr::get($request->getServerParams(), 'HTTP_USER_AGENT');
$this->last_user_agent = substr($agent ?? '', 0, 255);
} else {
// If no request is provided, we set the values back to null
// That way the values always match with the date logged in last_activity

View File

@@ -55,6 +55,11 @@ class AvatarUploader
{
$avatarPath = $user->getRawOriginal('avatar_url');
// If there was no avatar, there's nothing to remove.
if (! $avatarPath) {
return;
}
$user->afterSave(function () use ($avatarPath) {
if ($this->uploadDir->exists($avatarPath)) {
$this->uploadDir->delete($avatarPath);

View File

@@ -340,7 +340,7 @@ class User extends AbstractModel
* @param string $password
* @return bool
*/
public function checkPassword($password)
public function checkPassword(string $password)
{
$valid = false;
@@ -488,7 +488,7 @@ class User extends AbstractModel
return $value['default'];
}, static::$preferences);
$user = Arr::only((array) json_decode($value, true), array_keys(static::$preferences));
$user = $value !== null ? Arr::only((array) json_decode($value, true), array_keys(static::$preferences)) : [];
return array_merge($defaults, $user);
}

View File

@@ -121,14 +121,15 @@ class UpdateTest extends TestCase
'data' => [
'attributes' => [
'email' => 'someOtherEmail@example.com',
],
'meta' => [
'password' => 'notTheRightPassword!'
]
],
'meta' => [
'password' => 'notTheRightPassword!'
]
],
])
);
$this->assertEquals(401, $response->getStatusCode());
}