Commit 42ab83ec authored by John Voskuilen's avatar John Voskuilen
Browse files

Issue #3219111: Clean code - Introduce constant OfficeHoursDateHelper::DAYS_PER_WEEK

parent 52aa3971
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ class OfficeHoursDateHelper extends DateHelper {
  /**
   * @var int
   */
  const daysPerWeek = 7;
  const DAYS_PER_WEEK = 7;

  /**
   * Gets the day number of first day of the week.
@@ -290,7 +290,7 @@ class OfficeHoursDateHelper extends DateHelper {
    $first_day = ($first_day == '') ? OfficeHoursDateHelper::getFirstDay() : $first_day;
    // Sort Weekdays; leave Exception days at bottom of list.
    foreach ($office_hours as $key => $item) {
      $new_office_hours[$key - (OfficeHoursDateHelper::daysPerWeek * (int) ($key >= $first_day))] = $item;
      $new_office_hours[$key - (OfficeHoursDateHelper::DAYS_PER_WEEK * (int) ($key >= $first_day))] = $item;
    }
    // @todo Use pattern from extractFormValues(), avoiding key-change.
    // usort($values, function ($a, $b) {
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ trait OfficeHoursFormatterTrait {
    // Initialize days and times, using date_api as key (0=Sun, 6=Sat).
    // Empty days are not yet present in $values, and are now added in $days.
    $office_hours = [];
    for ($day = 0; $day < OfficeHoursDateHelper::daysPerWeek; $day++) {
    for ($day = 0; $day < OfficeHoursDateHelper::DAYS_PER_WEEK; $day++) {
      $office_hours[$day] = ['startday' => $day] + $default_office_hours;
    }

+3 −3
Original line number Diff line number Diff line
@@ -381,8 +381,8 @@ abstract class OfficeHoursFormatterBase extends FormatterBase {
          if ($next['startday'] != $today) {
            // We will open tomorrow or later.
            $next_time = $start;
            $add_days = ($next['startday'] - $today + OfficeHoursDateHelper::daysPerWeek)
              % OfficeHoursDateHelper::daysPerWeek;
            $add_days = ($next['startday'] - $today + OfficeHoursDateHelper::DAYS_PER_WEEK)
              % OfficeHoursDateHelper::DAYS_PER_WEEK;
            break;
          }
          elseif ($start > $now) {
@@ -405,7 +405,7 @@ abstract class OfficeHoursFormatterBase extends FormatterBase {
              $first_time_slot_found = TRUE;

              $next_time = $start;
              $add_days = OfficeHoursDateHelper::daysPerWeek;
              $add_days = OfficeHoursDateHelper::DAYS_PER_WEEK;
            }
            continue; // A new slot might come along.
          }
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class OfficeHoursDefaultWidget extends OfficeHoursWidgetBase {
      ->getCardinality();
    if ($field_cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
      $this->fieldDefinition->getFieldStorageDefinition()
        ->setCardinality($this->getFieldSetting('cardinality_per_day') * OfficeHoursDateHelper::daysPerWeek);
        ->setCardinality($this->getFieldSetting('cardinality_per_day') * OfficeHoursDateHelper::DAYS_PER_WEEK);
    }

    $elements = parent::formMultipleElements($items, $form, $form_state);
+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ class CSVOfficeHoursField extends OfficeHoursField {
    $delimiter = isset($this->configuration['delimiter']) ? $this->configuration['delimiter'] : '-';
    $has_comment = isset($this->configuration['comment']) ? $this->configuration['comment'] : FALSE;

    if (count($value) !== ($slots_per_day * ($has_comment ? 2 : 1) * OfficeHoursDateHelper::daysPerWeek)) {
    if (count($value) !== ($slots_per_day * ($has_comment ? 2 : 1) * OfficeHoursDateHelper::DAYS_PER_WEEK)) {
      throw new MigrateException(sprintf('%s does not have the correct size', var_export($value, TRUE)));
    }