Create::create()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 4
rs 9.8666
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