mirror of
https://github.com/flarum/core.git
synced 2025-08-13 11:54:32 +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:
@@ -15,11 +15,6 @@ use Flarum\User\User;
|
||||
|
||||
class DiscussionPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @param User $actor
|
||||
* @param Discussion $discussion
|
||||
* @return string|void
|
||||
*/
|
||||
public function reply(User $actor, Discussion $discussion)
|
||||
{
|
||||
if ($discussion->is_locked && $actor->cannot('lock', $discussion)) {
|
||||
|
@@ -14,23 +14,9 @@ use Flarum\User\User;
|
||||
|
||||
class DiscussionWasLocked
|
||||
{
|
||||
/**
|
||||
* @var Discussion
|
||||
*/
|
||||
public $discussion;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Discussion $discussion
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Discussion $discussion, User $user)
|
||||
{
|
||||
$this->discussion = $discussion;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Discussion $discussion,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -14,23 +14,9 @@ use Flarum\User\User;
|
||||
|
||||
class DiscussionWasUnlocked
|
||||
{
|
||||
/**
|
||||
* @var Discussion
|
||||
*/
|
||||
public $discussion;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Discussion $discussion
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Discussion $discussion, User $user)
|
||||
{
|
||||
$this->discussion = $discussion;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Discussion $discussion,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -16,17 +16,12 @@ use Flarum\Notification\NotificationSyncer;
|
||||
|
||||
class CreatePostWhenDiscussionIsLocked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(DiscussionWasLocked $event)
|
||||
public function handle(DiscussionWasLocked $event): void
|
||||
{
|
||||
$post = DiscussionLockedPost::reply(
|
||||
$event->discussion->id,
|
||||
|
@@ -16,17 +16,12 @@ use Flarum\Notification\NotificationSyncer;
|
||||
|
||||
class CreatePostWhenDiscussionIsUnlocked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(DiscussionWasUnlocked $event)
|
||||
public function handle(DiscussionWasUnlocked $event): void
|
||||
{
|
||||
$post = DiscussionLockedPost::reply(
|
||||
$event->discussion->id,
|
||||
|
@@ -15,7 +15,7 @@ use Flarum\Lock\Event\DiscussionWasUnlocked;
|
||||
|
||||
class SaveLockedToDatabase
|
||||
{
|
||||
public function handle(Saving $event)
|
||||
public function handle(Saving $event): void
|
||||
{
|
||||
if (isset($event->data['attributes']['isLocked'])) {
|
||||
$isLocked = (bool) $event->data['attributes']['isLocked'];
|
||||
|
@@ -9,61 +9,40 @@
|
||||
|
||||
namespace Flarum\Lock\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Lock\Post\DiscussionLockedPost;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class DiscussionLockedBlueprint implements BlueprintInterface
|
||||
{
|
||||
/**
|
||||
* @var DiscussionLockedPost
|
||||
*/
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* @param DiscussionLockedPost $post
|
||||
*/
|
||||
public function __construct(DiscussionLockedPost $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
protected DiscussionLockedPost $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post->discussion;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): array
|
||||
{
|
||||
return ['postNumber' => (int) $this->post->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'discussionLocked';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Discussion::class;
|
||||
}
|
||||
|
@@ -16,15 +16,9 @@ use Flarum\Post\Post;
|
||||
|
||||
class DiscussionLockedPost extends AbstractEventPost implements MergeableInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $type = 'discussionLocked';
|
||||
public static string $type = 'discussionLocked';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveAfter(Post $previous = null)
|
||||
public function saveAfter(Post $previous = null): static
|
||||
{
|
||||
// If the previous post is another 'discussion locked' post, and it's
|
||||
// by the same user, then we can merge this post into it. If we find
|
||||
@@ -47,15 +41,7 @@ class DiscussionLockedPost extends AbstractEventPost implements MergeableInterfa
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in reply to a discussion.
|
||||
*
|
||||
* @param int $discussionId
|
||||
* @param int $userId
|
||||
* @param bool $isLocked
|
||||
* @return static
|
||||
*/
|
||||
public static function reply($discussionId, $userId, $isLocked)
|
||||
public static function reply(int $discussionId, int $userId, bool $isLocked): static
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
@@ -67,14 +53,8 @@ class DiscussionLockedPost extends AbstractEventPost implements MergeableInterfa
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the content attribute.
|
||||
*
|
||||
* @param bool $isLocked Whether or not the discussion is locked.
|
||||
* @return array
|
||||
*/
|
||||
public static function buildContent($isLocked)
|
||||
public static function buildContent(bool $isLocked): array
|
||||
{
|
||||
return ['locked' => (bool) $isLocked];
|
||||
return ['locked' => $isLocked];
|
||||
}
|
||||
}
|
||||
|
@@ -17,14 +17,14 @@ use Illuminate\Database\Query\Builder;
|
||||
|
||||
class LockedFilterGambit extends AbstractRegexGambit implements FilterInterface
|
||||
{
|
||||
protected function getGambitPattern()
|
||||
protected function getGambitPattern(): string
|
||||
{
|
||||
return 'is:locked';
|
||||
}
|
||||
|
||||
protected function conditions(SearchState $searchState, array $matches, $negate)
|
||||
protected function conditions(SearchState $search, array $matches, bool $negate): void
|
||||
{
|
||||
$this->constrain($searchState->getQuery(), $negate);
|
||||
$this->constrain($search->getQuery(), $negate);
|
||||
}
|
||||
|
||||
public function getFilterKey(): string
|
||||
@@ -32,12 +32,12 @@ class LockedFilterGambit extends AbstractRegexGambit implements FilterInterface
|
||||
return 'locked';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$this->constrain($filterState->getQuery(), $negate);
|
||||
}
|
||||
|
||||
protected function constrain(Builder $query, bool $negate)
|
||||
protected function constrain(Builder $query, bool $negate): void
|
||||
{
|
||||
$query->where('is_locked', ! $negate);
|
||||
}
|
||||
|
Reference in New Issue
Block a user