Skip to content

Commit

Permalink
Optimize the between filter class.
Browse files Browse the repository at this point in the history
Using a single return statement in the accept() method as it is more efficient than using two return statements, and it
avoids the need to evaluate the expression in the second return statement if the first return statement is evaluated
to true.

Signed-off-by: Sacha Telgenhof <[email protected]>
  • Loading branch information
stelgenhof committed Oct 22, 2023
1 parent eaeb1d3 commit cedccb6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/Yasumi/Filters/BetweenFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public function accept(): bool
{
$holiday = $this->getInnerIterator()->current()->format(self::DATE_FORMAT);

if ($this->equal) {
return $holiday >= $this->startDate && $holiday <= $this->endDate;
}

return $holiday > $this->startDate && $holiday < $this->endDate;
return $this->equal
? $holiday >= $this->startDate && $holiday <= $this->endDate
: $holiday > $this->startDate && $holiday < $this->endDate;
}
}

0 comments on commit cedccb6

Please sign in to comment.