IsResource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 3
A setValues() 0 5 1
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