Completed
Push — master ( c75724...87d358 )
by Razon
03:04
created

BaseArticleLikeForm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 13
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 4 1
A getLike() 0 7 2
1
<?php
2
namespace App\Http\Api\Form;
3
4
use App\Form\Form;
5
use App\Model\ArticleLike;
6
7
abstract class BaseArticleLikeForm extends Form
8
{
9
    use UserTrait;
10
11
    /**
12
     * @property int $article_id
13
     */
14
    public $id;
15
16
    public function rules()
17
    {
18
        return [
19
            [['id', 'user'], 'required'],
20
        ];
21
    }
22
23
    private $like;
24
25
    public function getLike(): ?ArticleLike
26
    {
27
        if ($this->like === null) {
28
            $this->like = ArticleLike::findByArticleIdAndUserId($this->id, $this->getUser()->getId());
0 ignored issues
show
Bug introduced by
It seems like $this->getUser()->getId() can also be of type string; however, parameter $userId of App\Model\ArticleLike::findByArticleIdAndUserId() does only seem to accept integer, 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

28
            $this->like = ArticleLike::findByArticleIdAndUserId($this->id, /** @scrutinizer ignore-type */ $this->getUser()->getId());
Loading history...
29
        }
30
31
        return $this->like;
32
    }
33
}