mirror of
https://github.com/flarum/core.git
synced 2025-08-11 02:44:04 +02:00
chore(phpstan): upgrade to be compatible with latest dependency updates (#3835)
This commit is contained in:
@@ -21,13 +21,18 @@ use Illuminate\Support\Str;
|
||||
* @property string|null $allowed_ips
|
||||
* @property string|null $scopes
|
||||
* @property int|null $user_id
|
||||
* @property \Flarum\User\User|null $user
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon|null $last_activity_at
|
||||
* @property-read \Flarum\User\User|null $user
|
||||
*/
|
||||
class ApiKey extends AbstractModel
|
||||
{
|
||||
protected $casts = ['last_activity_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'last_activity_at' => 'datetime'
|
||||
];
|
||||
|
||||
public static function generate(): static
|
||||
{
|
||||
|
@@ -137,7 +137,7 @@ class ShowDiscussionController extends AbstractShowController
|
||||
|
||||
/** @var Post $post */
|
||||
foreach ($posts as $post) {
|
||||
$post->discussion = $discussion;
|
||||
$post->setRelation('discussion', $discussion);
|
||||
}
|
||||
|
||||
$this->loadRelations($posts, $include, $request);
|
||||
|
@@ -12,7 +12,7 @@ namespace Flarum\Api\Controller;
|
||||
use Flarum\Http\RememberAccessToken;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Http\SessionAccessToken;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class TerminateAllOtherSessionsController extends AbstractDeleteController
|
||||
|
@@ -14,6 +14,7 @@ use Flarum\Discussion\Command\EditDiscussion;
|
||||
use Flarum\Discussion\Command\ReadDiscussion;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Post\Post;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Arr;
|
||||
@@ -35,6 +36,7 @@ class UpdateDiscussionController extends AbstractShowController
|
||||
$discussionId = Arr::get($request->getQueryParams(), 'id');
|
||||
$data = Arr::get($request->getParsedBody(), 'data', []);
|
||||
|
||||
/** @var Discussion $discussion */
|
||||
$discussion = $this->bus->dispatch(
|
||||
new EditDiscussion($discussionId, $actor, $data)
|
||||
);
|
||||
@@ -50,6 +52,7 @@ class UpdateDiscussionController extends AbstractShowController
|
||||
}
|
||||
|
||||
if ($posts = $discussion->getModifiedPosts()) {
|
||||
/** @var Collection<int, Post> $posts */
|
||||
$posts = (new Collection($posts))->load('discussion', 'user');
|
||||
$discussionPosts = $discussion->posts()->whereVisibleTo($actor)->oldest()->pluck('id')->all();
|
||||
|
||||
|
@@ -164,11 +164,9 @@ abstract class AbstractSerializer extends BaseAbstractSerializer
|
||||
{
|
||||
if (is_object($model)) {
|
||||
return $model->$relation;
|
||||
} elseif (is_array($model)) {
|
||||
return $model[$relation];
|
||||
}
|
||||
|
||||
return null;
|
||||
return $model[$relation];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -17,6 +17,7 @@ class Schedule extends LaravelSchedule
|
||||
{
|
||||
public function dueEvents($app)
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
return (new Collection($this->events))->filter->isDue(new class($app) {
|
||||
protected Config $config;
|
||||
|
||||
|
@@ -9,8 +9,15 @@
|
||||
|
||||
namespace Flarum\Database\Eloquent;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Illuminate\Database\Eloquent\Collection as BaseCollection;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
* @template TModel of AbstractModel
|
||||
*
|
||||
* @extends BaseCollection<TKey, TModel>
|
||||
*/
|
||||
class Collection extends BaseCollection
|
||||
{
|
||||
/**
|
||||
|
@@ -46,16 +46,16 @@ use Illuminate\Support\Str;
|
||||
* @property int|null $last_post_number
|
||||
* @property \Carbon\Carbon|null $hidden_at
|
||||
* @property int|null $hidden_user_id
|
||||
* @property UserState|null $state
|
||||
* @property \Illuminate\Database\Eloquent\Collection $posts
|
||||
* @property \Illuminate\Database\Eloquent\Collection $comments
|
||||
* @property \Illuminate\Database\Eloquent\Collection $participants
|
||||
* @property Post|null $firstPost
|
||||
* @property User|null $user
|
||||
* @property Post|null $lastPost
|
||||
* @property User|null $lastPostedUser
|
||||
* @property \Illuminate\Database\Eloquent\Collection $readers
|
||||
* @property bool $is_private
|
||||
* @property-read UserState|null $state
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $posts
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $comments
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $participants
|
||||
* @property-read Post|null $firstPost
|
||||
* @property-read User|null $user
|
||||
* @property-read Post|null $lastPost
|
||||
* @property-read User|null $lastPostedUser
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $readers
|
||||
*/
|
||||
class Discussion extends AbstractModel
|
||||
{
|
||||
@@ -69,12 +69,16 @@ class Discussion extends AbstractModel
|
||||
*/
|
||||
protected array $modifiedPosts = [];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'comment_count' => 'integer',
|
||||
'participant_count' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'first_post_id' => 'integer',
|
||||
'last_posted_user_id' => 'integer',
|
||||
'last_post_id' => 'integer',
|
||||
'last_post_number' => 'integer',
|
||||
'hidden_user_id' => 'integer',
|
||||
'is_private' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'last_posted_at' => 'datetime',
|
||||
@@ -224,6 +228,8 @@ class Discussion extends AbstractModel
|
||||
|
||||
/**
|
||||
* Get the posts that have been modified during this request.
|
||||
*
|
||||
* @return Post[]
|
||||
*/
|
||||
public function getModifiedPosts(): array
|
||||
{
|
||||
|
@@ -38,7 +38,7 @@ class DiscussionRepository
|
||||
* Get the IDs of discussions which a user has read completely.
|
||||
*
|
||||
* @param User $user
|
||||
* @return Collection<Discussion>
|
||||
* @return Collection<int, Discussion>
|
||||
* @deprecated 1.3 Use `getReadIdsQuery` instead
|
||||
*/
|
||||
public function getReadIds(User $user): Collection
|
||||
|
@@ -28,8 +28,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
* @property int $discussion_id
|
||||
* @property Carbon|null $last_read_at
|
||||
* @property int|null $last_read_post_number
|
||||
* @property Discussion $discussion
|
||||
* @property User $user
|
||||
* @property-read Discussion $discussion
|
||||
* @property-read User $user
|
||||
*/
|
||||
class UserState extends AbstractModel
|
||||
{
|
||||
@@ -37,12 +37,12 @@ class UserState extends AbstractModel
|
||||
|
||||
protected $table = 'discussion_user';
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['last_read_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'discussion_id' => 'integer',
|
||||
'last_read_post_number' => 'integer',
|
||||
'last_read_at' => 'datetime'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
@@ -95,7 +95,7 @@ class ExtensionManager
|
||||
$extension = $extensions->get($enabledKey);
|
||||
if (is_null($extension)) {
|
||||
$needsReset = true;
|
||||
} else {
|
||||
} else { // @phpstan-ignore-line
|
||||
$enabledExtensions[] = $extension;
|
||||
}
|
||||
}
|
||||
|
@@ -236,4 +236,17 @@ class Application
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function version(): string
|
||||
{
|
||||
return static::VERSION;
|
||||
}
|
||||
|
||||
public function terminating(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function terminate(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@@ -9,13 +9,19 @@
|
||||
|
||||
namespace Flarum\Foundation;
|
||||
|
||||
class Container extends \Illuminate\Container\Container
|
||||
{
|
||||
public function terminating(): void
|
||||
{
|
||||
}
|
||||
use Illuminate\Container\Container as LaravelContainer;
|
||||
|
||||
public function terminate(): void
|
||||
class Container extends LaravelContainer
|
||||
{
|
||||
/**
|
||||
* Laravel's application is the container itself.
|
||||
* So as we upgrade Laravel versions, some of its internals that we rely on
|
||||
* make calls to methods that don't exist in our container, but do in Laravel's Application.
|
||||
*
|
||||
* @TODO: Implement the Application contract and merge the container into it.
|
||||
*/
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
return $this->get('flarum')->$name(...$arguments);
|
||||
}
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ use Illuminate\Cache\Repository as CacheRepository;
|
||||
use Illuminate\Config\Repository as ConfigRepository;
|
||||
use Illuminate\Contracts\Cache\Repository;
|
||||
use Illuminate\Contracts\Cache\Store;
|
||||
use Illuminate\Contracts\Container\Container as LaravelContainer;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Hashing\HashServiceProvider;
|
||||
use Illuminate\Validation\ValidationServiceProvider;
|
||||
@@ -86,7 +87,7 @@ class InstalledSite implements SiteInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function bootLaravel(): Container
|
||||
protected function bootLaravel(): LaravelContainer
|
||||
{
|
||||
$container = new Container;
|
||||
$laravel = new Application($container, $this->paths);
|
||||
@@ -95,7 +96,7 @@ class InstalledSite implements SiteInterface
|
||||
$container->instance('flarum.config', $this->config);
|
||||
$container->alias('flarum.config', Config::class);
|
||||
$container->instance('flarum.debug', $this->config->inDebugMode());
|
||||
$container->instance('config', $config = $this->getIlluminateConfig());
|
||||
$container->instance('config', $this->getIlluminateConfig());
|
||||
$container->instance('flarum.maintenance.handler', new MaintenanceModeHandler);
|
||||
|
||||
$this->registerLogger($container);
|
||||
|
@@ -26,8 +26,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property string|null $color
|
||||
* @property string|null $icon
|
||||
* @property bool $is_hidden
|
||||
* @property \Illuminate\Database\Eloquent\Collection $users
|
||||
* @property \Illuminate\Database\Eloquent\Collection $permissions
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $users
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection $permissions
|
||||
*/
|
||||
class Group extends AbstractModel
|
||||
{
|
||||
@@ -39,12 +39,9 @@ class Group extends AbstractModel
|
||||
const MEMBER_ID = 3;
|
||||
const MODERATOR_ID = 4;
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'is_hidden' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
@@ -21,12 +21,10 @@ class Permission extends AbstractModel
|
||||
{
|
||||
protected $table = 'group_permission';
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['created_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'group_id' => 'integer',
|
||||
'created_at' => 'datetime'
|
||||
];
|
||||
|
||||
public function group(): BelongsTo
|
||||
{
|
||||
|
@@ -29,7 +29,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
* @property string $title
|
||||
* @property string|null $last_ip_address
|
||||
* @property string|null $last_user_agent
|
||||
* @property \Flarum\User\User|null $user
|
||||
* @property-read \Flarum\User\User|null $user
|
||||
*/
|
||||
class AccessToken extends AbstractModel
|
||||
{
|
||||
@@ -38,6 +38,8 @@ class AccessToken extends AbstractModel
|
||||
protected $table = 'access_tokens';
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
'last_activity_at' => 'datetime',
|
||||
];
|
||||
|
@@ -19,8 +19,8 @@ use Illuminate\Database\ConnectionInterface;
|
||||
use Illuminate\Filesystem\FilesystemAdapter;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Flysystem\Adapter\Local;
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\Local\LocalFilesystemAdapter;
|
||||
|
||||
class EnableBundledExtensions implements Step
|
||||
{
|
||||
@@ -68,8 +68,9 @@ class EnableBundledExtensions implements Step
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
$extension->migrate($this->getMigrator());
|
||||
$adapter = new LocalFilesystemAdapter($this->assetPath);
|
||||
$extension->copyAssetsTo(
|
||||
new FilesystemAdapter(new Filesystem(new Local($this->assetPath)))
|
||||
new FilesystemAdapter(new Filesystem($adapter), $adapter)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,7 +82,7 @@ class EnableBundledExtensions implements Step
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<Extension>
|
||||
* @return Collection<string, Extension>
|
||||
*/
|
||||
private function loadExtensions(): Collection
|
||||
{
|
||||
|
@@ -14,4 +14,5 @@ use Symfony\Contracts\Translation\TranslatorInterface as SymfonyTranslatorInterf
|
||||
|
||||
interface TranslatorInterface extends Translator, SymfonyTranslatorInterface
|
||||
{
|
||||
public function getLocale(): string;
|
||||
}
|
||||
|
@@ -37,22 +37,27 @@ use Illuminate\Support\Arr;
|
||||
* @property int|null $from_user_id
|
||||
* @property string $type
|
||||
* @property int|null $subject_id
|
||||
* @property mixed|null $data
|
||||
* @property array|null $data
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $read_at
|
||||
* @property \Carbon\Carbon $deleted_at
|
||||
* @property \Flarum\User\User|null $user
|
||||
* @property \Flarum\User\User|null $fromUser
|
||||
* @property \Flarum\Database\AbstractModel|\Flarum\Post\Post|\Flarum\Discussion\Discussion|null $subject
|
||||
* @property-read \Flarum\User\User|null $user
|
||||
* @property-read \Flarum\User\User|null $fromUser
|
||||
* @property-read \Flarum\Database\AbstractModel|\Flarum\Post\Post|\Flarum\Discussion\Discussion|null $subject
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<Notification> matchingBlueprint(BlueprintInterface $blueprint)
|
||||
*/
|
||||
class Notification extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['created_at' => 'datetime', 'read_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'from_user_id' => 'integer',
|
||||
'subject_id' => 'integer',
|
||||
'data' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
'read_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* A map of notification types and the model classes to use for their
|
||||
@@ -69,26 +74,6 @@ class Notification extends AbstractModel
|
||||
$this->read_at = Carbon::now();
|
||||
}
|
||||
|
||||
/**
|
||||
* When getting the data attribute, unserialize the JSON stored in the
|
||||
* database into a plain array.
|
||||
*/
|
||||
public function getDataAttribute(?string $value): mixed
|
||||
{
|
||||
return $value !== null
|
||||
? json_decode($value, true)
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* When setting the data attribute, serialize it into JSON for storage in
|
||||
* the database.
|
||||
*/
|
||||
public function setDataAttribute(mixed $value): void
|
||||
{
|
||||
$this->attributes['data'] = json_encode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject model for this notification record by looking up its
|
||||
* type in our subject model map.
|
||||
|
@@ -15,6 +15,9 @@ use Illuminate\Database\Eloquent\Collection;
|
||||
|
||||
class NotificationRepository
|
||||
{
|
||||
/**
|
||||
* @return Collection<int, Notification>
|
||||
*/
|
||||
public function findByUser(User $user, ?int $limit = null, int $offset = 0): Collection
|
||||
{
|
||||
$primaries = Notification::query()
|
||||
|
@@ -70,7 +70,8 @@ class NotificationSyncer
|
||||
continue;
|
||||
}
|
||||
|
||||
$existing = $toDelete->first(function ($notification) use ($user) {
|
||||
/** @var Notification|null $existing */
|
||||
$existing = $toDelete->first(function (Notification $notification) use ($user) {
|
||||
return $notification->user_id === $user->id;
|
||||
});
|
||||
|
||||
|
@@ -33,12 +33,12 @@ use Staudenmeir\EloquentEagerLimit\HasEagerLimit;
|
||||
* @property int|null $edited_user_id
|
||||
* @property \Carbon\Carbon|null $hidden_at
|
||||
* @property int|null $hidden_user_id
|
||||
* @property \Flarum\Discussion\Discussion|null $discussion
|
||||
* @property User|null $user
|
||||
* @property User|null $editedUser
|
||||
* @property User|null $hiddenUser
|
||||
* @property string $ip_address
|
||||
* @property bool $is_private
|
||||
* @property-read Discussion|null $discussion
|
||||
* @property-read User|null $user
|
||||
* @property-read User|null $editedUser
|
||||
* @property-read User|null $hiddenUser
|
||||
*/
|
||||
class Post extends AbstractModel
|
||||
{
|
||||
@@ -48,12 +48,13 @@ class Post extends AbstractModel
|
||||
|
||||
protected $table = 'posts';
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'discussion_id' => 'integer',
|
||||
'number' => 'integer',
|
||||
'user_id' => 'integer',
|
||||
'edited_user_id' => 'integer',
|
||||
'hidden_user_id' => 'integer',
|
||||
'is_private' => 'boolean',
|
||||
'created_at' => 'datetime',
|
||||
'edited_at' => 'datetime',
|
||||
|
@@ -24,12 +24,10 @@ use Illuminate\Support\Str;
|
||||
*/
|
||||
class EmailToken extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['created_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* Use a custom primary key for this model.
|
||||
|
@@ -21,18 +21,11 @@ use Illuminate\Support\Str;
|
||||
*/
|
||||
class PasswordToken extends AbstractModel
|
||||
{
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = ['created_at' => 'datetime'];
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
'user_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* Use a custom primary key for this model.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected $primaryKey = 'token';
|
||||
|
@@ -63,6 +63,8 @@ class User extends AbstractModel
|
||||
use HasEagerLimit;
|
||||
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'is_email_confirmed' => 'boolean',
|
||||
'joined_at' => 'datetime',
|
||||
'last_seen_at' => 'datetime',
|
||||
'marked_all_as_read_at' => 'datetime',
|
||||
|
Reference in New Issue
Block a user