Completed
Push — master ( 5f432b...5d5b15 )
by Jens
15:50 queued 05:48
created

TransitionRenderer::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 0
cts 16
cp 0
rs 9.3142
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 1
crap 12
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
        foreach ($state->getTransitions() as $transition) {
24
            /**
25
             * @var State $targetState
26
             */
27
            $targetState = $transition->getObj();
28
            if ($targetState->getKey() === $state->getKey()) {
29
                $graph .= '  edge[dir="back",style="solid",color="' . $color . '"] state_'
30
                    . $state->getKey() . ' -> state_' . $state->getKey()  . ';' . PHP_EOL;
31
            } else {
32
                $graph .= '  edge[dir="forward",style="solid",color="' . $color . '"] state_'
33
                    . $state->getKey() . ' -> state_' . $targetState->getKey() . ' ;' . PHP_EOL;
34
            }
35
        }
36
37
        return $graph;
38
    }
39
}
40