From 19564c9e18ae456e39bc2c8a306f9e79dd619e11 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Mon, 7 May 2018 15:24:00 +0100 Subject: Docblock and fix toString functions --- src/Model/Collection.php | 54 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'src/Model/Collection.php') diff --git a/src/Model/Collection.php b/src/Model/Collection.php index 62bbf98..c4900fb 100644 --- a/src/Model/Collection.php +++ b/src/Model/Collection.php @@ -3,19 +3,19 @@ namespace App\Model; use App\Model\Model; +use App\Script\Input; use ArrayAccess; +use Countable; +use DateTime; use Exception; use Iterator; -use App\Script\Input; -use DateTime; -use Countable; /** * A collection of models * * @author Phil Burton */ -class Collection implements ArrayAccess, Iterator, Countable +class Collection implements ArrayAccess, Countable, Iterator { /** * Raw array of models @@ -170,6 +170,17 @@ class Collection implements ArrayAccess, Iterator, Countable ++$this->position; } + /** + * Return the count of the models in this collection + * + * @author Phil Burton + * @return int + */ + public function count(): int + { + return count($this->models); + } + /** * Filter by input * @@ -193,6 +204,13 @@ class Collection implements ArrayAccess, Iterator, Countable } } + /** + * Filter this collection by a given date and time + * + * @author Phil Burton + * @param string $date + * @param string $time + */ public function filterByDateTime(string $date, string $time) { $dateTime = DateTime::createFromFormat('d/m/y G:i', $date . ' ' . $time); @@ -213,6 +231,12 @@ class Collection implements ArrayAccess, Iterator, Countable $this->models = $out; } + /** + * Filter this collection by a given location postcode + * + * @author Phil Burton + * @param string $location + */ public function filterByLocation(string $location) { $location = substr($location, 0, 2); @@ -228,6 +252,12 @@ class Collection implements ArrayAccess, Iterator, Countable $this->models = $out; } + /** + * Filter this collection by a given max covers integer + * + * @author Phil Burton + * @param int $covers + */ public function filterByCovers(int $covers) { $out = []; @@ -241,8 +271,20 @@ class Collection implements ArrayAccess, Iterator, Countable $this->models = $out; } - public function count() + /** + * Return string representation of this collection + * + * @author Phil Burton + * @return string + */ + public function toString() : string { - return count($this->models); + $out = []; + + foreach ($this->models as $model) { + $out[] = $model->toString(); + } + + return implode("\n\n", $out); } } -- cgit v1.2.3