Skip to content

Commit 71cd085

Browse files
authored
Fixed PHPSTan Errors (#14)
2 parents 067e56c + 7ccfce2 commit 71cd085

File tree

6 files changed

+15
-10
lines changed

6 files changed

+15
-10
lines changed

phpstan.neon.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ parameters:
77
- src
88
- config
99
- database
10+
ignoreErrors:
11+
- '#Trait Coolsam\\NestedComments\\Concerns\\HasComments is used zero times and is not analysed#'
12+
-
13+
message: "#Called 'env' outside of the config directory which returns null when the config is cached, use 'config'#"
14+
path: config/*
1015
tmpDir: build/phpstan
1116
checkOctaneCompatibility: true
1217
checkModelProperties: true

src/Concerns/HasReactions.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Coolsam\NestedComments\Models\Reaction;
66
use Coolsam\NestedComments\NestedComments;
7+
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Database\Eloquent\Relations\MorphMany;
89
use Illuminate\Support\Facades\Auth;
910

@@ -22,7 +23,7 @@ public function getReactionsCountAttribute(): int
2223
/**
2324
* @throws \Throwable
2425
*/
25-
public function react(string $emoji): Reaction | int
26+
public function react(string $emoji): Reaction | Model | int
2627
{
2728
$existing = $this->getExistingReaction($emoji);
2829
if ($existing) {
@@ -47,7 +48,7 @@ public function react(string $emoji): Reaction | int
4748
/**
4849
* @throws \Exception
4950
*/
50-
protected function getExistingReaction(string $emoji): ?Reaction
51+
protected function getExistingReaction(string $emoji): Reaction | Model | null
5152
{
5253
$allowMultiple = \config('nested-comments.allow-multiple-reactions', false);
5354
$allowGuest = \config('nested-comments.allow-guest-reactions', false);

src/Livewire/AddComment.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Coolsam\NestedComments\Livewire;
44

5-
use Coolsam\NestedComments\Concerns\HasComments;
65
use Coolsam\NestedComments\Models\Comment;
76
use Coolsam\NestedComments\NestedCommentsServiceProvider;
87
use Filament\Forms;
@@ -38,9 +37,6 @@ public function mount(?Model $commentable = null, ?Comment $replyTo = null): voi
3837
$this->form->fill();
3938
}
4039

41-
/**
42-
* @return Model&HasComments
43-
*/
4440
public function getCommentable(): Model
4541
{
4642
if (! $this->commentable) {
@@ -80,6 +76,7 @@ public function create(): void
8076
public function render(): View
8177
{
8278
$namespace = NestedCommentsServiceProvider::$viewNamespace;
79+
8380
return view("$namespace::livewire.add-comment");
8481
}
8582

src/Livewire/Comments.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class Comments extends Component
1414
{
1515
/**
16-
* @var Model&HasComments|null
16+
* @var (Model&HasComments)|null
1717
*/
1818
public ?Model $record = null;
1919

@@ -42,8 +42,10 @@ public function mount(): void
4242

4343
public function refreshComments(): void
4444
{
45-
$this->record = $this->record?->newQuery()->find($this->record->getKey());
46-
$this->comments = $this->record?->getCommentsTree();
45+
$this->record = $this->record->refresh();
46+
if (method_exists($this->record, 'getCommentsTree')) {
47+
$this->comments = $this->record->getCommentsTree();
48+
}
4749
}
4850

4951
public function render()

src/Models/Comment.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function getCommentatorAttribute()
3030
if ($this->user) {
3131
return call_user_func(config('nested-comments.closures.getUserNameUsing'), $this->user);
3232
}
33+
3334
return $this->getAttribute('guest_name');
3435
}
3536

src/NestedComments.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Coolsam\NestedComments;
44

55
use Filament\AvatarProviders\UiAvatarsProvider;
6-
use Filament\Facades\Filament;
76
use Filament\Support\Facades\FilamentColor;
87
use Illuminate\Contracts\Auth\Authenticatable;
98
use Illuminate\Database\Eloquent\Model;

0 commit comments

Comments
 (0)