Passed
Push — master ( 204e2b...dee98e )
by Gallice
03:34
created

StepFactory::create()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 16
cp 0
rs 8.8571
nc 10
cc 6
eloc 13
nop 1
crap 42
1
<?php
2
3
namespace Tgallice\Wit;
4
5
use Tgallice\Wit\Exception\InvalidStepException;
6
use Tgallice\Wit\Model\Step;
7
use Tgallice\Wit\Model\Step\Action;
8
use Tgallice\Wit\Model\Step\Merge;
9
use Tgallice\Wit\Model\Step\Message;
10
use Tgallice\Wit\Model\Step\Stop;
11
12
class StepFactory
13
{
14
    public static function create(array $step)
15
    {
16
        $type = isset($step['type']) ? $step['type'] : null;
17
18
        switch ($type) {
19
            case Step::TYPE_ACTION:
20
                return self::createActionStep($step);
21
            case Step::TYPE_MESSAGE:
22
                return self::createMessageStep($step);
23
            case Step::TYPE_MERGE:
24
                return self::createMergeStep($step);
25
            case Step::TYPE_STOP:
26
                return self::createStopStep($step);
27
            default:
28
                throw new InvalidStepException('Invalid Step', $step);
29
        }
30
    }
31
32
    /**
33
     * @param array $step
34
     *
35
     * @return Action
36
     */
37
    public static function createActionStep(array $step)
38
    {
39
        return new Action($step['action'], $step['confidence']);
40
    }
41
42
    /**
43
     * @param array $step
44
     *
45
     * @return Merge
46
     */
47
    public static function createMergeStep(array $step)
48
    {
49
        return new Merge($step['entities'], $step['confidence']);
50
    }
51
52
    /**
53
     * @param array $step
54
     *
55
     * @return Message
56
     */
57
    public static function createMessageStep(array $step)
58
    {
59
        return new Message($step['msg'], $step['confidence']);
60
    }
61
62
    /**
63
     * @param array $step
64
     *
65
     * @return Stop
66
     */
67
    public static function createStopStep(array $step)
68
    {
69
        return new Stop($step['confidence']);
70
    }
71
}
72