Completed
Push — master ( 3f2d2e...78eab5 )
by Jens
09:03
created

TransitionRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 10
c 1
b 1
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 23 4
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Helper\State\Renderer;
7
8
use Commercetools\Core\Model\State\State;
9
10
class TransitionRenderer
11
{
12
    const COMMAND_COLOR = '#555555';
13
14
    /**
15
     * @param State $state
16
     * @return string
17
     */
18
    public function render(State $state)
19
    {
20
        $graph = '';
21
        $color = static::COMMAND_COLOR;
22
23
        if ($state->getTransitions()) {
24
            foreach ($state->getTransitions() as $transition) {
25
                /**
26
                 * @var State $targetState
27
                 */
28
                $targetState = $transition->getObj();
29
                if ($targetState->getKey() === $state->getKey()) {
30
                    $graph .= '  edge[dir="back",style="solid",color="' . $color . '"] state_'
31
                        . $state->getKey() . ' -> state_' . $state->getKey()  . ';' . PHP_EOL;
32
                } else {
33
                    $graph .= '  edge[dir="forward",style="solid",color="' . $color . '"] state_'
34
                        . $state->getKey() . ' -> state_' . $targetState->getKey() . ' ;' . PHP_EOL;
35
                }
36
            }
37
        }
38
39
        return $graph;
40
    }
41
}
42