Skip to content

Commit d2b7c59

Browse files
committed
Remove array access from GraphNode
1 parent c0e5c24 commit d2b7c59

File tree

5 files changed

+22
-84
lines changed

5 files changed

+22
-84
lines changed

src/GraphNode/GraphNode.php

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/**
2626
* @package Facebook
2727
*/
28-
class GraphNode implements \ArrayAccess, \IteratorAggregate
28+
class GraphNode implements \IteratorAggregate
2929
{
3030
/**
3131
* @var array maps object key names to Graph object types
@@ -112,59 +112,6 @@ public function getIterator()
112112
return new \ArrayIterator($this->fields);
113113
}
114114

115-
/**
116-
* Determine if an item exists at an offset.
117-
*
118-
* @param mixed $key
119-
*
120-
* @return bool
121-
*/
122-
public function offsetExists($key)
123-
{
124-
return array_key_exists($key, $this->fields);
125-
}
126-
127-
/**
128-
* Get an item at a given offset.
129-
*
130-
* @param mixed $key
131-
*
132-
* @return mixed
133-
*/
134-
public function offsetGet($key)
135-
{
136-
return $this->fields[$key];
137-
}
138-
139-
/**
140-
* Set the item at a given offset.
141-
*
142-
* @param mixed $key
143-
* @param mixed $value
144-
*
145-
* @return void
146-
*/
147-
public function offsetSet($key, $value)
148-
{
149-
if (is_null($key)) {
150-
$this->fields[] = $value;
151-
} else {
152-
$this->fields[$key] = $value;
153-
}
154-
}
155-
156-
/**
157-
* Unset the item at a given offset.
158-
*
159-
* @param string $key
160-
*
161-
* @return void
162-
*/
163-
public function offsetUnset($key)
164-
{
165-
unset($this->fields[$key]);
166-
}
167-
168115
/**
169116
* Convert the collection to its string representation.
170117
*

tests/FacebookTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function testPaginationReturnsProperResponse()
274274
$nextPage = $fb->next($graphEdge);
275275
$this->assertInstanceOf(GraphEdge::class, $nextPage);
276276
$this->assertInstanceOf(GraphUser::class, $nextPage[0]);
277-
$this->assertEquals('Foo', $nextPage[0]['name']);
277+
$this->assertEquals('Foo', $nextPage[0]->getField('name'));
278278

279279
$lastResponse = $fb->getLastResponse();
280280
$this->assertInstanceOf(Response::class, $lastResponse);

tests/GraphNode/GraphEdgeTest.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,20 @@ public function testCanMapOverNodes()
103103
$graphEdge = new GraphEdge(
104104
$this->request,
105105
[
106-
new GraphNode(['name' => 'dummy']),
107-
new GraphNode(['name' => 'dummy']),
106+
new GraphNode(['name' => 'dummy1']),
107+
new GraphNode(['name' => 'dummy2']),
108108
],
109109
['paging' => $this->pagination],
110110
'/1234567890/likes'
111111
);
112112

113-
$graphEdge = $graphEdge->map(function (GraphNode $node) {
114-
$node['name'] = str_replace('dummy', 'foo', $node['name']);
115-
return $node;
116-
});
113+
$output = '';
117114

118-
$graphEdgeToCompare = new GraphEdge(
119-
$this->request,
120-
[
121-
new GraphNode(['name' => 'foo']),
122-
new GraphNode(['name' => 'foo'])
123-
],
124-
['paging' => $this->pagination],
125-
'/1234567890/likes'
126-
);
115+
$graphEdge->map(function (GraphNode $node) use (&$output) {
116+
$output .= $node->getField('name');
117+
});
127118

128-
$this->assertEquals($graphEdgeToCompare, $graphEdge);
119+
$this->assertEquals('dummy1dummy2', $output);
129120
}
130121

131122
public function testAnExistingPropertyCanBeAccessed()

tests/GraphNode/GraphNodeFactoryTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,19 +348,19 @@ public function testAGraphEdgeWillBeCastRecursively()
348348

349349
// Story
350350
$storyObject = $graphNode[0];
351-
$this->assertInstanceOf(GraphNode::class, $storyObject['from']);
352-
$this->assertInstanceOf(GraphEdge::class, $storyObject['likes']);
353-
$this->assertInstanceOf(GraphEdge::class, $storyObject['comments']);
351+
$this->assertInstanceOf(GraphNode::class, $storyObject->getField('from'));
352+
$this->assertInstanceOf(GraphEdge::class, $storyObject->getField('likes'));
353+
$this->assertInstanceOf(GraphEdge::class, $storyObject->getField('comments'));
354354

355355
// Story Comments
356-
$storyComments = $storyObject['comments'];
356+
$storyComments = $storyObject->getField('comments');
357357
$firstStoryComment = $storyComments[0];
358-
$this->assertInstanceOf(GraphNode::class, $firstStoryComment['from']);
358+
$this->assertInstanceOf(GraphNode::class, $firstStoryComment->getField('from'));
359359

360360
// Message
361361
$messageObject = $graphNode[1];
362-
$this->assertInstanceOf(GraphEdge::class, $messageObject['to']);
363-
$toUsers = $messageObject['to'];
362+
$this->assertInstanceOf(GraphEdge::class, $messageObject->getField('to'));
363+
$toUsers = $messageObject->getField('to');
364364
$this->assertInstanceOf(GraphNode::class, $toUsers[0]);
365365
}
366366

@@ -422,10 +422,10 @@ public function testAGraphEdgeWillGenerateTheProperParentGraphEdges()
422422
$factory = new GraphNodeFactory($res);
423423
$graphEdge = $factory->makeGraphEdge();
424424
$topGraphEdge = $graphEdge->getParentGraphEdge();
425-
$childGraphEdgeOne = $graphEdge[0]['likes']->getParentGraphEdge();
426-
$childGraphEdgeTwo = $graphEdge[1]['likes']->getParentGraphEdge();
427-
$childGraphEdgeThree = $graphEdge[1]['photos']->getParentGraphEdge();
428-
$childGraphEdgeFour = $graphEdge[1]['photos'][0]['likes']->getParentGraphEdge();
425+
$childGraphEdgeOne = $graphEdge[0]->getField('likes')->getParentGraphEdge();
426+
$childGraphEdgeTwo = $graphEdge[1]->getField('likes')->getParentGraphEdge();
427+
$childGraphEdgeThree = $graphEdge[1]->getField('photos')->getParentGraphEdge();
428+
$childGraphEdgeFour = $graphEdge[1]->getField('photos')[0]->getField('likes')->getParentGraphEdge();
429429

430430
$this->assertNull($topGraphEdge);
431431
$this->assertEquals('/111/likes', $childGraphEdgeOne);

tests/GraphNode/GraphNodeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public function testAGraphNodeCanBeAccessedAsAnArray()
193193
{
194194
$graphNode = new GraphNode(['foo' => 'bar', 'faz' => 'baz']);
195195

196-
$this->assertEquals('bar', $graphNode['foo']);
197-
$this->assertEquals('baz', $graphNode['faz']);
196+
$this->assertEquals('bar', $graphNode->getField('foo'));
197+
$this->assertEquals('baz', $graphNode->getField('faz'));
198198
}
199199

200200
public function testAGraphNodeCanBeIteratedOver()

0 commit comments

Comments
 (0)