Completed
Push — master ( 3f293a...dfbdc5 )
by Konstantin
02:30
created

OutlineNode::getNodeType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Behat Gherkin.
5
 * (c) Konstantin Kudryashov <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Behat\Gherkin\Node;
12
13
/**
14
 * Represents Gherkin Outline.
15
 *
16
 * @author Konstantin Kudryashov <[email protected]>
17
 */
18
class OutlineNode implements ScenarioInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    private $title;
24
    /**
25
     * @var string[]
26
     */
27
    private $tags;
28
    /**
29
     * @var StepNode[]
30
     */
31
    private $steps;
32
    /**
33
     * @var ExampleTableNode
34
     */
35
    private $table;
36
    /**
37
     * @var string
38
     */
39
    private $keyword;
40
    /**
41
     * @var integer
42
     */
43
    private $line;
44
    /**
45
     * @var null|ExampleNode[]
46
     */
47
    private $examples;
48
49
    /**
50
     * Initializes outline.
51
     *
52
     * @param null|string      $title
53
     * @param string[]         $tags
54
     * @param StepNode[]       $steps
55
     * @param ExampleTableNode $table
56
     * @param string           $keyword
57
     * @param integer          $line
58
     */
59 34
    public function __construct(
60
        $title,
61
        array $tags,
62
        array $steps,
63
        ExampleTableNode $table,
64
        $keyword,
65
        $line
66
    ) {
67 34
        $this->title = $title;
68 34
        $this->tags = $tags;
69 34
        $this->steps = $steps;
70 34
        $this->table = $table;
71 34
        $this->keyword = $keyword;
72 34
        $this->line = $line;
73 34
    }
74
75
    /**
76
     * Returns node type string
77
     *
78
     * @return string
79
     */
80
    public function getNodeType()
81
    {
82
        return 'Outline';
83
    }
84
85
    /**
86
     * Returns outline title.
87
     *
88
     * @return null|string
89
     */
90 7
    public function getTitle()
91
    {
92 7
        return $this->title;
93
    }
94
95
    /**
96
     * Checks if outline is tagged with tag.
97
     *
98
     * @param string $tag
99
     *
100
     * @return Boolean
101
     */
102
    public function hasTag($tag)
103
    {
104
        return in_array($tag, $this->getTags());
105
    }
106
107
    /**
108
     * Checks if outline has tags (both inherited from feature and own).
109
     *
110
     * @return Boolean
111
     */
112 1
    public function hasTags()
113
    {
114 1
        return 0 < count($this->getTags());
115
    }
116
117
    /**
118
     * Returns outline tags (including inherited from feature).
119
     *
120
     * @return string[]
121
     */
122 3
    public function getTags()
123
    {
124 3
        return $this->tags;
125
    }
126
127
    /**
128
     * Checks if outline has steps.
129
     *
130
     * @return Boolean
131
     */
132 1
    public function hasSteps()
133
    {
134 1
        return 0 < count($this->steps);
135
    }
136
137
    /**
138
     * Returns outline steps.
139
     *
140
     * @return StepNode[]
141
     */
142 6
    public function getSteps()
143
    {
144 6
        return $this->steps;
145
    }
146
147
    /**
148
     * Checks if outline has examples.
149
     *
150
     * @return Boolean
151
     */
152 10
    public function hasExamples()
153
    {
154 10
        return 0 < count($this->table->getColumnsHash());
155
    }
156
157
    /**
158
     * Returns examples table.
159
     *
160
     * @return ExampleTableNode
161
     */
162 5
    public function getExampleTable()
163
    {
164 5
        return $this->table;
165
    }
166
167
    /**
168
     * Returns list of examples for the outline.
169
     *
170
     * @return ExampleNode[]
171
     */
172 5
    public function getExamples()
173
    {
174 5
        return $this->examples = $this->examples ? : $this->createExamples();
175
    }
176
177
    /**
178
     * Returns outline keyword.
179
     *
180
     * @return string
181
     */
182 2
    public function getKeyword()
183
    {
184 2
        return $this->keyword;
185
    }
186
187
    /**
188
     * Returns outline declaration line number.
189
     *
190
     * @return integer
191
     */
192 15
    public function getLine()
193
    {
194 15
        return $this->line;
195
    }
196
197
    /**
198
     * Creates examples for this outline using examples table.
199
     *
200
     * @return ExampleNode[]
201
     */
202 5
    protected function createExamples()
203
    {
204 5
        $examples = array();
205 5
        foreach ($this->table->getColumnsHash() as $rowNum => $row) {
206 3
            $examples[] = new ExampleNode(
207 3
                $this->table->getRowAsString($rowNum + 1),
208 3
                $this->tags,
209 3
                $this->getSteps(),
210 3
                $row,
211 3
                $this->table->getRowLine($rowNum + 1),
212 3
                $this->getTitle()
213 3
            );
214 5
        }
215
216 5
        return $examples;
217
    }
218
}
219