Create::create()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 5
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Note;
6
7
use App\Exception\NoteException;
8
9
class Create extends BaseNoteService
10
{
11
    public function create($input)
12
    {
13
        $note = new \stdClass();
14
        $data = json_decode(json_encode($input), false);
15
        if (!isset($data->name)) {
16
            throw new NoteException('Invalid data: name is required.', 400);
17
        }
18
        $note->name = self::validateNoteName($data->name);
19
        $note->description = null;
20
        if (isset($data->description)) {
21
            $note->description = $data->description;
22
        }
23
        $notes = $this->noteRepository->createNote($note);
24
        if (self::isRedisEnabled() === true) {
25
            $this->saveInCache($notes->id, $notes);
26
        }
27
28
        return $notes;
29
    }
30
}
31