Completed
Push — master ( de7e19...857622 )
by Ron
02:42
created

DiffStorageStoreRow::getLocal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace DataDiff;
3
4
use Exception;
5
6
class DiffStorageStoreRow implements DiffStorageStoreRowInterface {
7
	/** @var array */
8
	private $data = [];
9
	/** @var DiffStorageStoreRowData */
10
	private $localData;
11
	/** @var DiffStorageStoreRowData */
12
	private $foreignRowData;
13
14
	/**
15
	 * @param array $localData
16
	 * @param array $foreignData
17
	 * @param array $keys
18
	 * @param array $valueKeys
19
	 * @param array $converter
20
	 */
21
	public function __construct(array $localData = null, array $foreignData = null, array $keys, array $valueKeys, array $converter) {
22
		if($localData !== null) {
23
			$this->data = $localData;
24
		} elseif($foreignData !== null) {
25
			$this->data = $foreignData;
26
		}
27
		$localData = is_array($localData) ? $localData : [];
28
		$foreignData = is_array($foreignData) ? $foreignData : [];
29
		$this->localData = new DiffStorageStoreRowData($localData, $foreignData, $keys, $valueKeys, $converter);
30
		$this->foreignRowData = new DiffStorageStoreRowData($foreignData, $localData, $keys, $valueKeys, $converter);
31
	}
32
33
	/**
34
	 * @return DiffStorageStoreRowData
35
	 */
36
	public function getLocal() {
37
		return $this->localData;
38
	}
39
40
	/**
41
	 * @return DiffStorageStoreRowData
42
	 */
43
	public function getForeign() {
44
		return $this->foreignRowData;
45
	}
46
47
	/**
48
	 * `$options` are:
49
	 * * `keys`: Only these keys are considered and returned
50
	 * * `ignore`: These keys are ignored and omitted
51
	 *
52
	 * @param array $options
53
	 * @return array
54
	 */
55
	public function getData(array $options = []) {
56
		return $this->localData->getData($options);
57
	}
58
59
	/**
60
	 * `$options` are:
61
	 * * `keys`: Only these keys are considered and returned
62
	 * * `ignore`: These keys are ignored and omitted
63
	 *
64
	 * @param array $options
65
	 * @return array
66
	 */
67
	public function getForeignData(array $options = []) {
68
		return $this->foreignRowData->getData($options);
69
	}
70
71
	/**
72
	 * @param array $fields
73
	 * @return array
74
	 */
75
	public function getDiff(array $fields = null) {
76
		return $this->localData->getDiff($fields);
77
	}
78
79
	/**
80
	 * @param array $fields
81
	 * @param mixed $format
82
	 * @return array
83
	 * @throws Exception
84
	 */
85
	public function getDiffFormatted(array $fields = null, $format = null) {
86
		return $this->localData->getDiffFormatted($fields, $format);
87
	}
88
89
	/**
90
	 * @return mixed
91
	 */
92
	public function jsonSerialize() {
93
		return $this->data;
94
	}
95
96
	/**
97
	 * @param mixed $offset
98
	 * @return boolean true on success or false on failure.
99
	 */
100
	public function offsetExists($offset) {
101
		return array_key_exists($offset, $this->data);
102
	}
103
104
	/**
105
	 * @param mixed $offset
106
	 * @return mixed
107
	 */
108
	public function offsetGet($offset) {
109
		if($this->offsetExists($offset)) {
110
			return $this->data[$offset];
111
		}
112
		return null;
113
	}
114
115
	/**
116
	 * @param mixed $offset
117
	 * @param mixed $value
118
	 * @return void
119
	 */
120
	public function offsetSet($offset, $value) {
121
		$this->data[$offset] = $value;
122
	}
123
124
	/**
125
	 * @param mixed $offset
126
	 * @return void
127
	 */
128
	public function offsetUnset($offset) {
129
		if($this->offsetExists($offset)) {
130
			unset($this->data[$offset]);
131
		}
132
	}
133
}
134