1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 00:47:00 +02:00

chore(phpstan): enable phpstan in bundled extensions (#3667)

* feat(phpstan): pick up extended model relations typings
* feat(phpstan): pick up extended model date attributes
* feat(core): introduce `castAttribute` extender
Stops using `dates` as it's deprecated in laravel 8
* feat(phpstan): pick up extended model attributes through casts
* fix: extenders not resolved when declared namespace
* fix(phpstan): new model attributes are always nullable
* chore(phpstan): add helpful cache clearing command
* Apply fixes from StyleCI
* chore: improve extend files provider logic
* chore: rename `castAttribute` to just `cast`
* chore: update phpstan package to detect `cast` method
* chore: enable phpstan in bundled extensions
* chore: rebasing conflicts
* chore: rebasing conflicts
* chore: typings for latest 1.7 changes

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Sami Mazouz
2023-01-19 21:49:38 +01:00
committed by GitHub
parent ccf9442d79
commit da1bf8da21
59 changed files with 215 additions and 138 deletions

View File

@@ -46,7 +46,7 @@ return [
->delete('/posts/{id}/flags', 'flags.delete', DeleteFlagsController::class),
(new Extend\Model(User::class))
->dateAttribute('read_flags_at'),
->cast('read_flags_at', 'datetime'),
(new Extend\Model(Post::class))
->hasMany('flags', Flag::class, 'post_id'),

View File

@@ -9,6 +9,7 @@
namespace Flarum\Flags\Api\Controller;
use Carbon\Carbon;
use Flarum\Api\Controller\AbstractListController;
use Flarum\Flags\Api\Serializer\FlagSerializer;
use Flarum\Flags\Flag;
@@ -43,7 +44,7 @@ class ListFlagsController extends AbstractListController
$actor->assertRegistered();
$actor->read_flags_at = time();
$actor->read_flags_at = Carbon::now();
$actor->save();
$flags = Flag::whereVisibleTo($actor)

View File

@@ -12,6 +12,8 @@ namespace Flarum\Flags\Api\Serializer;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Flags\Flag;
use InvalidArgumentException;
class FlagSerializer extends AbstractSerializer
{
@@ -20,11 +22,14 @@ class FlagSerializer extends AbstractSerializer
*/
protected $type = 'flags';
/**
* {@inheritdoc}
*/
protected function getDefaultAttributes($flag)
{
if (! ($flag instanceof Flag)) {
throw new InvalidArgumentException(
get_class($this).' can only serialize instances of '.Flag::class
);
}
return [
'type' => $flag->type,
'reason' => $flag->reason,

View File

@@ -9,6 +9,7 @@
namespace Flarum\Flags\Command;
use Carbon\Carbon;
use Flarum\Flags\Event\Created;
use Flarum\Flags\Flag;
use Flarum\Foundation\ValidationException;
@@ -99,7 +100,7 @@ class CreateFlagHandler
$flag->type = 'user';
$flag->reason = Arr::get($data, 'attributes.reason');
$flag->reason_detail = Arr::get($data, 'attributes.reasonDetail');
$flag->created_at = time();
$flag->created_at = Carbon::now();
$flag->save();

View File

@@ -11,7 +11,7 @@ namespace Flarum\Flags\Command;
use Flarum\Flags\Event\Deleting;
use Flarum\Flags\Event\FlagsWillBeDeleted;
use Flarum\Flags\Flag;
use Flarum\Post\Post;
use Flarum\Post\PostRepository;
use Illuminate\Events\Dispatcher;
@@ -39,7 +39,7 @@ class DeleteFlagsHandler
/**
* @param DeleteFlags $command
* @return Flag
* @return Post
*/
public function handle(DeleteFlags $command)
{

View File

@@ -9,11 +9,23 @@
namespace Flarum\Flags;
use Carbon\Carbon;
use Flarum\Database\AbstractModel;
use Flarum\Database\ScopeVisibilityTrait;
use Flarum\Post\Post;
use Flarum\User\User;
/**
* @property int $post_id
* @property int $user_id
* @property string $type
* @property string $reason
* @property string $reason_detail
* @property Carbon $created_at
*
* @property-read Post $post
* @property-read User $user
*/
class Flag extends AbstractModel
{
use ScopeVisibilityTrait;