mirror of
https://github.com/flarum/core.git
synced 2025-08-11 02:44:04 +02:00
chore: update codebase to php8.1 (#3827)
* chore: set minimum php version to 8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: update codebase to php8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: update workflow php version Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: more caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: phpstan caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: introduce `Flarum\Locale\TranslatorInterface` Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: remove mixin Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: one last error Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -14,11 +14,6 @@ use Flarum\User\User;
|
||||
|
||||
class UserPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @param User $actor
|
||||
* @param User $user
|
||||
* @return bool|null
|
||||
*/
|
||||
public function suspend(User $actor, User $user)
|
||||
{
|
||||
if ($user->isAdmin() || $user->id === $actor->id) {
|
||||
|
@@ -14,7 +14,7 @@ use Flarum\User\User;
|
||||
|
||||
class AddUserSuspendAttributes
|
||||
{
|
||||
public function __invoke(UserSerializer $serializer, User $user)
|
||||
public function __invoke(UserSerializer $serializer, User $user): array
|
||||
{
|
||||
$attributes = [];
|
||||
$canSuspend = $serializer->getActor()->can('suspend', $user);
|
||||
|
@@ -13,18 +13,9 @@ use Flarum\User\User;
|
||||
|
||||
class Suspended
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
public function __construct(User $user, User $actor)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public User $user,
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -13,18 +13,9 @@ use Flarum\User\User;
|
||||
|
||||
class Unsuspended
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
public function __construct(User $user, User $actor)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public User $user,
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -20,29 +20,13 @@ use Illuminate\Support\Arr;
|
||||
|
||||
class SaveSuspensionToDatabase
|
||||
{
|
||||
/**
|
||||
* Validator for limited suspension.
|
||||
*
|
||||
* @var SuspendValidator
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @param SuspendValidator $validator
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(SuspendValidator $validator, Dispatcher $events)
|
||||
{
|
||||
$this->validator = $validator;
|
||||
$this->events = $events;
|
||||
public function __construct(
|
||||
protected SuspendValidator $validator,
|
||||
protected Dispatcher $events
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Saving $event)
|
||||
public function handle(Saving $event): void
|
||||
{
|
||||
$attributes = Arr::get($event->data, 'attributes', []);
|
||||
|
||||
|
@@ -15,20 +15,12 @@ use Flarum\Suspend\Notification\UserSuspendedBlueprint;
|
||||
|
||||
class SendNotificationWhenUserIsSuspended
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Suspended $event)
|
||||
public function handle(Suspended $event): void
|
||||
{
|
||||
$this->notifications->sync(
|
||||
new UserSuspendedBlueprint($event->user),
|
||||
|
@@ -15,20 +15,12 @@ use Flarum\Suspend\Notification\UserUnsuspendedBlueprint;
|
||||
|
||||
class SendNotificationWhenUserIsUnsuspended
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Unsuspended $event)
|
||||
public function handle(Unsuspended $event): void
|
||||
{
|
||||
$this->notifications->sync(
|
||||
new UserUnsuspendedBlueprint($event->user),
|
||||
|
@@ -9,78 +9,51 @@
|
||||
|
||||
namespace Flarum\Suspend\Notification;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\User\User;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UserSuspendedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): CarbonInterface
|
||||
{
|
||||
return $this->user->suspended_until;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'userSuspended';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return User::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-suspend::emails.suspended'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-suspend.email.suspended.subject');
|
||||
}
|
||||
|
@@ -9,79 +9,52 @@
|
||||
|
||||
namespace Flarum\Suspend\Notification;
|
||||
|
||||
use Carbon\CarbonInterface;
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UserUnsuspendedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): CarbonInterface
|
||||
{
|
||||
return Carbon::now();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'userUnsuspended';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return User::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-suspend::emails.unsuspended'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-suspend.email.unsuspended.subject');
|
||||
}
|
||||
|
@@ -20,28 +20,17 @@ use Illuminate\Database\Query\Builder;
|
||||
|
||||
class SuspendedFilterGambit extends AbstractRegexGambit implements FilterInterface
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\User\UserRepository
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @param \Flarum\User\UserRepository $users
|
||||
*/
|
||||
public function __construct(UserRepository $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
public function __construct(
|
||||
protected UserRepository $users
|
||||
) {
|
||||
}
|
||||
|
||||
protected function getGambitPattern()
|
||||
protected function getGambitPattern(): string
|
||||
{
|
||||
return 'is:suspended';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(SearchState $search, $bit)
|
||||
public function apply(SearchState $search, string $bit): bool
|
||||
{
|
||||
if (! $search->getActor()->can('suspend', new Guest())) {
|
||||
return false;
|
||||
@@ -50,10 +39,7 @@ class SuspendedFilterGambit extends AbstractRegexGambit implements FilterInterfa
|
||||
return parent::apply($search, $bit);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function conditions(SearchState $search, array $matches, $negate)
|
||||
protected function conditions(SearchState $search, array $matches, bool $negate): void
|
||||
{
|
||||
$this->constrain($search->getQuery(), $negate);
|
||||
}
|
||||
@@ -63,16 +49,16 @@ class SuspendedFilterGambit extends AbstractRegexGambit implements FilterInterfa
|
||||
return 'suspended';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
if (! $filterState->getActor()->can('suspend', new Guest())) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->constrain($filterState->getQuery(), $negate);
|
||||
}
|
||||
|
||||
protected function constrain(Builder $query, bool $negate)
|
||||
protected function constrain(Builder $query, bool $negate): void
|
||||
{
|
||||
$query->where(function ($query) use ($negate) {
|
||||
if ($negate) {
|
||||
|
@@ -15,11 +15,7 @@ use Flarum\User\User;
|
||||
|
||||
class RevokeAccessFromSuspendedUsers
|
||||
{
|
||||
/**
|
||||
* @param User $user
|
||||
* @param array $groupIds
|
||||
*/
|
||||
public function __invoke(User $user, array $groupIds)
|
||||
public function __invoke(User $user, array $groupIds): array
|
||||
{
|
||||
$suspendedUntil = $user->suspended_until;
|
||||
|
||||
|
@@ -13,10 +13,7 @@ use Flarum\Foundation\AbstractValidator;
|
||||
|
||||
class SuspendValidator extends AbstractValidator
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $rules = [
|
||||
protected array $rules = [
|
||||
'suspendedUntil' => ['nullable', 'date'],
|
||||
];
|
||||
}
|
||||
|
Reference in New Issue
Block a user