summaryrefslogtreecommitdiff
path: root/src/Script
diff options
context:
space:
mode:
Diffstat (limited to 'src/Script')
-rw-r--r--src/Script/Console.php6
-rw-r--r--src/Script/Input.php13
-rw-r--r--src/Script/Output.php24
3 files changed, 35 insertions, 8 deletions
diff --git a/src/Script/Console.php b/src/Script/Console.php
index 3228750..ee8114e 100644
--- a/src/Script/Console.php
+++ b/src/Script/Console.php
@@ -46,12 +46,14 @@ class Console
public function exec()
{
$output = new Output;
+
try {
$input = new Input;
+ // Get vendor data
$vendors = Vendor::loadAll($input->getOption('f'));
-
+ // Filter data
$vendors->filterByInput($input);
-
+ // Output data
$output->printCollection($vendors);
} catch (Exception $e) {
$output->printException($e);
diff --git a/src/Script/Input.php b/src/Script/Input.php
index 772bb8c..6a91a72 100644
--- a/src/Script/Input.php
+++ b/src/Script/Input.php
@@ -6,6 +6,8 @@ use Exception;
/**
* Input handler for CLI arugments and options
+ *
+ * @author Phil Burton <phil@pgburton.com>
*/
class Input
{
@@ -21,6 +23,16 @@ class Input
*/
protected $shortOpts = 'f:d::t::l::c::';
+ /**
+ * Available CLI options
+ * f filename - input file with the vendors data
+ * d day - delivery day (dd/mm/yy)
+ * t time - delivery time in 24h format (hh:mm)
+ * l location - delivery location (postcode without spaces, e.g. NW43QB)
+ * c covers - number of people to feed
+ *
+ * @var string
+ */
protected $longOpts = [
'filename:',
'day::',
@@ -48,6 +60,7 @@ class Input
/**
* Load options, make sure required options are set
+ * Throw an exception if input data is badly formatted
*
* @author Phil Burton <phil@pgburton.com>
*/
diff --git a/src/Script/Output.php b/src/Script/Output.php
index e61cff8..4598dc1 100644
--- a/src/Script/Output.php
+++ b/src/Script/Output.php
@@ -5,8 +5,19 @@ namespace App\Script;
use App\Model\Collection;
use Exception;
+/**
+ * Handle output to CLI
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
class Output
{
+ /**
+ * Echo out the output data
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param Collection $collection
+ */
public function printCollection(Collection $collection)
{
if (count($collection) === 0) {
@@ -14,14 +25,15 @@ class Output
return;
}
- $out = [];
- foreach ($collection as $vendor) {
- $out[] = implode("\n", $vendor->toString());
- }
-
- echo implode("\n\n", $out) . "\n";
+ echo $collection->toString() . "\n";
}
+ /**
+ * Output the exception message
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ * @param Exception $e
+ */
public function printException(Exception $e)
{
echo "An unexpected exception occured:\n" . $e->getMessage() . "\n";