Conditions | 4 |
Paths | 5 |
Total Lines | 18 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | 3 | public function create(array $input): object |
|
15 | 3 | { |
|
16 | 1 | $data = json_decode((string) json_encode($input), false); |
|
17 | if (!isset($data->name)) { |
||
18 | 2 | throw new \App\Exception\NoteException('Invalid data: name is required.', 400); |
|
19 | 2 | } |
|
20 | 1 | $note = new Note(); |
|
21 | 1 | $note->updateName(self::validateNoteName($data->name)); |
|
22 | 1 | $desc = isset($data->description) ? $data->description : null; |
|
23 | $note->updateDescription($desc); |
||
24 | 1 | $note->updateCreatedAt(date('Y-m-d H:i:s')); |
|
25 | 1 | /** @var Note $note */ |
|
26 | 1 | $response = $this->noteRepository->create($note); |
|
27 | if (self::isRedisEnabled() === true) { |
||
28 | $this->saveInCache($response->getId(), $response->toJson()); |
||
29 | 1 | } |
|
30 | |||
31 | return $response->toJson(); |
||
32 | } |
||
34 |