Skip to content

Commit

Permalink
Refactoring retrieval of holidays by location, now uses 'england-and-…
Browse files Browse the repository at this point in the history
…wales' instead of 'england-wales'
  • Loading branch information
Jordan Hall committed Jan 26, 2018
1 parent 38019cc commit df90c25
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
25 changes: 4 additions & 21 deletions src/Factories/UkBankHolidayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
22 changes: 6 additions & 16 deletions src/Objects/DataRetrievers/GovUkDataRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class GovUkDataRetriever

private $cache = null;
private $cacheKey = 'GovUkBankHolidays';
private $acceptableLocations = ['england-and-wales', 'scotland', 'northern-ireland'];

private function setupCache()
{
Expand All @@ -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))) {
Expand Down Expand Up @@ -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");
}

}
2 changes: 1 addition & 1 deletion tests/Unit/HolidayRetrievalByLocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit df90c25

Please sign in to comment.