Skip to content

Commit

Permalink
Merge 2ad4550 into 5082376
Browse files Browse the repository at this point in the history
  • Loading branch information
200MPH committed Jan 10, 2020
2 parents 5082376 + 2ad4550 commit ff9844b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ php:
- '5.6'
- '7.0'
- '7.1'
- 'hhvm'
install:
- composer update
script:
- ./vendor/bin/phpunit --coverage-clover ./tests/Logs/clover.xml
after_script:
- php vendor/bin/php-coveralls -v
- php vendor/bin/php-coveralls -v
38 changes: 18 additions & 20 deletions src/Factories/UkBankHolidayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@
abstract class UkBankHolidayFactory
{
private static $dataRetriver;
private static $dates = [];

private static function setUpDataRetriever()
{
self::$dataRetriver = new GovUkDataRetriever();
}

public static function getAll($location = 'england-and-wales')
{
{
if(empty(self::$dates[$location]) === false) {
return self::$dates[$location];
}
self::setUpDataRetriever();
$dates = self::$dataRetriver->retrieve($location);

return $dates;
self::$dates[$location] = self::$dataRetriver->retrieve($location);
return self::$dates[$location];
}

public static function getByMonth($year, $month, $location = 'england-and-wales')
{
$dates = self::getAll($location);
$dateRange = [];
foreach ($dates as $date) {
if (date('Y', strtotime($date->date)) == $year && date('m', strtotime($date->date)) == $month) {
$dateRange[] = $date;
}
$dates = self::getAll($location);
if(!isset($dates[$year][$month])) {
return [];
}

return $dateRange;
return $dates[$year][$month];
}

public static function getByDate($year, $month, $day, $location = 'england-and-wales')
{
$dates = self::getByMonth($year, $month, $location);
$dateRange = [];
foreach ($dates as $date) {
if (date('d', strtotime($date->date)) == $day) {
$dateRange[] = $date;
}
$dates = self::getByMonth($year, $month, $location);
if(!isset($dates[$day])) {
return [];
}

return $dateRange;
return $dates[$day];
}
}
3 changes: 2 additions & 1 deletion src/Objects/CacheDrivers/DOFileCacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct()
[
'cacheDirectory' => '/tmp/php-uk-bank-holidays-cache/',
'gzipCompression' => true,
]
]
);
}

Expand All @@ -27,6 +27,7 @@ public function set($key, $value)
$cacheItem = $this->cache->getItem($key);
$cacheItem->set($value);
$cacheItem->expiresAfter(self::CACHE_EXPIRY_IN_SECONDS);
$this->cache->save($cacheItem);
}

public function get($key)
Expand Down
3 changes: 2 additions & 1 deletion src/Objects/DataRetrievers/GovUkDataRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public function retrieve($location)
$bankHolidayDates = [];

foreach ($data[$location]['events'] as $holidayDate) {
list($year, $month, $day) = explode('-', $holidayDate['date']);
$bankHolidayDate = new UkBankHoliday($holidayDate['title'], $holidayDate['date'], $holidayDate['notes']);
$bankHolidayDates[] = $bankHolidayDate;
$bankHolidayDates[$year][$month][$day][] = $bankHolidayDate;
}

return $bankHolidayDates;
Expand Down

0 comments on commit ff9844b

Please sign in to comment.