Completed
Push — master ( 5fca0d...2a987b )
by Quim
02:16
created

JSONDomainEventFactory::create()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace Cmp\Queues\Domain\Event;
4
5
use Cmp\Queues\Domain\Event\Exception\InvalidJSONDomainEventException;
6
use Cmp\Queues\Domain\Queue\JSONMessageFactory;
7
8
class JSONDomainEventFactory implements JSONMessageFactory
9
{
10
    /**
11
     * @param $json
12
     * @return DomainEvent
13
     * @throws InvalidJSONDomainEventException
14
     */
15
    public function create($json)
16
    {
17
        try {
18
            $domainEventArray = json_decode($json, true);
19
            return new DomainEvent($domainEventArray['origin'], $domainEventArray['name'], $domainEventArray['occurredOn'], $domainEventArray['body']);
20
        } catch (\Exception $e) {
21
            throw new InvalidJSONDomainEventException();
22
        }
23
    }
24
25
}