Skip to content
Snippets Groups Projects

Resolve #3497013 "Refactor switch in"

2 unresolved threads

Closes #3497013

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
80 break;
81
82 case 'year':
83 $formula = $this->getDateFormat('Y');
84 break;
57 $formula = match ($this->options['granularity']) {
58 'minute' => $this->getDateFormat('YmdHi'),
59 'hour' => $this->getDateFormat('YmdH'),
60 'day' => $this->getDateFormat('Ymd'),
61 'month' => $this->getDateFormat('Ym'),
62 'year' => $this->getDateFormat('Y'),
63 default => NULL,
64 };
65
66 if ($formula) {
67 // Add the field.
  • Joachim Noreiko added 9 commits

    added 9 commits

    Compare with previous version

  • 85 }
    57 // Determine whether to use a formula in the query.
    58 $formula = match ($this->options['granularity']) {
    59 'minute' => $this->getDateFormat('YmdHi'),
    60 'hour' => $this->getDateFormat('YmdH'),
    61 'day' => $this->getDateFormat('Ymd'),
    62 'week' => $this->getDateFormat('W'),
    63 'month' => $this->getDateFormat('Ym'),
    64 'year' => $this->getDateFormat('Y'),
    65 default => NULL,
    66 };
    86 67
    87 68 // Add the field.
    88 $this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
    69 if ($formula) {
    70 $this->query->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
    • Before both these orderedBys were added now only 1 would be applied. Also not sure this is much better. Why can't seconds be added to the match like the rest of the switch?

    • I don't know what you mean. Without the MR, only one addOrderBy() is applied -- the 'second' and 'default' case has a return statement.

      We could add a 'seconds' => NULL arm to be more explicit.

    • Please register or sign in to reply
  • added 1 commit

    • 41ee8fdc - Explicitly set the second parameter to null

    Compare with previous version

  • added 1 commit

    • 221a0b81 - Reorder granularity options in ascending order

    Compare with previous version

  • added 1 commit

    • 6675ce96 - Changing the order of granularity.

    Compare with previous version

  • Please register or sign in to reply
    Loading