StepFactory   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 70
c 0
b 0
f 0
rs 10
ccs 23
cts 23
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 17 6
A getEntitiesFromStepData() 0 4 2
A createActionStep() 0 4 1
A createMergeStep() 0 4 1
A createMessageStep() 0 4 1
A createStopStep() 0 4 1
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 9
    public static function create(array $step)
15
    {
16 9
        $type = isset($step['type']) ? $step['type'] : null;
17
18
        switch ($type) {
19 9
            case Step::TYPE_ACTION:
20 2
                return self::createActionStep($step);
21 9
            case Step::TYPE_MESSAGE:
22 2
                return self::createMessageStep($step);
23 9
            case Step::TYPE_MERGE:
24 4
                return self::createMergeStep($step);
25 8
            case Step::TYPE_STOP:
26 7
                return self::createStopStep($step);
27 1
            default:
28 1
                throw new InvalidStepException('Invalid Step', $step);
29 1
        }
30
    }
31
32
    /**
33
     * @param array $step
34
     *
35
     * @return array
36
     */
37 9
    private static function getEntitiesFromStepData(array $step = [])
38
    {
39 9
        return isset($step['entities']) ? $step['entities'] : [];
40
    }
41
42
    /**
43
     * @param array $step
44
     *
45
     * @return Action
46
     */
47 3
    public static function createActionStep(array $step)
48
    {
49 3
        return new Action($step['action'], $step['confidence'], self::getEntitiesFromStepData($step));
50
    }
51
52
    /**
53
     * @param array $step
54
     *
55
     * @return Merge
56
     */
57 5
    public static function createMergeStep(array $step)
58
    {
59 5
        return new Merge(self::getEntitiesFromStepData($step), $step['confidence']);
60
    }
61
62
    /**
63
     * @param array $step
64
     *
65
     * @return Message
66
     */
67 3
    public static function createMessageStep(array $step)
68
    {
69 3
        return new Message($step['msg'], $step['confidence'], self::getEntitiesFromStepData($step));
70
    }
71
72
    /**
73
     * @param array $step
74
     *
75
     * @return Stop
76
     */
77 8
    public static function createStopStep(array $step)
78
    {
79 8
        return new Stop($step['confidence']);
80
    }
81
}
82