44
55namespace ArangoDB \Collection ;
66
7+ use JsonSerializable ;
78use ArangoDB \Http \Api ;
89use ArangoDB \Document \Edge ;
910use ArangoDB \Document \Vertex ;
1011use ArangoDB \Document \Document ;
1112use ArangoDB \Database \Database ;
13+ use ArangoDB \Exceptions \Exception ;
1214use ArangoDB \Connection \Connection ;
1315use ArangoDB \Cursor \CollectionCursor ;
14- use ArangoDB \Collection \Index \Factory ;
15- use ArangoDB \DataStructures \ArrayList ;
16- use ArangoDB \Exceptions \IndexException ;
1716use GuzzleHttp \Exception \ClientException ;
1817use GuzzleHttp \Exception \GuzzleException ;
1918use ArangoDB \Cursor \Contracts \CursorInterface ;
2019use ArangoDB \Cursor \Exceptions \CursorException ;
21- use ArangoDB \Collection \Contracts \IndexInterface ;
2220use ArangoDB \Exceptions \Database \DatabaseException ;
2321use ArangoDB \Validation \Collection \CollectionValidator ;
2422use ArangoDB \Validation \Exceptions \InvalidParameterException ;
2523use ArangoDB \Validation \Exceptions \MissingParameterException ;
26- use JsonSerializable ;
2724
2825/**
2926 * Represents an ArangoDB collection
3330 */
3431class Collection implements JsonSerializable
3532{
33+ use IndexableTrait;
34+
3635 /**
3736 * Attributes of collection
37+ *
38+ * @var array
3839 */
3940 protected array $ attributes ;
4041
4142 /**
4243 * If the collection is a new one or a representation of an existing collection on server
44+ *
45+ * @var bool
4346 */
4447 protected bool $ isNew ;
4548
4649 /**
4750 * Database object
51+ *
52+ * @var Database
4853 */
4954 protected Database $ database ;
5055
5156 /**
5257 * Connection object
58+ *
59+ * @var Connection
5360 */
5461 protected Connection $ connection ;
5562
@@ -82,6 +89,8 @@ class Collection implements JsonSerializable
8289
8390 /**
8491 * Status descriptions
92+ *
93+ * @var array
8594 */
8695 protected array $ statusStrings = [
8796 0 => 'unknown ' ,
@@ -190,21 +199,21 @@ public function __get(string $name)
190199 }
191200
192201 /**
193- * Set a attribute
202+ * Set an attribute
194203 *
195204 * @param string $name
196205 * @param mixed $value
197- * @throws \ Exception
206+ * @throws Exception
198207 */
199- public function __set (string $ name , $ value )
208+ public function __set (string $ name , mixed $ value )
200209 {
201210 // Allow defaults attributes to be set.
202211 if (array_key_exists ($ name , $ this ->attributes )) {
203212 $ this ->attributes [$ name ] = $ value ;
204213 return ;
205214 }
206215
207- throw new \ Exception ("Non-default collection property with name: ( $ name) " );
216+ throw new Exception ("Non-default collection property with name: ( $ name) " );
208217 }
209218
210219 /**
@@ -383,34 +392,6 @@ public function getChecksum(): string
383392 }
384393 }
385394
386- /**
387- * Return all indexes of collection
388- *
389- * @return ArrayList
390- * @throws DatabaseException|GuzzleException|InvalidParameterException|IndexException|MissingParameterException
391- */
392- public function getIndexes (): ArrayList
393- {
394- try {
395- if ($ this ->isNew ()) {
396- return new ArrayList ();
397- }
398-
399- $ uri = Api::addQuery (Api::INDEX , ['collection ' => $ this ->getName ()]);
400- $ response = $ this ->connection ->get ($ uri );
401- $ data = json_decode ((string )$ response ->getBody (), true );
402- $ indexes = new ArrayList ();
403- foreach ($ data ['indexes ' ] as $ index ) {
404- $ indexes ->push (Factory::factory ($ index ));
405- }
406-
407- return $ indexes ;
408- } catch (ClientException $ exception ) {
409- $ response = json_decode ((string )$ exception ->getResponse ()->getBody (), true );
410- throw new DatabaseException ($ response ['errorMessage ' ], $ exception , $ response ['errorNum ' ]);
411- }
412- }
413-
414395 /**
415396 * Return the revision of collection
416397 *
@@ -435,65 +416,6 @@ public function getRevision(): string
435416 }
436417 }
437418
438- /**
439- * Create a index for collection
440- * @param IndexInterface $index
441- *
442- * @return bool
443- * @throws DatabaseException|GuzzleException
444- */
445- public function addIndex (IndexInterface $ index ): bool
446- {
447- try {
448- // If the collection is a new one,
449- // we cannot add indexes on server.
450- if ($ this ->isNew ()) {
451- return false ;
452- }
453-
454- $ uri = Api::addQuery (Api::INDEX , ['collection ' => $ this ->getName ()]);
455- $ response = $ this ->connection ->post ($ uri , $ index ->getCreateData ());
456-
457- json_decode ((string )$ response ->getBody (), true );
458- return true ;
459- } catch (ClientException $ exception ) {
460- $ response = json_decode ((string )$ exception ->getResponse ()->getBody (), true );
461- throw new DatabaseException ($ response ['errorMessage ' ], $ exception , $ response ['errorNum ' ]);
462- }
463- }
464-
465- /**
466- * Drops a index of collection
467- * @param IndexInterface $index
468- *
469- * @return bool
470- * @throws DatabaseException|GuzzleException
471- */
472- public function dropIndex (IndexInterface $ index ): bool
473- {
474- try {
475- // If the collection is a new one, or the index,
476- // we cannot drop it on server.
477- if ($ this ->isNew () || $ index ->isNew ()) {
478- return false ;
479- }
480-
481- $ uri = Api::addUriParam (Api::INDEX , $ index ->getId ());
482- $ response = $ this ->connection ->delete ($ uri );
483- $ data = json_decode ((string )$ response ->getBody (), true );
484- return !$ data ['error ' ];
485- } catch (ClientException $ exception ) {
486- $ response = json_decode ((string )$ exception ->getResponse ()->getBody (), true );
487- $ databaseException = new DatabaseException ($ response ['errorMessage ' ], $ exception , $ response ['errorNum ' ]);
488-
489- if ($ exception ->getResponse ()->getStatusCode () === 404 ) {
490- return false ;
491- }
492-
493- throw $ databaseException ;
494- }
495- }
496-
497419 /**
498420 * Saves or update the collection.
499421 * Except for 'waitForSync' and 'name', a collection can not be modified after creation.
@@ -587,9 +509,7 @@ public function findByKey(string $key, bool $isVertex = false)
587509 $ response = $ this ->connection ->get (sprintf ("%s/%s " , $ uri , $ handle ));
588510 $ data = json_decode ((string )$ response ->getBody (), true );
589511 $ document = $ this ->isGraph () ? new Edge ($ data , $ this ) : new Document ($ data , $ this );
590- $ document = $ isVertex ? new Vertex ($ data , $ this ) : $ document ;
591-
592- return $ document ;
512+ return $ isVertex ? new Vertex ($ data , $ this ) : $ document ;
593513 } catch (ClientException $ exception ) {
594514 $ response = json_decode ((string )$ exception ->getResponse ()->getBody (), true );
595515
@@ -665,7 +585,7 @@ public function rename(string $newName): bool
665585 }
666586
667587 /**
668- * @see \ JsonSerializable::jsonSerialize()
588+ * @see JsonSerializable::jsonSerialize
669589 */
670590 public function jsonSerialize (): mixed
671591 {
0 commit comments