Update   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 21 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Note;
6
7
final class Update extends Base
8
{
9 3
    /**
10
     * @param array<string> $input
11 3
     */
12 2
    public function update(array $input, int $noteId): object
13 2
    {
14 1
        $note = $this->getOneFromDb($noteId);
15
        $data = json_decode((string) json_encode($input), false);
16 2
        if (isset($data->name)) {
17 1
            $note->updateName(self::validateNoteName($data->name));
18
        }
19 2
        if (isset($data->description)) {
20
            $note->updateDescription($data->description);
21 2
        }
22 2
        $note->updateUpdatedAt(date('Y-m-d H:i:s'));
23 2
        /** @var Note $notes */
24
        $response = $this->noteRepository->update($note);
25 2
        if (self::isRedisEnabled() === true) {
26 2
            $this->saveInCache($response->getId(), $response->toJson());
27
        }
28
        if (self::isLoggerEnabled() === true) {
29 2
            $this->loggerService->setInfo('The note with the ID ' . $response->getId() . ' has updated successfully.');
30
        }
31
32
        return $response->toJson();
33
    }
34
}
35