Completed
Push — master ( 2b6acf...5f05b1 )
by Christopher
03:20
created

PostsHaveComments::commentAsGuest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Chriscreate\Blog\Traits\Post;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
trait PostsHaveComments
8
{
9
    public function commentAsUser(Model $user, string $comment)
10
    {
11
        return $this->comments()->create([
0 ignored issues
show
Bug introduced by
It seems like comments() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
12
            'content' => $comment,
13
            'user_id' => $user->getKey(),
14
            'email' => $user->email,
15
        ]);
16
    }
17
18
    public function commentAsGuest(array $fields)
19
    {
20
        return $this->comments()->create([
0 ignored issues
show
Bug introduced by
It seems like comments() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21
            'content' => $fields->content,
22
            'user_id' => null,
23
            'email' => $comment->email,
0 ignored issues
show
Bug introduced by
The variable $comment does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
24
            'author' => $comment->author,
25
        ]);
26
    }
27
}
28