Completed
Pull Request — master (#297)
by
unknown
07:01
created

GraphNode::getID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SRF\Graph;
4
5
class GraphNode {
6
	private $id;
7
	private $label = [];
8
	private $parent = [];
9
10
	/**
11
	 * @var string $id : Node ID including namespace
12
	 */
13 1
	public function __construct( $id ) {
14 1
		$this->id = $id;
15 1
	}
16
17
	/**
18
	 * @param integer $labelIndex : label index
19
	 * @param string $label : a label, e.g. Display Title, used instead of $id. Left align (\l) from label2 onwards
20
	 */
21 1
	public function addLabel( $labelIndex, $label ) {
22
23 1
		if ( $labelIndex == 1 ) {
24
			// label1 is always single value!
25 1
			$this->label[$labelIndex] = $label;
26
		} else {
27
			// append to support multivalue
28
			// (a simple ".=" failed with offset error during testing)
29 1
			$this->label[$labelIndex] = array_key_exists($labelIndex, $this->label) ? $this->label[$labelIndex] . $label . "\l" : $label . "\l";
30
		}
31 1
	}
32
33
	/**
34
	 * @var string $predicate : the "predicate" linking an object to a subject
35
	 * @var srting $object : the object, linked to this node
36
	 */
37 1
	public function addParentNode( $predicate, $object ) {
38 1
		$this->parent[] = [
39 1
			"predicate" => $predicate,
40 1
			"object"    => $object
41
		];
42 1
	}
43
44
	/**
45
	 * @return array Of parent nodes
46
	 */
47 1
	public function getParentNode() {
48 1
		return $this->parent;
49
	}
50
51
	/**
52
	 * @return array: of labels
0 ignored issues
show
Documentation introduced by
The doc-type array: could not be parsed: Unknown type name "array:" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
53
	 */
54
	public function getLabels() {
55
		return $this->label;
56
	}
57
58 1
	public function getLabel( $labelIndex ) {
59 1
		return $this->label[$labelIndex];
60
	}
61
62 1
	public function getID() {
63 1
		return $this->id;
64
	}
65
66
}