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

StepNode::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 14
cts 14
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 3
nop 5
crap 3
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
use Behat\Gherkin\Exception\NodeException;
14
15
/**
16
 * Represents Gherkin Step.
17
 *
18
 * @author Konstantin Kudryashov <[email protected]>
19
 */
20
class StepNode implements NodeInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    private $keyword;
26
    /**
27
     * @var string
28
     */
29
    private $keywordType;
30
    /**
31
     * @var string
32
     */
33
    private $text;
34
    /**
35
     * @var ArgumentInterface[]
36
     */
37
    private $arguments = array();
38
    /**
39
     * @var integer
40
     */
41
    private $line;
42
43
    /**
44
     * Initializes step.
45
     *
46
     * @param string              $keyword
47
     * @param string              $text
48
     * @param ArgumentInterface[] $arguments
49
     * @param integer             $line
50
     * @param string              $keywordType
51
     */
52 48
    public function __construct($keyword, $text, array $arguments, $line, $keywordType = null)
53
    {
54 48
        if (count($arguments) > 1) {
55 1
            throw new NodeException(sprintf(
56 1
                'Steps could have only one argument, but `%s %s` have %d.',
57 1
                $keyword,
58 1
                $text,
59 1
                count($arguments)
60 1
            ));
61
        }
62
63 47
        $this->keyword = $keyword;
64 47
        $this->text = $text;
65 47
        $this->arguments = $arguments;
66 47
        $this->line = $line;
67 47
        $this->keywordType = $keywordType ?: 'Given';
68 47
    }
69
70
    /**
71
     * Returns node type string
72
     *
73
     * @return string
74
     */
75 1
    public function getNodeType()
76
    {
77 1
        return 'Step';
78
    }
79
80
    /**
81
     * Returns step keyword in provided language (Given, When, Then, etc.).
82
     *
83
     * @return string
84
     *
85
     * @deprecated use getKeyword() instead
86
     */
87
    public function getType()
88
    {
89
        return $this->getKeyword();
90
    }
91
92
    /**
93
     * Returns step keyword in provided language (Given, When, Then, etc.).
94
     *
95
     * @return string
96
     *
97
     */
98 19
    public function getKeyword()
99
    {
100 19
        return $this->keyword;
101
    }
102
103
    /**
104
     * Returns step type keyword (Given, When, Then, etc.).
105
     *
106
     * @return string
107
     */
108 44
    public function getKeywordType()
109
    {
110 44
        return $this->keywordType;
111
    }
112
113
    /**
114
     * Returns step text.
115
     *
116
     * @return string
117
     */
118 19
    public function getText()
119
    {
120 19
        return $this->text;
121
    }
122
123
    /**
124
     * Checks if step has arguments.
125
     *
126
     * @return Boolean
127
     */
128
    public function hasArguments()
129
    {
130
        return 0 < count($this->arguments);
131
    }
132
133
    /**
134
     * Returns step arguments.
135
     *
136
     * @return ArgumentInterface[]
137
     */
138 17
    public function getArguments()
139
    {
140 17
        return $this->arguments;
141
    }
142
143
    /**
144
     * Returns step declaration line number.
145
     *
146
     * @return integer
147
     */
148 19
    public function getLine()
149
    {
150 19
        return $this->line;
151
    }
152
}
153