Total Complexity | 6 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
14 | trait HasModel |
||
15 | { |
||
16 | /** |
||
17 | * The model instance. |
||
18 | * |
||
19 | * @var Model |
||
20 | */ |
||
21 | protected $model; |
||
22 | |||
23 | /** |
||
24 | * Set the model. |
||
25 | * |
||
26 | * @param Model $model |
||
27 | * |
||
28 | * @return static |
||
29 | * @throws JsonApiFakerException |
||
30 | */ |
||
31 | public function setModel($model) |
||
32 | 21 | { |
|
33 | if ($model == null) { |
||
34 | 21 | throw new JsonApiFakerException(Messages::ERROR_MODEL_NOT_NULL); |
|
35 | 2 | } |
|
36 | if (is_a($model, Model::class) === false) { |
||
37 | throw new JsonApiFakerException(Messages::ERROR_MODEL_NOT_OBJECT); |
||
38 | 19 | } |
|
39 | |||
40 | 19 | $this->model = $model; |
|
41 | |||
42 | return $this; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Get the model. |
||
47 | * |
||
48 | * @return Model |
||
49 | */ |
||
50 | 2 | public function getModel() |
|
53 | 1 | } |
|
54 | |||
55 | /** |
||
56 | 1 | * Get the value of the model's primary key. |
|
57 | * |
||
58 | * @return mixed |
||
59 | * @throws JsonApiFakerException |
||
60 | */ |
||
61 | public function getKey() |
||
68 | } |
||
69 | } |
||
70 |