Completed
Pull Request — master (#7)
by Michał
06:27 queued 04:37
created

NoteFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 17
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromJson() 0 4 1
A fromArray() 0 9 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
}