Passed
Push — 5.0.0 ( 337324...37581b )
by Fèvre
05:07
created

CommentForm::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Forms;
6
7
use Livewire\Attributes\Locked;
8
use Livewire\Attributes\Validate;
9
use Livewire\Form;
10
use Xetaio\Mentions\Parser\MentionParser;
11
use Xetaravel\Models\BlogComment;
12
13
class CommentForm extends Form
14
{
15
    /**
16
     * The article id where the comment belong to.
17
     *
18
     * @var int|null
19
     */
20
    #[Locked]
21
    public ?int $blog_article_id = null;
22
23
    /**
24
     * The content of the comment.
25
     *
26
     * @var string|null
27
     */
28
    #[Validate('required|min:10')]
29
    public ?string $content = null;
30
31
    /**
32
     * Function to store the model.
33
     *
34
     * @return BlogComment
35
     */
36
    public function store(): BlogComment
37
    {
38
        $comment = BlogComment::create($this->only([
39
            'blog_article_id',
40
            'content'
41
        ]));
42
43
        $parser = new MentionParser($comment);
0 ignored issues
show
Bug introduced by
It seems like $comment can also be of type Illuminate\Database\Eloq...gHasThroughRelationship; however, parameter $model of Xetaio\Mentions\Parser\M...onParser::__construct() does only seem to accept Illuminate\Database\Eloquent\Model, maybe add an additional type check? ( Ignorable by Annotation )

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

43
        $parser = new MentionParser(/** @scrutinizer ignore-type */ $comment);
Loading history...
44
        $content = $parser->parse($this->content);
45
        $comment->content = $content;
0 ignored issues
show
Bug introduced by
The property content does not seem to exist on Illuminate\Database\Eloq...gHasThroughRelationship.
Loading history...
46
        $comment->save();
47
48
        return $comment;
49
    }
50
}
51