Completed
Push — master ( b408c6...9b0fcb )
by Michał
01:56
created

NoteFactory::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
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
}