Completed
Pull Request — master (#150)
by Matt
02:41
created

RuleNode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
namespace Behat\Gherkin\Node;
4
5
class RuleNode implements KeywordNodeInterface
6
{
7
8
    /**
9
     * @var string
10
     */
11
    private $title;
12
    /**
13
     * @var int
14
     */
15
    private $line;
16
    /**
17
     * @var null|BackgroundNode
18
     */
19
    private $background;
20
    /**
21
     * @var ExampleNode[]
22
     */
23
    private $examples = array();
24
25
    /**
26
     * Initializes Rule
27
     *
28
     * @param string $title
29
     * @param integer $line
30
     * @param BackgroundNode|null $background
31
     * @param ExampleNode[] $examples
32
     */
33 2
    public function __construct($title, $line, BackgroundNode $background = null, array $examples = array())
34
    {
35 2
        $this->title = $title;
36 2
        $this->line = $line;
37 2
        $this->background = $background;
38
39 2
        array_walk($examples, array($this, 'addExample'));
40 2
    }
41
42 2
    private function addExample(ExampleNode $example)
43
    {
44 2
        $this->examples[] = $example;
45 2
    }
46
47
    /**
48
     * Returns node type string
49
     *
50
     * @return string
51
     */
52
    public function getNodeType()
53
    {
54
        return 'Rule';
55
    }
56
57
    /**
58
     * Returns node keyword.
59
     *
60
     * @return string
61
     */
62
    public function getKeyword()
63
    {
64
        return $this->getNodeType();
65
    }
66
67
    /**
68
     * Returns node title.
69
     *
70
     * @return null|string
71
     */
72 1
    public function getTitle()
73
    {
74 1
        return $this->title;
75
    }
76
77
    /**
78
     * Returns feature declaration line number.
79
     *
80
     * @return integer
81
     */
82 1
    public function getLine()
83
    {
84 1
        return $this->line;
85
    }
86
87
    /**
88
     * Returns rule background.
89
     *
90
     * @return null|BackgroundNode
91
     */
92
    public function getBackground()
93
    {
94
        return $this->background;
95
    }
96
97
    /**
98
     * Returns rule examples
99
     *
100
     * @return ExampleNode[]
101
     */
102 1
    public function getExamples()
103
    {
104 1
        return $this->examples;
105
    }
106
}
107