Total Complexity | 4 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
6 | trait Creatable |
||
7 | { |
||
8 | protected $createPath; |
||
9 | |||
10 | /** |
||
11 | * Post a resource and update this parameters with the response from the API |
||
12 | * @return $this |
||
13 | * @throws ResourceNotCreated |
||
14 | */ |
||
15 | |||
16 | public function create() |
||
17 | { |
||
18 | $path = $this->getCreatePath() ?? $this->getResourceName(); |
||
|
|||
19 | |||
20 | $response = $this->postRequest($path); |
||
21 | $this->setAttributes([]); |
||
22 | $this->setValues($response); |
||
23 | if ($this->getClient()->getLastResponse()->getStatusCode() !== 201) { |
||
24 | throw new ResourceNotCreated($this->getClient()->getLastResponse()->getBody()); |
||
25 | } |
||
26 | return $this; |
||
27 | } |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Get the create path of the current object |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | |||
36 | public function getCreatePath() |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Set the save path of the current object |
||
43 | * |
||
44 | * @param $path |
||
45 | * @return mixed |
||
46 | */ |
||
47 | |||
48 | public function setCreatePath($path) |
||
51 | } |
||
52 | |||
53 | } |