diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c6b01b0..10036df 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,6 +7,11 @@ parameters: - src - config - database + ignoreErrors: + - '#Trait Coolsam\\NestedComments\\Concerns\\HasComments is used zero times and is not analysed#' + - + message: "#Called 'env' outside of the config directory which returns null when the config is cached, use 'config'#" + path: config/* tmpDir: build/phpstan checkOctaneCompatibility: true checkModelProperties: true diff --git a/src/Concerns/HasReactions.php b/src/Concerns/HasReactions.php index 18e8462..db35103 100644 --- a/src/Concerns/HasReactions.php +++ b/src/Concerns/HasReactions.php @@ -4,6 +4,7 @@ use Coolsam\NestedComments\Models\Reaction; use Coolsam\NestedComments\NestedComments; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Support\Facades\Auth; @@ -22,7 +23,7 @@ public function getReactionsCountAttribute(): int /** * @throws \Throwable */ - public function react(string $emoji): Reaction | int + public function react(string $emoji): Reaction | Model | int { $existing = $this->getExistingReaction($emoji); if ($existing) { @@ -47,7 +48,7 @@ public function react(string $emoji): Reaction | int /** * @throws \Exception */ - protected function getExistingReaction(string $emoji): ?Reaction + protected function getExistingReaction(string $emoji): Reaction | Model | null { $allowMultiple = \config('nested-comments.allow-multiple-reactions', false); $allowGuest = \config('nested-comments.allow-guest-reactions', false); diff --git a/src/Livewire/AddComment.php b/src/Livewire/AddComment.php index 908ab2b..7008796 100644 --- a/src/Livewire/AddComment.php +++ b/src/Livewire/AddComment.php @@ -2,7 +2,6 @@ namespace Coolsam\NestedComments\Livewire; -use Coolsam\NestedComments\Concerns\HasComments; use Coolsam\NestedComments\Models\Comment; use Coolsam\NestedComments\NestedCommentsServiceProvider; use Filament\Forms; @@ -38,9 +37,6 @@ public function mount(?Model $commentable = null, ?Comment $replyTo = null): voi $this->form->fill(); } - /** - * @return Model&HasComments - */ public function getCommentable(): Model { if (! $this->commentable) { @@ -80,6 +76,7 @@ public function create(): void public function render(): View { $namespace = NestedCommentsServiceProvider::$viewNamespace; + return view("$namespace::livewire.add-comment"); } diff --git a/src/Livewire/Comments.php b/src/Livewire/Comments.php index ec764f6..dfbbe05 100644 --- a/src/Livewire/Comments.php +++ b/src/Livewire/Comments.php @@ -13,7 +13,7 @@ class Comments extends Component { /** - * @var Model&HasComments|null + * @var (Model&HasComments)|null */ public ?Model $record = null; @@ -42,8 +42,10 @@ public function mount(): void public function refreshComments(): void { - $this->record = $this->record?->newQuery()->find($this->record->getKey()); - $this->comments = $this->record?->getCommentsTree(); + $this->record = $this->record->refresh(); + if (method_exists($this->record, 'getCommentsTree')) { + $this->comments = $this->record->getCommentsTree(); + } } public function render() diff --git a/src/Models/Comment.php b/src/Models/Comment.php index 09e5406..339e20e 100644 --- a/src/Models/Comment.php +++ b/src/Models/Comment.php @@ -30,6 +30,7 @@ public function getCommentatorAttribute() if ($this->user) { return call_user_func(config('nested-comments.closures.getUserNameUsing'), $this->user); } + return $this->getAttribute('guest_name'); } diff --git a/src/NestedComments.php b/src/NestedComments.php index 7222913..00296b7 100644 --- a/src/NestedComments.php +++ b/src/NestedComments.php @@ -3,7 +3,6 @@ namespace Coolsam\NestedComments; use Filament\AvatarProviders\UiAvatarsProvider; -use Filament\Facades\Filament; use Filament\Support\Facades\FilamentColor; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model;