Skip to content

Commit

Permalink
fix: phpstan complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 12, 2023
1 parent f191508 commit daa5b66
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Flarum\Extend;
use Flarum\Post\Event\Posted;
use Flarum\Post\Event\Saving as PostSaving;
use Flarum\Post\Post;
use Flarum\Settings\Event\Saving as SettingSaving;
use FoF\Filter\Listener\AddCensorChecks;
use FoF\Filter\Listener\AutoMerge;
Expand All @@ -32,6 +33,10 @@
(new Extend\View())
->namespace('fof-filter', __DIR__.'/views'),

(new Extend\Model(Post::class))
->cast('auto_mod', 'bool')
->cast('emailed', 'bool'),

(new Extend\Event())
->listen(SettingSaving::class, AddCensorChecks::class)
->listen(PostSaving::class, CheckPost::class)
Expand Down
4 changes: 3 additions & 1 deletion src/Listener/AddCensorChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class AddCensorChecks
{
public function handle(Saving $event)
{
if (isset($event->settings['fof-filter.words']) && $badwords = explode("\n", trim($event->settings['fof-filter.words']))) {
if (isset($event->settings['fof-filter.words'])) {
$badwords = explode("\n", trim($event->settings['fof-filter.words']));

$leet_replace = [];
$leet_replace['a'] = '(a|a\.|a\-|4|@|Á|á|À|Â|à|Â|â|Ä|ä|Ã|ã|Å|å|α|Δ|Λ|λ)';
$leet_replace['b'] = '(b|b\.|b\-|8|\|3|ß|Β|β)';
Expand Down
8 changes: 6 additions & 2 deletions src/Listener/CheckPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace FoF\Filter\Listener;

use Carbon\Carbon;
use Flarum\Flags\Event\Created;
use Flarum\Flags\Flag;
use Flarum\Post\Event\Saving;
Expand Down Expand Up @@ -85,6 +86,7 @@ function ($matches) use (&$isExplicit) {
if ($matches) {
$isExplicit = true;
}
return $matches[0];
},
str_replace(' ', '', $postContent)
);
Expand All @@ -94,17 +96,19 @@ function ($matches) use (&$isExplicit) {

public function deletePost(Post $post): void
{
/** @phpstan-ignore-next-line */
$post->is_approved = false;
$post->auto_mod = true;
$post->afterSave(function ($post) {
if ($post->number == 1) {
if ($post->number === 1) {
$post->discussion->delete();
}
});
}

public function flagPost(Post $post): void
{
/** @phpstan-ignore-next-line */
$post->is_approved = false;
$post->auto_mod = true;
$post->afterSave(function ($post) {
Expand All @@ -117,7 +121,7 @@ public function flagPost(Post $post): void
$flag->post_id = $post->id;
$flag->type = 'autoMod';
$flag->reason_detail = $this->translator->trans('fof-filter.forum.flag_message');
$flag->created_at = time();
$flag->created_at = Carbon::now();
$flag->save();

$this->bus->dispatch(new Created($flag, new Guest()));
Expand Down

0 comments on commit daa5b66

Please sign in to comment.