IsResource::setValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace VGirol\JsonApiFaker\Laravel\Factory;
4
5
use Illuminate\Database\Eloquent\Model;
6
use VGirol\JsonApiFaker\Exception\JsonApiFakerException;
7
8
/**
9
 * An abstract factory for resources (resource object or resource identifer).
10
 */
11
trait IsResource
12
{
13 1
    use HasModel;
14
15
    /**
16
     * Class constructor.
17
     *
18
     * @param Model|null  $model
19
     * @param string|null $resourceType
20
     *
21
     * @return void
22
     * @throws JsonApiFakerException
23
     */
24 60
    public function __construct($model = null, ?string $resourceType = null)
25
    {
26 60
        if (($model !== null) && ($resourceType !== null)) {
27 45
            $this->setValues($model, $resourceType);
28
        }
29 60
    }
30
31
    /**
32
     * Set the model and the resource type.
33
     *
34
     * @param Model  $model
35
     * @param string $resourceType
36
     *
37
     * @return static
38
     * @throws JsonApiFakerException
39
     */
40 54
    public function setValues($model, string $resourceType)
41
    {
42 54
        return $this->setModel($model)
43 51
            ->setId($model->getKey())
0 ignored issues
show
Bug introduced by
It seems like setId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

43
            ->/** @scrutinizer ignore-call */ setId($model->getKey())
Loading history...
44 51
            ->setResourceType($resourceType);
45
    }
46
}
47