Skip to content

Commit

Permalink
Merge PR #623 from @zonky2
Browse files Browse the repository at this point in the history
- Fix group per week: code style
  • Loading branch information
stefanheimes committed Nov 30, 2023
2 parents cf7f3a4 + f68c69f commit de1d82a
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class GetGroupHeaderSubscriber
*
* @var EventDispatcherInterface
*/
private $dispatcher;
private EventDispatcherInterface $dispatcher;

/**
* The translator.
*
* @var TranslatorInterface
*/
private $translator;
private TranslatorInterface $translator;

/**
* Create a new instance.
Expand Down Expand Up @@ -136,6 +136,7 @@ protected function formatGroupHeader(
if (isset($evaluation['multiple']) && !$evaluation['multiple'] && ('checkbox' === $property->getWidgetType())) {
return $this->formatCheckboxOptionLabel($model->getProperty($property->getName()));
}

if (GroupAndSortingInformationInterface::GROUP_NONE !== $groupingMode) {
return $this->formatByGroupingMode($groupingMode, $groupingLength, $environment, $property, $model);
}
Expand Down Expand Up @@ -240,9 +241,9 @@ private function formatByCharGrouping($value, $groupingLength)
*
* @param int $value The value.
*
* @return string|null
* @return string
*/
private function formatByDayGrouping(int $value): ?string
private function formatByDayGrouping(int $value): string
{
$value = $this->getTimestamp($value);

Expand All @@ -263,13 +264,14 @@ private function formatByDayGrouping(int $value): ?string
*
* @return string
*/
private function formatByWeekGrouping(int $value): ?string
private function formatByWeekGrouping(int $value): string
{
$value = $this->getTimestamp($value);

if (0 === $value) {
return '-';
}

$event = new ParseDateEvent($value, $this->translator->translate('MSC.week_format'));
$this->dispatcher->dispatch($event, ContaoEvents::DATE_PARSE);

Expand All @@ -281,15 +283,16 @@ private function formatByWeekGrouping(int $value): ?string
*
* @param int $value The value.
*
* @return string|null
* @return string
*/
private function formatByMonthGrouping(int $value): ?string
private function formatByMonthGrouping(int $value): string
{
$value = $this->getTimestamp($value);

if (0 === $value) {
return '-';
}

$event = new ParseDateEvent($value, 'F Y');
$this->dispatcher->dispatch($event, ContaoEvents::DATE_PARSE);

Expand Down Expand Up @@ -317,11 +320,11 @@ private function formatByYearGrouping($value)
/**
* Make sure a timestamp is returned.
*
* @param int|\DateTime $value The given date.
* @param \DateTime|int $value The given date.
*
* @return int
*/
private function getTimestamp($value)
private function getTimestamp(\DateTime|int $value): int
{
return ($value instanceof \DateTime) ? $value->getTimestamp() : $value;
}
Expand Down

0 comments on commit de1d82a

Please sign in to comment.