Skip to content

Commit

Permalink
Address errors/warnings raised by phpcs when run on Services/OpenStre…
Browse files Browse the repository at this point in the history
…etMap/OpeningHours.php
  • Loading branch information
kenguest committed Jan 4, 2013
1 parent 42e397f commit 2d1dd15
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions Services/OpenStreetMap/OpeningHours.php
Expand Up @@ -57,7 +57,8 @@ public function setValue($value)
* Return true, false or null depending on whether the [opening hours]
* value explicitly indicates an open, closed or undecided result.
*
* @param double $time A numeric value representing a time. If null, the current time is used.
* @param double $time A numeric value representing a time. If null, the
* current time is used.
*
* @link http://wiki.openstreetmap.org/wiki/Key:opening_hours
* @return null|boolean
Expand Down Expand Up @@ -126,6 +127,7 @@ private function _openTimeSpec($portions, $time)

$day = strtolower(substr(date('D', $time), 0, 2));
$days = $this->_daySpecToArray($portions[0]);
$pattern = '/^[0-2][0-9]:[0-5][0-9]\+$/';
if (is_array($days)) {
foreach ($days as $rday) {
if ($rday == $day) {
Expand All @@ -134,7 +136,9 @@ private function _openTimeSpec($portions, $time)
if (strtolower($time_spec) == 'off') {
return false;
}
if (strpos($time_spec, '-') && (strpos($time_spec, ',') === false)) {
if (strpos($time_spec, '-')
&& (strpos($time_spec, ',') === false)
) {
// specified starting and end times for just one range - not
// comma delimited.
$startend_times = explode('-', $time_spec);
Expand All @@ -156,7 +160,7 @@ private function _openTimeSpec($portions, $time)
}
}
return false;
} elseif (preg_match('/^[0-2][0-9]:[0-5][0-9]\+$/', $time_spec)) {
} elseif (preg_match($pattern, $time_spec)) {
// open-ended.
if ($this->_evaluateOpenEnded($time_spec) === false) {
return false;
Expand All @@ -166,7 +170,9 @@ private function _openTimeSpec($portions, $time)
}
} else {
// here we go again... need to refactor/decide a better algorithm.
$months = array('jan', 'feb', 'mar', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
$months = array(
'jan', 'feb', 'mar', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'
);
if (in_array($portions[0], $months)) {
$month = strtolower(date('M', $time));
$time_spec = trim($portions[1]);
Expand Down Expand Up @@ -232,23 +238,49 @@ private function _daySpecToArray($day_specification)
}
}

/**
* Return true/false depending on whether a given time_spec value is
* open-ended.
*
* @param string $time_spec Timespec
*
* @return bool
*/
private function _evaluateOpenEnded($time_spec)
{
$start = $this->_startTime($time_spec);
$d = getdate($time);
$ctime = $d['hours'] * 60 + $d['minutes'];
if ($ctime < $start) {
return false;
} else {
return true;
}
}

/**
* Return number of seconds representing the start time in
* the provided time_spec string.
*
* @param string $time_spec Timespec
*
* @return int
*/
private function _startTime($time_spec)
{
$starthour = substr($time_spec, 0, 2);
$startmin = substr($time_spec, 3, 2);
return $starthour * 60 + $startmin;
}

/**
* Return number of seconds representing the end time in
* the provided time_spec string.
*
* @param string $time_spec Timespec
*
* @return int
*/
private function _endTime($time_spec)
{
$endhour = substr($time_spec, 0, 2);
Expand Down

0 comments on commit 2d1dd15

Please sign in to comment.