| Total Complexity | 4 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace Mbh\Collection\Traits; |
||
| 11 | trait Collection |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Returns whether the collection is empty. |
||
| 15 | * |
||
| 16 | * This should be equivalent to a count of zero, but is not required. |
||
| 17 | * Implementations should define what empty means in their own context. |
||
| 18 | * |
||
| 19 | * @return bool whether the collection is empty. |
||
| 20 | */ |
||
| 21 | public function isEmpty(): bool |
||
| 22 | { |
||
| 23 | return count($this) === 0; |
||
|
|
|||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Returns a representation that can be natively converted to JSON, which is |
||
| 28 | * called when invoking json_encode. |
||
| 29 | * |
||
| 30 | * @return mixed |
||
| 31 | * |
||
| 32 | * @see JsonSerializable |
||
| 33 | */ |
||
| 34 | public function jsonSerialize(): array |
||
| 35 | { |
||
| 36 | return $this->toArray(); |
||
| 37 | } |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * Returns an array representation of the collection. |
||
| 42 | * |
||
| 43 | * The format of the returned array is implementation-dependent. Some |
||
| 44 | * implementations may throw an exception if an array representation |
||
| 45 | * could not be created (for example when object are used as keys). |
||
| 46 | * |
||
| 47 | * @return array |
||
| 48 | */ |
||
| 49 | abstract public function toArray(): array; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Invoked when calling var_dump. |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | public function __debugInfo() |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Returns a string representation of the collection, which is invoked when |
||
| 63 | * the collection is converted to a string. |
||
| 64 | */ |
||
| 65 | public function __toString() |
||
| 68 | } |
||
| 69 | } |
||
| 70 |