Update::update()   A
last analyzed

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 16
nop 2
dl 0
loc 21
ccs 12
cts 12
cp 1
crap 5
rs 9.5222
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