Completed
Pull Request — master (#5)
by Quim
05:12 queued 02:42
created

JSONTaskFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 14
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 Domain\Task;
4
5
use Domain\Queue\JSONMessageFactory;
6
use Domain\Task\Exception\InvalidJSONTaskException;
7
8
class JSONTaskFactory implements JSONMessageFactory
9
{
10
11
    public function create($json)
12
    {
13
        try {
14
            $taskArray = json_decode($json, true);
15
            return new Task($taskArray['name'], $taskArray['body'], $taskArray['delay']);
16
        } catch (\Exception $e) {
17
            throw new InvalidJSONTaskException();
18
        }
19
    }
20
21
}