Create   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service\Note;
6
7
use App\Entity\Note;
8
9
final class Create extends Base
10
{
11
    /**
12 3
     * @param array<string> $input
13
     */
14 3
    public function create(array $input): object
15 3
    {
16 1
        $data = json_decode((string) json_encode($input), false);
17
        if (!isset($data->name)) {
18 2
            throw new \App\Exception\NoteException('Invalid data: name is required.', 400);
19 2
        }
20 1
        $note = new Note();
21 1
        $note->updateName(self::validateNoteName($data->name));
22 1
        $desc = isset($data->description) ? $data->description : null;
23
        $note->updateDescription($desc);
24 1
        $note->updateCreatedAt(date('Y-m-d H:i:s'));
25 1
        /** @var Note $note */
26 1
        $response = $this->noteRepository->create($note);
27
        if (self::isRedisEnabled() === true) {
28
            $this->saveInCache($response->getId(), $response->toJson());
29 1
        }
30
31
        return $response->toJson();
32
    }
33
}
34