Create   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 19 4
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