From da0a51a657fdbc7adf95607516f61c3b3c852c9e Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 13 Jul 2020 15:59:41 +0300 Subject: [PATCH] feat(element-queries): Collections API implementation #436 --- src/flextype/core/Collections/Collections.php | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/flextype/core/Collections/Collections.php b/src/flextype/core/Collections/Collections.php index bc845973..40e00409 100644 --- a/src/flextype/core/Collections/Collections.php +++ b/src/flextype/core/Collections/Collections.php @@ -236,9 +236,9 @@ class Collections } /** - * Returns the number of items. + * Returns a value indicating whether the collection contains any item of data. * - * @return int The number of items. + * @return bool Return true or false. * * @access public */ @@ -259,14 +259,28 @@ class Collections return count($this->all()); } + /** + * Returns a last single item of result. + * + * @return array Item + * + * @access public + */ public function last() { - return Arr::undot(Arr::dot($this->matchCollection()->last())); + return Arr::undot($this->matchCollection()->last()); } - public function one() + /** + * Returns a single item of result. + * + * @return array Item + * + * @access public + */ + public function one() : array { - return Arr::undot(Arr::dot($this->matchCollection()->first())); + return Arr::undot($this->matchCollection()->first()); } /** @@ -281,6 +295,11 @@ class Collections return Arr::undot(Arr::dot($this->matchCollection()->toArray())); } + /** + * Match collection + * + * @access protected + */ protected function matchCollection() { // Match collection