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

BaseArticleLikeForm::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 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
}