Skip to content

Commit

Permalink
chore: enable phpstan, apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Oct 31, 2023
1 parent 88ef714 commit 381fd1f
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 88 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: FoF Follow Tags PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: false

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF Follow Tags JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,11 +8,12 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: yarn
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
135 changes: 75 additions & 60 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,65 +1,80 @@
{
"name": "fof/follow-tags",
"description": "Follow tags and be notified of new discussions and replies",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/follow-tags/issues",
"source": "https://github.com/FriendsOfFlarum/follow-tags",
"forum": "https://discuss.flarum.org/d/20525"
},
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
"require": {
"flarum/core": "^1.3.0",
"flarum/tags": "^1.3.0",
"fof/extend": "^1.0.0"
},
"authors": [
{
"name": "David Sevilla Martín",
"email": "[email protected]",
"role": "Developer"
"name": "fof/follow-tags",
"description": "Follow tags and be notified of new discussions and replies",
"keywords": [
"flarum"
],
"type": "flarum-extension",
"license": "MIT",
"support": {
"issues": "https://github.com/FriendsOfFlarum/follow-tags/issues",
"source": "https://github.com/FriendsOfFlarum/follow-tags",
"forum": "https://discuss.flarum.org/d/20525"
},
{
"name": "IanM",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"FoF\\FollowTags\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "FoF Follow Tags",
"category": "feature",
"icon": {
"name": "fas fa-user-tag",
"backgroundColor": "#e74c3c",
"color": "#fff"
},
"optional-dependencies": [
"flarum/subscriptions",
"flarum/approval"
]
"homepage": "https://friendsofflarum.org",
"funding": [
{
"type": "website",
"url": "https://opencollective.com/fof/donate"
}
],
"require": {
"flarum/core": "^1.8.3",
"flarum/tags": "^1.8.0",
"fof/extend": "^1.2.0"
},
"authors": [
{
"name": "David Sevilla Martín",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "IanM",
"email": "[email protected]",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"FoF\\FollowTags\\": "src/"
}
},
"extra": {
"flarum-extension": {
"title": "FoF Follow Tags",
"category": "feature",
"icon": {
"name": "fas fa-user-tag",
"backgroundColor": "#e74c3c",
"color": "#fff"
},
"optional-dependencies": [
"flarum/subscriptions",
"flarum/approval",
"flarum/mentions"
]
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/20525"
},
"flarum-cli": {
"modules": {
"githubActions": true
}
}
},
"require-dev": {
"flarum/approval": "*",
"flarum/subscriptions": "*",
"flarum/phpstan": "*",
"flarum/mentions": "*"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/20525"
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
},
"require-dev": {
"flarum/approval": "*",
"flarum/subscriptions": "*"
}
}
4 changes: 4 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Flarum\Extend;
use Flarum\Post\Event as Post;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\TagState;
use FoF\Extend\Extend\ExtensionSettings;

return [
Expand All @@ -29,6 +30,9 @@

new Extend\Locales(__DIR__.'/resources/locale'),

(new Extend\Model(TagState::class))
->cast('subscription', 'string'),

(new Extend\Routes('api'))
->post('/tags/{id}/subscription', 'fof-follow-tags.subscription', Controllers\ChangeTagSubscription::class),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}tag_user` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
$connection->statement("ALTER TABLE `${prefix}tag_user` MODIFY updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
$connection->statement("ALTER TABLE `{$prefix}tag_user` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
$connection->statement("ALTER TABLE `{$prefix}tag_user` MODIFY updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
},

'down' => function (Builder $schema) {
Expand Down
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- vendor/flarum/phpstan/extension.neon

parameters:
# The level will be increased in Flarum 2.0
level: 5
paths:
- extend.php
- src
excludePaths:
- *.blade.php
checkMissingIterableValueType: false
databaseMigrationsPath: ['migrations']
2 changes: 2 additions & 0 deletions src/AddTagSubscriptionAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Tag;
use Flarum\Tags\TagState;

class AddTagSubscriptionAttribute
{
public function __invoke(TagSerializer $serializer, Tag $tag, array $attributes): array
{
/** @var TagState $state */
$state = $tag->stateFor($serializer->getActor());

$attributes['subscription'] = $state->subscription;
Expand Down
12 changes: 3 additions & 9 deletions src/Controllers/ChangeTagSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Flarum\Http\RequestUtil;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Tag;
use Flarum\Tags\TagState;
use Flarum\User\User;
use FoF\FollowTags\Event;
use Illuminate\Contracts\Events\Dispatcher;
Expand All @@ -24,9 +25,6 @@

class ChangeTagSubscription extends AbstractShowController
{
/**
* {@inheritdoc}
*/
public $serializer = TagSerializer::class;

/**
Expand All @@ -39,21 +37,17 @@ public function __construct(Dispatcher $events)
$this->events = $events;
}

/**
* {@inheritdoc}
*/
protected function data(ServerRequestInterface $request, Document $document)
{
/**
* @var User
*/
$actor = RequestUtil::getActor($request);
$id = Arr::get($request->getQueryParams(), 'id');
$subscription = Arr::get($request->getParsedBody(), 'data.subscription');

$actor->assertRegistered();

$tag = Tag::whereVisibleTo($actor)->findOrFail($id);

/** @var TagState $state */
$state = $tag->stateFor($actor);

if (!in_array($subscription, ['follow', 'lurk', 'ignore', 'hide'])) {
Expand Down
5 changes: 3 additions & 2 deletions src/Jobs/NotificationJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

namespace FoF\FollowTags\Jobs;

use Flarum\Database\Eloquent\Collection;
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Notification\NotificationSyncer;
use Flarum\Queue\AbstractJob;
use Flarum\User\User;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Eloquent\Collection;

class NotificationJob extends AbstractJob implements ShouldQueue
{
Expand All @@ -30,7 +31,7 @@ class NotificationJob extends AbstractJob implements ShouldQueue
*
* @param NotificationSyncer $syncer
* @param BlueprintInterface $blueprint
* @param Collection $recipients
* @param Collection<User> $recipients
*/
protected function sync(NotificationSyncer $syncer, BlueprintInterface $blueprint, Collection $recipients): void
{
Expand Down
5 changes: 3 additions & 2 deletions src/Jobs/SendNotificationWhenDiscussionIsReTagged.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Flarum\Discussion\Discussion;
use Flarum\Notification\NotificationSyncer;
use Flarum\Tags\Tag;
use Flarum\User\User;
use FoF\FollowTags\Notifications\NewDiscussionTagBlueprint;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -42,8 +43,8 @@ public function handle(NotificationSyncer $notifications)
}

/**
* @var Collection
* @var $tagIds Collection
* @var Collection<Tag>|null $tags
* @phpstan-ignore-next-line
*/
$tags = $this->discussion->tags;
$tagIds = $tags->map->id;
Expand Down
4 changes: 2 additions & 2 deletions src/Jobs/SendNotificationWhenDiscussionIsStarted.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function handle(NotificationSyncer $notifications)
}

/**
* @var Collection
* @var $tagIds Collection
* @var Collection<Tag>|null $tags
* @phpstan-ignore-next-line
*/
$tags = $this->discussion->tags;
$tagIds = $tags->map->id;
Expand Down
10 changes: 6 additions & 4 deletions src/Jobs/SendNotificationWhenReplyIsPosted.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SendNotificationWhenReplyIsPosted extends NotificationJob
protected $post;

/**
* @var Post
* @var int
*/
protected $lastPostNumber;

Expand All @@ -41,11 +41,13 @@ public function handle(NotificationSyncer $notifications)
return;
}


$discussion = $this->post->discussion;

/**
* @var Collection
* @var $tagIds Collection
* @var Collection<Tag>|null $tags
* @phpstan-ignore-next-line
*/
$discussion = $this->post->discussion;
$tags = $discussion->tags;
$tagIds = $tags->map->id;

Expand Down
6 changes: 1 addition & 5 deletions src/Listeners/PreventMentionNotificationsFromIgnoredTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ public function __invoke(BlueprintInterface $blueprint, array $recipients): arra
return $recipients;
}

/**
* @var PostMentionedBlueprint|UserMentionedBlueprint
* @var $ids \Illuminate\Support\Collection
* @var $tags \Illuminate\Support\Collection
*/
$ids = collect($recipients)->pluck('id');
/** @phpstan-ignore-next-line */
$tags = $blueprint->post->discussion->tags->pluck('id');

if ($tags->isEmpty()) {
Expand Down

0 comments on commit 381fd1f

Please sign in to comment.