Skip to content

Commit 64a793b

Browse files
committed
Rename GraphNode internal items to fields
1 parent 73ed914 commit 64a793b

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

src/GraphNode/GraphNode.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
3333
protected static $graphNodeMap = [];
3434

3535
/**
36-
* The items contained in the collection.
36+
* The fields contained in the node.
3737
*
3838
* @var array
3939
*/
40-
protected $items = [];
40+
protected $fields = [];
4141

4242
/**
4343
* Init this Graph object.
@@ -46,7 +46,7 @@ class GraphNode implements \ArrayAccess, \Countable, \IteratorAggregate
4646
*/
4747
public function __construct(array $data = [])
4848
{
49-
$this->items = $this->castItems($data);
49+
$this->fields = $this->castFields($data);
5050
}
5151

5252
/**
@@ -59,8 +59,8 @@ public function __construct(array $data = [])
5959
*/
6060
public function getField($name, $default = null)
6161
{
62-
if (isset($this->items[$name])) {
63-
return $this->items[$name];
62+
if (isset($this->fields[$name])) {
63+
return $this->fields[$name];
6464
}
6565

6666
return $default;
@@ -73,21 +73,21 @@ public function getField($name, $default = null)
7373
*/
7474
public function getFieldNames()
7575
{
76-
return array_keys($this->items);
76+
return array_keys($this->fields);
7777
}
7878

7979
/**
80-
* Get all of the items in the collection.
80+
* Get all of the fields in the node.
8181
*
8282
* @return array
8383
*/
8484
public function all()
8585
{
86-
return $this->items;
86+
return $this->fields;
8787
}
8888

8989
/**
90-
* Get the collection of items as a plain array.
90+
* Get all fields as a plain array.
9191
*
9292
* @return array
9393
*/
@@ -99,51 +99,51 @@ public function asArray()
9999
}
100100

101101
return $value;
102-
}, $this->items);
102+
}, $this->fields);
103103
}
104104

105105
/**
106-
* Run a map over each of the items.
106+
* Run a map over each field.
107107
*
108108
* @param \Closure $callback
109109
*
110110
* @return static
111111
*/
112112
public function map(\Closure $callback)
113113
{
114-
return new static(array_map($callback, $this->items, array_keys($this->items)));
114+
return new static(array_map($callback, $this->fields, array_keys($this->fields)));
115115
}
116116

117117
/**
118-
* Get the collection of items as JSON.
118+
* Get all fields as JSON.
119119
*
120120
* @param int $options
121121
*
122122
* @return string
123123
*/
124124
public function asJson($options = 0)
125125
{
126-
return json_encode($this->uncastItems(), $options);
126+
return json_encode($this->uncastFields(), $options);
127127
}
128128

129129
/**
130-
* Count the number of items in the collection.
130+
* Count the number of fields in the collection.
131131
*
132132
* @return int
133133
*/
134134
public function count()
135135
{
136-
return count($this->items);
136+
return count($this->fields);
137137
}
138138

139139
/**
140-
* Get an iterator for the items.
140+
* Get an iterator for the fields.
141141
*
142142
* @return \ArrayIterator
143143
*/
144144
public function getIterator()
145145
{
146-
return new \ArrayIterator($this->items);
146+
return new \ArrayIterator($this->fields);
147147
}
148148

149149
/**
@@ -155,7 +155,7 @@ public function getIterator()
155155
*/
156156
public function offsetExists($key)
157157
{
158-
return array_key_exists($key, $this->items);
158+
return array_key_exists($key, $this->fields);
159159
}
160160

161161
/**
@@ -167,7 +167,7 @@ public function offsetExists($key)
167167
*/
168168
public function offsetGet($key)
169169
{
170-
return $this->items[$key];
170+
return $this->fields[$key];
171171
}
172172

173173
/**
@@ -181,9 +181,9 @@ public function offsetGet($key)
181181
public function offsetSet($key, $value)
182182
{
183183
if (is_null($key)) {
184-
$this->items[] = $value;
184+
$this->fields[] = $value;
185185
} else {
186-
$this->items[$key] = $value;
186+
$this->fields[$key] = $value;
187187
}
188188
}
189189

@@ -196,7 +196,7 @@ public function offsetSet($key, $value)
196196
*/
197197
public function offsetUnset($key)
198198
{
199-
unset($this->items[$key]);
199+
unset($this->fields[$key]);
200200
}
201201

202202
/**
@@ -211,51 +211,51 @@ public function __toString()
211211

212212
/**
213213
* Iterates over an array and detects the types each node
214-
* should be cast to and returns all the items as an array.
214+
* should be cast to and returns all the fields as an array.
215215
*
216216
* @TODO Add auto-casting to AccessToken entities.
217217
*
218218
* @param array $data the array to iterate over
219219
*
220220
* @return array
221221
*/
222-
public function castItems(array $data)
222+
public function castFields(array $data)
223223
{
224-
$items = [];
224+
$fields = [];
225225

226226
foreach ($data as $k => $v) {
227227
if ($this->shouldCastAsDateTime($k)
228228
&& (is_numeric($v)
229229
|| $this->isIso8601DateString($v))
230230
) {
231-
$items[$k] = $this->castToDateTime($v);
231+
$fields[$k] = $this->castToDateTime($v);
232232
} elseif ($k === 'birthday') {
233-
$items[$k] = $this->castToBirthday($v);
233+
$fields[$k] = $this->castToBirthday($v);
234234
} else {
235-
$items[$k] = $v;
235+
$fields[$k] = $v;
236236
}
237237
}
238238

239-
return $items;
239+
return $fields;
240240
}
241241

242242
/**
243243
* Uncasts any auto-casted datatypes.
244-
* Basically the reverse of castItems().
244+
* Basically the reverse of castFields().
245245
*
246246
* @return array
247247
*/
248-
public function uncastItems()
248+
public function uncastFields()
249249
{
250-
$items = $this->asArray();
250+
$fields = $this->asArray();
251251

252252
return array_map(function ($v) {
253253
if ($v instanceof \DateTime) {
254254
return $v->format(\DateTime::ISO8601);
255255
}
256256

257257
return $v;
258-
}, $items);
258+
}, $fields);
259259
}
260260

261261
/**

tests/GraphNode/GraphNodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testUncastingAGraphNodeWillUncastTheDateTimeObject()
103103
'some_collection' => $graphNodeOne,
104104
]);
105105

106-
$uncastArray = $graphNodeTwo->uncastItems();
106+
$uncastArray = $graphNodeTwo->uncastFields();
107107

108108
$this->assertEquals([
109109
'id' => '123',

0 commit comments

Comments
 (0)