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

JSONDomainEventFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
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
}