StepInfo   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
dl 0
loc 111
ccs 33
cts 33
cp 1
rs 10
c 1
b 0
f 0
wmc 16

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getImage() 0 3 1
A hasDefaultImage() 0 3 1
A __construct() 0 4 1
A getStep() 0 3 1
A annotate() 0 20 4
A getAnnotations() 0 9 4
A getImageName() 0 3 1
A getStepNumber() 0 3 1
A getName() 0 5 2
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File\Info;
6
7
use Ktomk\Pipelines\File\File;
8
use Ktomk\Pipelines\File\ParseException;
9
use Ktomk\Pipelines\File\Pipeline\Step;
10
11
/**
12
 * info about a step (for show output)
13
 */
14
final class StepInfo
15
{
16
    const NO_NAME = 'no-name';
17
    const CHAR_ARTIFACTS = 'A';
18
    const CHAR_CONDITION = 'C';
19
    const CHAR_MANUAL = 'M';
20
21
    /**
22
     * @var Step
23
     */
24
    private $step;
25
    private $index;
26
27
    /**
28
     * @param Step $step
29
     * @param int $index (zero-based)
30
     */
31 4
    public function __construct(Step $step, $index)
32
    {
33 4
        $this->step = $step;
34 4
        $this->index = (int)$index;
35
    }
36
37
    /**
38
     * @param string $string
39
     * @param string $separator [optional]
40
     * @param mixed $errorFree
41
     *
42
     * @return string
43
     */
44 7
    public function annotate($string, $separator = null, &$errorFree = null)
45
    {
46 7
        null === $separator && $separator = ' *';
47 7
        $errorFree = true;
48
49 7
        $buffer = (string)$string;
50
51
        try {
52 7
            $annotations = $this->getAnnotations();
53 1
        } catch (ParseException $parseException) {
54 1
            $errorFree = false;
55
56 1
            return $buffer . ' ERROR ' . $parseException->getParseMessage();
57
        }
58
59 6
        if ($annotations) {
60 4
            $buffer .= $separator . implode('', $annotations);
61
        }
62
63 6
        return $buffer;
64
    }
65
66
    /**
67
     * @return array
68
     */
69 4
    public function getAnnotations()
70
    {
71 4
        $annotations = array();
72
73 4
        $this->step->getArtifacts() && $annotations[] = self::CHAR_ARTIFACTS;
74 4
        $this->step->getCondition() && $annotations[] = self::CHAR_CONDITION;
75 4
        $this->step->isManual() && $annotations[] = self::CHAR_MANUAL;
76
77 4
        return $annotations;
78
    }
79
80
    /**
81
     * @return \Ktomk\Pipelines\File\Image
82
     */
83 2
    public function getImage()
84
    {
85 2
        return $this->step->getImage();
86
    }
87
88
    /**
89
     * @return string
90
     */
91 2
    public function getImageName()
92
    {
93 2
        return $this->step->getImage()->getName();
94
    }
95
96
    /**
97
     * @return string
98
     */
99 4
    public function getName()
100
    {
101 4
        $name = $this->step->getName();
102
103 4
        return null === $name ? self::NO_NAME : sprintf('"%s"', $name);
104
    }
105
106 2
    public function getStep()
107
    {
108 2
        return $this->step;
109
    }
110
111
    /**
112
     * @return int
113
     */
114 2
    public function getStepNumber()
115
    {
116 2
        return $this->index + 1;
117
    }
118
119
    /**
120
     * @return bool
121
     */
122 2
    public function hasDefaultImage()
123
    {
124 2
        return File::DEFAULT_IMAGE === $this->getImageName();
125
    }
126
}
127