Update   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B update() 0 20 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Note;
6
7
use App\Exception\NoteException;
8
9
class Update extends BaseNoteService
10
{
11
    public function update($input, int $noteId)
12
    {
13
        $note = $this->getOneFromDb($noteId);
14
        $data = json_decode(json_encode($input), false);
15
        if (!isset($data->name) && !isset($data->description)) {
16
            throw new NoteException('Enter the data to update the note.', 400);
17
        }
18
        if (isset($data->name)) {
19
            $note->name = self::validateNoteName($data->name);
20
        }
21
        if (isset($data->description)) {
22
            $note->description = $data->description;
23
        }
24
        $notes = $this->noteRepository->updateNote($note);
25
        if (self::isRedisEnabled() === true) {
26
            $this->saveInCache($notes->id, $notes);
27
        }
28
29
        return $notes;
30
    }
31
}
32