From df90c25a87021e543a81b4903d51ceee20edf76e Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 26 Jan 2018 13:33:46 +0000 Subject: [PATCH] Refactoring retrieval of holidays by location, now uses 'england-and-wales' instead of 'england-wales' --- README.md | 2 +- src/Factories/UkBankHolidayFactory.php | 25 +++---------------- .../DataRetrievers/GovUkDataRetriever.php | 22 +++++----------- tests/Unit/HolidayRetrievalByLocationTest.php | 2 +- 4 files changed, 12 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index afd61c1..627a698 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ If you wish to retrieve bank holidays from Scotland or Northern Ireland, make us argument, as follows. ```php -$englandWalesHolidays = UkBankHolidayFactory::getByDate(2017, 01, 2, 'england-wales'); +$englandWalesHolidays = UkBankHolidayFactory::getByDate(2017, 01, 2, 'england-and-wales'); $scotlandHolidays = UkBankHolidayFactory::getByDate(2017, 01, 2, 'scotland'); $northernIrelandHolidays = UkBankHolidayFactory::getByDate(2017, 01, 2, 'northern-ireland'); diff --git a/src/Factories/UkBankHolidayFactory.php b/src/Factories/UkBankHolidayFactory.php index 03c5eb6..8d2a7ff 100755 --- a/src/Factories/UkBankHolidayFactory.php +++ b/src/Factories/UkBankHolidayFactory.php @@ -13,31 +13,14 @@ private static function setUpDataRetriever() self::$dataRetriver = new GovUkDataRetriever(); } - public static function getAll($location = "england-wales") + public static function getAll($location = 'england-and-wales') { self::setUpDataRetriever(); - switch($location) - { - case"england-wales": - $dates = self::$dataRetriver->retrieveEnglandAndWales(); - break; - - case"scotland": - $dates = self::$dataRetriver->retrieveScotland(); - break; - - case"northern-ireland": - $dates = self::$dataRetriver->retrieveNorthernIreland(); - break; - - default: - throw new exception("Specified Location is invalid"); - break; - } + $dates = self::$dataRetriver->retrieve($location); return $dates; } - public static function getByMonth($year,$month,$location = "england-wales") + public static function getByMonth($year,$month,$location = 'england-and-wales') { $dates = self::getAll($location); $dateRange = array(); @@ -48,7 +31,7 @@ public static function getByMonth($year,$month,$location = "england-wales") } return $dateRange; } - public static function getByDate($year,$month,$day,$location = "england-wales") + public static function getByDate($year,$month,$day,$location = 'england-and-wales') { $dates = self::getByMonth($year,$month,$location); $dateRange = array(); diff --git a/src/Objects/DataRetrievers/GovUkDataRetriever.php b/src/Objects/DataRetrievers/GovUkDataRetriever.php index c8c264e..c7e1793 100755 --- a/src/Objects/DataRetrievers/GovUkDataRetriever.php +++ b/src/Objects/DataRetrievers/GovUkDataRetriever.php @@ -11,6 +11,7 @@ class GovUkDataRetriever private $cache = null; private $cacheKey = 'GovUkBankHolidays'; + private $acceptableLocations = ['england-and-wales', 'scotland', 'northern-ireland']; private function setupCache() { @@ -21,8 +22,12 @@ private function setupCache() } } - private function retrieve($location) + public function retrieve($location) { + if (!in_array($location, $this->acceptableLocations)) { + throw new Exception('Invalid location specified. Acceptable locations: '.implode(', ', $this->acceptableLocations)); + } + $this->setupCache(); if (!($data = $this->cache->get($this->cacheKey))) { @@ -57,19 +62,4 @@ private function retrieve($location) return $bankHolidayDates; } - public function retrieveEnglandAndWales() - { - return $this->retrieve("england-and-wales"); - } - - public function retrieveScotland() - { - return $this->retrieve("scotland"); - } - - public function retrieveNorthernIreland() - { - return $this->retrieve("northern-ireland"); - } - } diff --git a/tests/Unit/HolidayRetrievalByLocationTest.php b/tests/Unit/HolidayRetrievalByLocationTest.php index c716864..dbd4b8f 100644 --- a/tests/Unit/HolidayRetrievalByLocationTest.php +++ b/tests/Unit/HolidayRetrievalByLocationTest.php @@ -18,7 +18,7 @@ private function checkHolidaysArrayFormat($holidays) public function testEnglandWales() { - $this->checkHolidaysArrayFormat(UkBankHolidayFactory::getAll('england-wales')); + $this->checkHolidaysArrayFormat(UkBankHolidayFactory::getAll('england-and-wales')); } public function testScotland()