Skip to content

Commit 3087b06

Browse files
committed
Fixed / added doc blocks and PSR-2 formatting
1 parent 715317b commit 3087b06

File tree

6 files changed

+152
-99
lines changed

6 files changed

+152
-99
lines changed

lib/triagens/ArangoDb/Collection.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public function getType()
459459
*
460460
* @throws ClientException
461461
*
462-
* @param int $keyOptions - status = 1 -> new born, status = 2 -> unloaded, status = 3 -> loaded, status = 4 -> being unloaded, status = 5 -> deleted
462+
* @param int $status - statuses = 1 -> new born, status = 2 -> unloaded, status = 3 -> loaded, status = 4 -> being unloaded, status = 5 -> deleted
463463
*
464464
* @return void
465465
*/
@@ -471,7 +471,17 @@ public function setStatus($status)
471471
throw new ClientException('Should not update the status of an existing collection');
472472
}
473473

474-
if (!in_array($status, array(self::STATUS_NEW_BORN, self::STATUS_UNLOADED, self::STATUS_LOADED, self::STATUS_BEING_UNLOADED, self::STATUS_DELETED))) {
474+
if (!in_array(
475+
$status,
476+
array(
477+
self::STATUS_NEW_BORN,
478+
self::STATUS_UNLOADED,
479+
self::STATUS_LOADED,
480+
self::STATUS_BEING_UNLOADED,
481+
self::STATUS_DELETED
482+
)
483+
)
484+
) {
475485
throw new ClientException('Invalid status used for collection');
476486
}
477487

lib/triagens/ArangoDb/DocumentHandler.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function getById($collectionId, $documentId, array $options = array())
9090
$data = $response->getJson();
9191

9292
$options['_isNew'] = false;
93+
9394
return Document::createFromArray($data, $options);
9495
}
9596

@@ -193,9 +194,9 @@ public function add($collectionId, Document $document, $options = array())
193194
*
194195
* @throws Exception
195196
*
196-
* @param mixed $collectionId - collection id as string or number
197-
* @param mixed $document - the document to be added, can be passed as a document or an array
198-
* @param bool|array $options - optional, prior to v1.2.0 this was a boolean value for create. Since v1.0.0 it's an array of options.
197+
* @param Document $document - the document to be added, can be passed as a document or an array
198+
* @param mixed $collectionId - collection id as string or number
199+
* @param bool|array $options - optional, prior to v1.2.0 this was a boolean value for create. Since v1.2.0 it's an array of options.
199200
* <p>Options are :<br>
200201
* <li>'create' - create the collection if it does not yet exist.</li>
201202
* <li>'waitForSync' - if set to true, then all removal operations will instantly be synchronised to disk / If this is not specified, then the collection's default sync behavior will be applied.</li>
@@ -206,19 +207,19 @@ public function add($collectionId, Document $document, $options = array())
206207
*/
207208
public function store(Document $document, $collectionId = null, $options = array())
208209
{
209-
if($document->getIsNew()){
210+
if ($document->getIsNew()) {
210211

211-
if($collectionId == null){
212+
if ($collectionId == null) {
212213
throw new ClientException('A collection id is required to store a new document.');
213214
}
214215

215216
$result = $this->save($collectionId, $document, $options);
216217
$document->setIsNew(false);
217218

218219
return $result;
219-
}else{
220+
} else {
220221

221-
if($collectionId){
222+
if ($collectionId) {
222223
throw new ClientException('An existing document cannot be stored into a new collection');
223224
}
224225

@@ -380,8 +381,9 @@ public function updateById($collectionId, $documentId, Document $document, $opti
380381
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
381382
$url = UrlHelper::appendParamsUrl($url, $params);
382383
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll()));
383-
$json = $result->getJson();
384+
$json = $result->getJson();
384385
$document->setRevision($json[Document::ENTRY_REV]);
386+
385387
return true;
386388
}
387389

@@ -465,8 +467,9 @@ public function replaceById($collectionId, $documentId, Document $document, $opt
465467
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, $collectionId, $documentId);
466468
$url = UrlHelper::appendParamsUrl($url, $params);
467469
$result = $this->getConnection()->put($url, $this->json_encode_wrapper($data));
468-
$json = $result->getJson();
470+
$json = $result->getJson();
469471
$document->setRevision($json[Document::ENTRY_REV]);
472+
470473
return true;
471474
}
472475

lib/triagens/ArangoDb/Graph.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ class Graph extends
4949
/**
5050
* Constructs an empty graph
5151
*
52-
* @param array $options - optional, initial $options for document
52+
* @param array $name - optional, initial name for graph
53+
* @param array $options - optional, initial $options for graph
5354
*
5455
* @return void
5556
*/
5657
public function __construct($name = null, array $options = array())
5758
{
5859

5960
// prevent backwards compatibility break where the first parameter is the $options array
60-
if(!is_array($name) && $name != null){
61+
if (!is_array($name) && $name != null) {
6162
$this->set('_key', $name);
6263
}
6364

@@ -134,7 +135,7 @@ public function getEdgesCollection()
134135
public function set($key, $value)
135136
{
136137

137-
if(in_array($key, array(self::ENTRY_VERTICES, self::ENTRY_EDGES))){
138+
if (in_array($key, array(self::ENTRY_VERTICES, self::ENTRY_EDGES))) {
138139

139140
if (!is_string($key)) {
140141
throw new ClientException('Invalid document attribute key');
@@ -154,8 +155,7 @@ public function set($key, $value)
154155

155156
return;
156157
}
157-
158-
}else{
158+
} else {
159159
parent::set($key, $value);
160160
}
161161
}

lib/triagens/ArangoDb/GraphHandler.php

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,26 @@ public function createGraph(Graph $graph)
9999
*
100100
* @throws Exception
101101
*
102-
* @param String - $graph - The name of the graph
102+
* @param string $graph - The name of the graph
103+
* @param array $options - can be used to provide additional options
103104
*
104105
* @return Graph - A graph object representing the graph
105106
* @since 1.2
106107
*
107108
* @example "ArangoDb/examples/graph.php" How to use this function
108-
* @example "ArangoDb/examples/graph.php" How to use this function
109109
*/
110110
public function getGraph($graph, array $options = array())
111111
{
112-
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, $graph);
112+
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, $graph);
113113
$response = $this->getConnection()->get($url);
114-
$data = $response->getJson();
114+
$data = $response->getJson();
115115

116-
if($data['error']){
116+
if ($data['error']) {
117117
return false;
118118
}
119119

120120
$options['_isNew'] = false;
121+
121122
return Graph::createFromArray($data['graph'], $options);
122123
}
123124

@@ -171,8 +172,8 @@ public function properties($graph)
171172
*
172173
* @throws Exception
173174
*
174-
* @param mixed $graphName - the name of the graph
175-
* @param mixed $document - the vertex to be added, can be passed as a vertex object or an array
175+
* @param mixed $graphName - the name of the graph
176+
* @param mixed $document - the vertex to be added, can be passed as a vertex object or an array
176177
*
177178
* @return mixed - id of vertex created
178179
* @since 1.2
@@ -200,6 +201,7 @@ public function saveVertex($graphName, $document)
200201
}
201202

202203
$document->setIsNew(false);
204+
203205
return $document->getId();
204206
}
205207

@@ -233,6 +235,7 @@ public function getVertex($graphName, $vertexId, array $options = array())
233235
$vertex = $jsonArray['vertex'];
234236

235237
$options['_isNew'] = false;
238+
236239
return Vertex::createFromArray($vertex, $options);
237240
}
238241

@@ -250,10 +253,10 @@ public function getVertex($graphName, $vertexId, array $options = array())
250253
*
251254
* @throws Exception
252255
*
253-
* @param string $graphName - the graph name as string
254-
* @param mixed $vertexId - the vertex id as string or number
255-
* @param Document $document - the vertex-document to be updated
256-
* @param mixed $options - optional, an array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)
256+
* @param string $graphName - the graph name as string
257+
* @param mixed $vertexId - the vertex id as string or number
258+
* @param Document $document - the vertex-document to be updated
259+
* @param mixed $options - optional, an array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)
257260
* <p>Options are :
258261
* <li>'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li>
259262
* <li>'waitForSync' - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection</li>
@@ -357,9 +360,10 @@ public function updateVertex($graphName, $vertexId, Document $document, $options
357360
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, $graphName, Urls::URLPART_VERTEX, $vertexId);
358361
$url = UrlHelper::appendParamsUrl($url, $params);
359362
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll()));
360-
$json = $result->getJson();
363+
$json = $result->getJson();
361364
$vertex = $json['vertex'];
362365
$document->setRevision($vertex[Vertex::ENTRY_REV]);
366+
363367
return true;
364368
}
365369

@@ -420,11 +424,11 @@ public function removeVertex($graphName, $vertexId, $revision = null, $options =
420424
*
421425
* @throws Exception
422426
*
423-
* @param mixed $graphName - the graph name as string
424-
* @param mixed $from - the 'from' vertex
425-
* @param mixed $to - the 'to' vertex
426-
* @param mixed $label - (optional) a label for the edge
427-
* @param mixed $document - the edge-document to be added, can be passed as an edge object or an array
427+
* @param mixed $graphName - the graph name as string
428+
* @param mixed $from - the 'from' vertex
429+
* @param mixed $to - the 'to' vertex
430+
* @param mixed $label - (optional) a label for the edge
431+
* @param mixed $document - the edge-document to be added, can be passed as an edge object or an array
428432
*
429433
* @return mixed - id of edge created
430434
* @since 1.2
@@ -459,6 +463,7 @@ public function saveEdge($graphName, $from, $to, $label = null, $document)
459463
}
460464

461465
$document->setIsNew(false);
466+
462467
return $document->getId();
463468
}
464469

@@ -492,6 +497,7 @@ public function getEdge($graphName, $edgeId, array $options = array())
492497
$edge = $jsonArray['edge'];
493498

494499
$options['_isNew'] = false;
500+
495501
return Edge::createFromArray($edge, $options);
496502
}
497503

@@ -509,11 +515,11 @@ public function getEdge($graphName, $edgeId, array $options = array())
509515
*
510516
* @throws Exception
511517
*
512-
* @param mixed $graphName - graph name as string or number
513-
* @param mixed $edgeId - edge id as string or number
514-
* @param mixed $label - (optional) label for the edge
515-
* @param Edge $document - edge document to be updated
516-
* @param mixed $options - optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)
518+
* @param mixed $graphName - graph name as string or number
519+
* @param mixed $edgeId - edge id as string or number
520+
* @param mixed $label - (optional) label for the edge
521+
* @param Edge $document - edge document to be updated
522+
* @param mixed $options - optional, array of options (see below) or the boolean value for $policy (for compatibility prior to version 1.1 of this method)
517523
* <p>Options are :
518524
* <li>'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li>
519525
* <li>'waitForSync' - can be used to force synchronisation of the document replacement operation to disk even in case that the waitForSync flag had been disabled for the entire collection</li>
@@ -581,11 +587,11 @@ public function ReplaceEdge($graphName, $edgeId, $label, Edge $document, $option
581587
*
582588
* @throws Exception
583589
*
584-
* @param string $graphName - graph name as string
585-
* @param mixed $edgeId - edge id as string or number
586-
* @param mixed $label - (optional) label for the edge
587-
* @param Edge $document - patch edge-document which contains the attributes and values to be updated
588-
* @param mixed $options - optional, array of options (see below)
590+
* @param string $graphName - graph name as string
591+
* @param mixed $edgeId - edge id as string or number
592+
* @param mixed $label - (optional) label for the edge
593+
* @param Edge $document - patch edge-document which contains the attributes and values to be updated
594+
* @param mixed $options - optional, array of options (see below)
589595
* <p>Options are :
590596
* <li>'policy' - update policy to be used in case of conflict ('error', 'last' or NULL [use default])</li>
591597
* <li>'keepNull' - can be used to instruct ArangoDB to delete existing attributes instead setting their values to null. Defaults to true (keep attributes when set to null)</li>
@@ -626,9 +632,10 @@ public function updateEdge($graphName, $edgeId, $label, Edge $document, $options
626632
$url = UrlHelper::buildUrl(Urls::URL_GRAPH, $graphName, Urls::URLPART_EDGE, $edgeId);
627633
$url = UrlHelper::appendParamsUrl($url, $params);
628634
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll()));
629-
$json = $result->getJson();
630-
$edge = $json['edge'];
635+
$json = $result->getJson();
636+
$edge = $json['edge'];
631637
$document->setRevision($edge[Edge::ENTRY_REV]);
638+
632639
return true;
633640
}
634641

0 commit comments

Comments
 (0)