Skip to content

Commit 5374be8

Browse files
committed
Merge remote-tracking branch 'origin/devel' into 2.2
2 parents 9662676 + 3385ee4 commit 5374be8

File tree

5 files changed

+74
-39
lines changed

5 files changed

+74
-39
lines changed

lib/triagens/ArangoDb/Cursor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ private function addDistanceToFromArray(array $data)
468468
*/
469469
private function addCommonNeighborsFromArray(array $data)
470470
{
471-
$k = array_keys($data)[0];
471+
$k = array_keys($data);
472+
$k = $k[0];
472473
$this->_result[$k] = array();
473474

474475
foreach ($data[$k] as $neighbor => $neighbors) {
@@ -488,7 +489,8 @@ private function addCommonNeighborsFromArray(array $data)
488489
*/
489490
private function addCommonPropertiesFromArray(array $data)
490491
{
491-
$k = array_keys($data)[0];
492+
$k = array_keys($data);
493+
$k = $k[0];
492494
$this->_result[$k] = array();
493495
foreach ($data[$k] as $c) {
494496
$id = $c["_id"];

lib/triagens/ArangoDb/Graph.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public function getVerticesCollection()
120120
return null;
121121
}
122122
$this->addEdgeDefinition($edgeDefinition);
123-
return $edgeDefinition->getFromCollections()[0];
123+
$fc = $edgeDefinition->getFromCollections();
124+
return $fc[0];
124125
}
125126

126127
/**
@@ -260,21 +261,26 @@ public function set($key, $value)
260261
* @return EdgeDefinition
261262
*/
262263
private function getSingleUndirectedRelation() {
263-
if (count($this->getEdgeDefinitions()) > 1 ||
264+
$ed = $this->getEdgeDefinitions();
265+
if (count($ed) > 0) {
266+
$a = $ed[0];
267+
$b = $a->getFromCollections();
268+
$c = $a->getToCollections();
269+
}
270+
if (count($ed) > 1 ||
264271
(
265-
count($this->getEdgeDefinitions()) === 1 && (
266-
count($this->getEdgeDefinitions()[0]->getFromCollections()) > 1 ||
267-
count($this->getEdgeDefinitions()[0]->getToCollections()) > 1 ||
268-
$this->getEdgeDefinitions()[0]->getFromCollections()[0] !==
269-
$this->getEdgeDefinitions()[0]->getToCollections()[0]
272+
count($ed) === 1 && (
273+
count($a->getFromCollections()) > 1 ||
274+
count($a->getToCollections()) > 1 ||
275+
$b[0] !== $c[0]
270276

271277
)
272278
)
273279
) {
274280
throw new ClientException('This operation only supports graphs with one undirected single collection relation');
275281
}
276-
if (count($this->getEdgeDefinitions()) === 1) {
277-
$eD = $this->getEdgeDefinitions()[0];
282+
if (count($ed) === 1) {
283+
$eD = $ed[0];
278284
$this->_edgeDefinitions = array();
279285
} else {
280286
$eD = new EdgeDefinition();

lib/triagens/ArangoDb/GraphHandler.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ public function saveVertex($graph, $document ,$collection = null)
552552
if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
553553
throw new ClientException('A collection must be provided.');
554554
} else if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
555-
$collection = $this->getVertexCollections($graph)[0];
555+
$collection = $this->getVertexCollections($graph);
556+
$collection = $collection[0];
556557
}
557558

558559
$data = $document->getAll();
@@ -608,7 +609,8 @@ public function getVertex($graph, $vertexId, array $options = array(), $collecti
608609
if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
609610
throw new ClientException('A collection must be provided.');
610611
} else if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
611-
$collection = $this->getVertexCollections($graph)[0];
612+
$collection = $this->getVertexCollections($graph);
613+
$collection = $collection[0];
612614
}
613615

614616
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_VERTEX, $collection, $vertexId));
@@ -662,7 +664,8 @@ public function replaceVertex($graph, $vertexId, Document $document, $options =
662664
if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
663665
throw new ClientException('A collection must be provided.');
664666
} else if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
665-
$collection = $this->getVertexCollections($graph)[0];
667+
$collection = $this->getVertexCollections($graph);
668+
$collection = $collection[0];
666669
}
667670

668671
$options = array_merge(array(self::OPTION_REVISION => false), $options);
@@ -751,7 +754,8 @@ public function updateVertex($graph, $vertexId, Document $document, $options = a
751754
if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
752755
throw new ClientException('A collection must be provided.');
753756
} else if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
754-
$collection = $this->getVertexCollections($graph)[0];
757+
$collection = $this->getVertexCollections($graph);
758+
$collection = $collection[0];
755759
}
756760

757761
$options = array_merge(array(self::OPTION_REVISION => false), $options);
@@ -825,7 +829,8 @@ public function removeVertex($graph, $vertexId, $revision = null, $options = arr
825829
if (count($this->getVertexCollections($graph)) !== 1 && $collection === null) {
826830
throw new ClientException('A collection must be provided.');
827831
} else if (count($this->getVertexCollections($graph)) === 1 && $collection === null) {
828-
$collection = $this->getVertexCollections($graph)[0];
832+
$collection = $this->getVertexCollections($graph);
833+
$collection = $collection[0];
829834
}
830835

831836
// This preserves compatibility for the old policy parameter.
@@ -883,7 +888,8 @@ public function saveEdge($graph, $from, $to, $label = null, $document, $collecti
883888
if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) {
884889
throw new ClientException('A collection must be provided.');
885890
} else if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) {
886-
$collection = $this->getEdgeCollections($graph)[0];
891+
$collection = $this->getEdgeCollections($graph);
892+
$collection = $collection[0];
887893
}
888894

889895

@@ -949,7 +955,8 @@ public function getEdge($graph, $edgeId, array $options = array(), $collection =
949955
if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) {
950956
throw new ClientException('A collection must be provided.');
951957
} else if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) {
952-
$collection = $this->getEdgeCollections($graph)[0];
958+
$collection = $this->getEdgeCollections($graph);
959+
$collection = $collection[0];
953960
}
954961

955962
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, array($graph, Urls::URLPART_EDGE, $collection, $edgeId));
@@ -1004,7 +1011,8 @@ public function replaceEdge($graph, $edgeId, $label, Edge $document, $options =
10041011
if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) {
10051012
throw new ClientException('A collection must be provided.');
10061013
} else if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) {
1007-
$collection = $this->getEdgeCollections($graph)[0];
1014+
$collection = $this->getEdgeCollections($graph);
1015+
$collection = $collection[0];
10081016
}
10091017

10101018
$options = array_merge(array(self::OPTION_REVISION => false), $options);
@@ -1097,7 +1105,8 @@ public function updateEdge($graph, $edgeId, $label, Edge $document, $options = a
10971105
if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) {
10981106
throw new ClientException('A collection must be provided.');
10991107
} else if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) {
1100-
$collection = $this->getEdgeCollections($graph)[0];
1108+
$collection = $this->getEdgeCollections($graph);
1109+
$collection = $collection[0];
11011110
}
11021111

11031112
$options = array_merge(array(self::OPTION_REVISION => false), $options);
@@ -1177,7 +1186,8 @@ public function removeEdge($graph, $edgeId, $revision = null, $options = array()
11771186
if (count($this->getEdgeCollections($graph)) !== 1 && $collection === null) {
11781187
throw new ClientException('A collection must be provided.');
11791188
} else if (count($this->getEdgeCollections($graph)) === 1 && $collection === null) {
1180-
$collection = $this->getEdgeCollections($graph)[0];
1189+
$collection = $this->getEdgeCollections($graph);
1190+
$collection = $collection[0];
11811191
}
11821192

11831193
// This preserves compatibility for the old policy parameter.
@@ -2496,7 +2506,8 @@ public function getRadius($graph,
24962506
$statement->bind('options', $options);
24972507

24982508
$statement->setQuery($aql);
2499-
return $statement->execute()->getAll()[0];
2509+
$a = $statement->execute()->getAll();
2510+
return $a[0];
25002511
}
25012512

25022513
/**
@@ -2552,7 +2563,8 @@ public function getDiameter($graph,
25522563
$statement->bind('options', $options);
25532564

25542565
$statement->setQuery($aql);
2555-
return $statement->execute()->getAll()[0];
2566+
$a = $statement->execute()->getAll();
2567+
return $a[0];
25562568
}
25572569

25582570
}

tests/GeneralGraphExtendedTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,9 @@ public function testGetCommonNeighborVertices()
699699
),
700700
array("_id" => $this->v1 . "/" . $this->vertex7Array["_key"])
701701
);
702-
703-
$this->assertTrue($e->getMetadata()["hasMore"]);
704-
$this->assertTrue($e->getMetadata()["count"] === 2);
702+
$meta = $e->getMetadata();
703+
$this->assertTrue($meta["hasMore"]);
704+
$this->assertTrue($meta["count"] === 2);
705705

706706

707707
}
@@ -734,8 +734,9 @@ public function testGetCommonProperties()
734734
$this->graphHandler->setCount(true);
735735
$this->graphHandler->setLimit(2);
736736
$e = $this->graphHandler->getCommonProperties($this->graphName);
737-
$this->assertTrue($e->getMetadata()["hasMore"]);
738-
$this->assertTrue($e->getMetadata()["count"] === 2);
737+
$meta = $e->getMetadata();
738+
$this->assertTrue($meta["hasMore"]);
739+
$this->assertTrue($meta["count"] === 2);
739740

740741
}
741742

tests/GraphBasicTest.php

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ public function testCreateAndDeleteGraphs()
5656
*/
5757
public function testCreateAndDeleteGraphsWithDefintions()
5858
{
59-
60-
$ed1 = EdgeDefinition::createDirectedRelation("directed", ["lba", "blub"], ["bla", "blob"]);
59+
$param1 = array ();
60+
$param1[] = "lba";
61+
$param1[] = "blub";
62+
$param2 = array ();
63+
$param2[] = "bla";
64+
$param2[] = "blob";
65+
$ed1 = EdgeDefinition::createDirectedRelation("directed", $param1, $param2);
6166
$ed2 = EdgeDefinition::createUndirectedRelation("undirected", "singleV");
6267
$this->graph = new Graph();
6368
$this->graph->set('_key', 'Graph1');
@@ -87,15 +92,20 @@ public function testCreationOfGraphObject()
8792
$this->assertTrue($this->graph->getEdgesCollection() === 'ArangoDBPHPTestSuiteTestEdgeCollection01');
8893
$this->assertTrue($this->graph->getVerticesCollection() === 'ArangoDBPHPTestSuiteTestCollection01');
8994
$this->assertTrue(count($this->graph->getEdgeDefinitions()) === 1);
90-
$this->assertTrue($this->graph->getEdgeDefinitions()[0]->getRelation() === 'ArangoDBPHPTestSuiteTestEdgeCollection01');
91-
$this->assertTrue($this->graph->getEdgeDefinitions()[0]->getToCollections()[0] === 'ArangoDBPHPTestSuiteTestCollection01');
92-
$this->assertTrue($this->graph->getEdgeDefinitions()[0]->getFromCollections()[0] === 'ArangoDBPHPTestSuiteTestCollection01');
93-
94-
$this->graph->getEdgeDefinitions()[0]->addFromCollection("newFrom");
95-
$this->graph->getEdgeDefinitions()[0]->addToCollection("newTo");
95+
$ed = $this->graph->getEdgeDefinitions();
96+
$ed = $ed[0];
97+
$a = $ed->getToCollections();
98+
$b = $ed->getFromCollections();
99+
$this->assertTrue($ed->getRelation() === 'ArangoDBPHPTestSuiteTestEdgeCollection01');
100+
$this->assertTrue($a[0] === 'ArangoDBPHPTestSuiteTestCollection01');
101+
$this->assertTrue($b[0] === 'ArangoDBPHPTestSuiteTestCollection01');
102+
$ed = $this->graph->getEdgeDefinitions();
103+
$ed = $ed[0];
104+
$ed->addFromCollection("newFrom");
105+
$ed->addToCollection("newTo");
96106

97-
$this->assertTrue(count($this->graph->getEdgeDefinitions()[0]->getFromCollections()) === 2);
98-
$this->assertTrue(count($this->graph->getEdgeDefinitions()[0]->getToCollections()) === 2);
107+
$this->assertTrue(count($ed->getFromCollections()) === 2);
108+
$this->assertTrue(count($ed->getToCollections()) === 2);
99109

100110
$exception = null;
101111
try {
@@ -312,7 +322,11 @@ public function testAddGetDeleteEdgeCollections()
312322
$this->graph,
313323
EdgeDefinition::createUndirectedRelation("undirected2", "singleV3")
314324
);
315-
$this->assertTrue($this->graph->getEdgeDefinitions()[0]->getToCollections()[0] === "singleV3");
325+
326+
$ed = $this->graph->getEdgeDefinitions();
327+
$ed = $ed[0];
328+
$ed = $ed->getToCollections();
329+
$this->assertTrue($ed[0] === "singleV3");
316330

317331
$error = null;
318332
try {

0 commit comments

Comments
 (0)