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

JSONTaskFactory::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 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
}