22namespace Ds \Traits ;
33
44/**
5- * Collection
6- *
7- * @package Ds\Traits
5+ * Common to structures that implement the base collection interface.
86 */
97trait Collection
108{
@@ -14,27 +12,30 @@ trait Collection
1412 * This should be equivalent to a count of zero, but is not required.
1513 * Implementations should define what empty means in their own context.
1614 *
17- * @return bool
15+ * @return bool whether the collection is empty.
1816 */
1917 public function isEmpty (): bool
2018 {
2119 return count ($ this ) === 0 ;
2220 }
2321
2422 /**
25- * Json Serialize
23+ * Returns a representation that can be natively converted to JSON, which is
24+ * called when invoking json_encode.
2625 *
27- * @return string
26+ * @return mixed
27+ *
28+ * @see JsonSerializable
2829 */
2930 public function jsonSerialize ()
3031 {
3132 return $ this ->toArray ();
3233 }
3334
3435 /**
35- * Creates a copy of the collection.
36+ * Creates a shallow copy of the collection.
3637 *
37- * @return self
38+ * @return \Ds\Collection a shallow copy of the collection.
3839 */
3940 public function copy (): \Ds \Collection
4041 {
@@ -44,24 +45,27 @@ public function copy(): \Ds\Collection
4445 /**
4546 * Returns an array representation of the collection.
4647 *
47- * The format of the returned array is implementation-dependent.
48- * Some implementations may throw an exception if an array representation
49- * could not be created.
48+ * The format of the returned array is implementation-dependent. Some
49+ * implementations may throw an exception if an array representation
50+ * could not be created (for example when object are used as keys) .
5051 *
5152 * @return array
5253 */
5354 abstract public function toArray (): array ;
5455
5556 /**
56- * Debug Info
57+ * Invoked when calling var_dump.
58+ *
59+ * @return array
5760 */
5861 public function __debugInfo ()
5962 {
6063 return $ this ->toArray ();
6164 }
6265
6366 /**
64- * To String
67+ * Returns a string representation of the collection, which is invoked when
68+ * the collection is converted to a string.
6569 */
6670 public function __toString ()
6771 {
0 commit comments