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/Script/Console.php | 6 ++++-- src/Script/Input.php | 13 +++++++++++++ src/Script/Output.php | 24 ++++++++++++++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) (limited to 'src/Script') 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 */ 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 */ 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 + */ class Output { + /** + * Echo out the output data + * + * @author Phil Burton + * @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 + * @param Exception $e + */ public function printException(Exception $e) { echo "An unexpected exception occured:\n" . $e->getMessage() . "\n"; -- cgit v1.2.3