Completed
Pull Request — master (#7)
by Michał
01:58
created

NoteFactory::fromJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Barenote\Factory;
3
4
use Barenote\Domain\Identity\CategoryId;
5
use Barenote\Domain\Identity\NoteId;
6
use Barenote\Domain\Identity\UserId;
7
use Barenote\Domain\Note;
8
9
class NoteFactory
10
{
11
    public static function fromJson($payload)
12
    {
13
        return static::fromArray(json_decode($payload, true));
14
    }
15
16
    public static function fromArray(array $data)
17
    {
18
        return (new Note())
19
            ->setId(new NoteId($data['id']))
20
            ->setCategoryId(new CategoryId($data['category_id']))
21
            ->setUserId(new UserId($data['user_id']))
22
            ->setContent($data['content'])
23
            ->setTitle($data['title']);
24
    }
25
}