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 | 66 | public function setModel($model) |
|
32 | { |
||
33 | 66 | if ($model == null) { |
|
34 | 6 | throw new JsonApiFakerException(Messages::ERROR_MODEL_NOT_NULL); |
|
35 | } |
||
36 | 60 | if (is_a($model, Model::class) === false) { |
|
37 | 3 | throw new JsonApiFakerException(Messages::ERROR_MODEL_NOT_OBJECT); |
|
38 | } |
||
39 | |||
40 | 57 | $this->model = $model; |
|
41 | |||
42 | 57 | return $this; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Get the model. |
||
47 | * |
||
48 | * @return Model |
||
49 | */ |
||
50 | 27 | public function getModel() |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Get the value of the model's primary key. |
||
57 | * |
||
58 | * @return mixed |
||
59 | * @throws JsonApiFakerException |
||
60 | */ |
||
61 | 6 | public function getKey() |
|
68 | } |
||
69 | } |
||
70 |