summaryrefslogtreecommitdiff
path: root/src/Model/Vendor.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Vendor.php')
-rw-r--r--src/Model/Vendor.php139
1 files changed, 107 insertions, 32 deletions
diff --git a/src/Model/Vendor.php b/src/Model/Vendor.php
index 6b98704..dfed157 100644
--- a/src/Model/Vendor.php
+++ b/src/Model/Vendor.php
@@ -11,46 +11,46 @@ use DateInterval;
/**
* Vendor Model
+ *
+ * @author Phil Burton <phil@pgburton.com>
*/
class Vendor extends Model
{
+ /**
+ * Name of vendor
+ *
+ * @var string
+ */
protected $name;
+
+ /**
+ * Vendor postcode
+ *
+ * @var string
+ */
protected $postcode;
- protected $maxCovers;
- protected $menus;
- public function __construct($name, $postcode, $maxCovers)
- {
- $this->name = $name;
- $this->postcode = $postcode;
- $this->maxCovers = $maxCovers;
- $this->menus = [];
- }
+ /**
+ * Max no of people this vendor can cover
+ *
+ * @var int
+ */
+ protected $maxCovers;
- public function addMenu(Menu $menu)
- {
- $this->menus[] = $menu;
- }
+ /**
+ * The array of menus this vendor provides
+ *
+ * @var Menu[]
+ */
+ protected $menus;
/**
- * Load vendors from file, parse them into a model collection and Return
+ * Load all the vendor data from a given file
*
* @author Phil Burton <phil@pgburton.com>
- * @param FileHandler $handler
+ * @param string $filename
* @return Collection
*/
- public function loadFromFile(FileHandler $handler): Collection
- {
- // initalise a Vendor Collection
- $collection = new Collection;
-
- foreach ($handler->getVendorArray() as $vendorRaw) {
- $collection[] = new Vendor($vendorRaw);
- }
-
- return $collection;
- }
-
public static function loadAll(string $filename): Collection
{
$fileHandler = new FileHandler($filename);
@@ -104,7 +104,62 @@ class Vendor extends Model
return $collection;
}
- public function checkDate(DateTime $date)
+ /**
+ * Set vendor data and intiate empty menus array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param $name
+ * @param $postcode
+ * @param $maxCovers
+ */
+ public function __construct($name, $postcode, $maxCovers)
+ {
+ $this->name = $name;
+ $this->postcode = $postcode;
+ $this->maxCovers = $maxCovers;
+ $this->menus = [];
+ }
+
+ /**
+ * Add a menu to the menus array
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param Menu $menu
+ */
+ public function addMenu(Menu $menu)
+ {
+ $this->menus[] = $menu;
+ }
+
+ /**
+ * Load vendors from file, parse them into a model collection and Return
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param FileHandler $handler
+ * @return Collection
+ */
+ public function loadFromFile(FileHandler $handler): Collection
+ {
+ // initalise a Vendor Collection
+ $collection = new Collection;
+
+ foreach ($handler->getVendorArray() as $vendorRaw) {
+ $collection[] = new Vendor($vendorRaw);
+ }
+
+ return $collection;
+ }
+
+ /**
+ * Filter the menus base on a given date
+ * Return true if at least one menu is still valid
+ * Otherwose return false
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param DateTime $date
+ * @return bool
+ */
+ public function checkDate(DateTime $date): bool
{
$out = [];
$now = new DateTime();
@@ -126,7 +181,14 @@ class Vendor extends Model
return true;
}
- public function checkLocation(string $location)
+ /**
+ * Return true if the first charaters of the given string matche the first characters of the postcode
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param string $location
+ * @return bool
+ */
+ public function checkLocation(string $location): bool
{
$postPrefix = '';
@@ -141,7 +203,14 @@ class Vendor extends Model
return strtoupper($postPrefix) === strtoupper($location);
}
- public function checkMaxCovers(int $covers)
+ /**
+ * Return true if the given covers int is less or equal to the max covers int this vendor supports
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param int $covers
+ * @return bool
+ */
+ public function checkMaxCovers(int $covers): bool
{
if ($this->maxCovers >= $covers) {
return true;
@@ -150,7 +219,13 @@ class Vendor extends Model
return false;
}
- public function toString()
+ /**
+ * Return a string representation of this vendor
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @return string
+ */
+ public function toString(): string
{
$out = [
$this->name . ';' . $this->postcode . ';' . $this->maxCovers
@@ -160,6 +235,6 @@ class Vendor extends Model
$out[] = $menu->toString();
}
- return $out;
+ return implode("\n", $out);
}
}