Issues (264)

app/Livewire/Discuss/CreatePost.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Discuss;
6
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
11
use Illuminate\Support\Facades\Auth;
12
use Livewire\Attributes\On;
13
use Livewire\Component;
14
use Masmerise\Toaster\Toastable;
15
use Xetaravel\Livewire\Forms\DiscussPostForm;
16
use Xetaravel\Models\DiscussConversation;
17
use Xetaravel\Models\DiscussPost;
18
use Throwable;
19
20
class CreatePost extends Component
21
{
22
    use AuthorizesRequests;
23
    use Toastable;
24
25
    /**
26
     * The form used to create/update a model.
27
     *
28
     * @var DiscussPostForm
29
     */
30
    public DiscussPostForm $form;
31
32
    public function mount(DiscussConversation $discussConversation): void
33
    {
34
        $this->form->conversation_id = $discussConversation->getKey();
35
        $this->form->is_pinned = $discussConversation->is_pinned;
36
    }
37
38
    /**
39
     * Create a new post
40
     *
41
     * @return void
42
     *
43
     * @throws Throwable
44
     */
45
    public function create(): void
46
    {
47
        $this->authorize('create', DiscussPost::class);
48
49
        $this->validate();
50
51
        // Users that have the permission "manage discuss conversation" can bypass this rule. (Default to Developer)
52
        if (DiscussPost::isFlooding('xetaravel.flood.discuss.post') && !Auth::user()->hasPermissionTo('manage discuss conversation')) {
0 ignored issues
show
The method hasPermissionTo() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        if (DiscussPost::isFlooding('xetaravel.flood.discuss.post') && !Auth::user()->/** @scrutinizer ignore-call */ hasPermissionTo('manage discuss conversation')) {
Loading history...
53
            $this->error('Wow, keep calm bro, and try to not flood !');
54
55
            return;
56
        }
57
        $discussPost = $this->form->create();
58
59
        redirect()
60
            ->route('discuss.post.show', ['id' => $discussPost->getKey()])
0 ignored issues
show
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
            ->/** @scrutinizer ignore-call */ route('discuss.post.show', ['id' => $discussPost->getKey()])

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
            ->success('Your reply has been posted successfully !');
62
    }
63
64
    public function render(): Factory|Application|View|\Illuminate\View\View
65
    {
66
        return view('livewire.discuss.create-post');
67
    }
68
69
    /**
70
     * When a user click on 'Reply' set the content to the username#postId
71
     *
72
     * @param $content
73
     *
74
     * @return void
75
     */
76
    #[On('post-reply')]
77
    public function updateContent($content): void
78
    {
79
        $this->form->content = $content . $this->form->content;
80
    }
81
}
82