diffInMonths($end) > 1) { $period = 'Year'; } // more than one year date difference means multi year report. if ($start->diffInMonths($end) > 12) { $period = 'MultiYear'; } $class = sprintf('FireflyIII\Generator\Report\%s\%sReportGenerator', $type, $period); if (class_exists($class)) { /** @var ReportGeneratorInterface $obj */ $obj = new $class; $obj->setStartDate($start); $obj->setEndDate($end); return $obj; } throw new FireflyException(sprintf('Cannot generate report. There is no "%s"-report for period "%s".', $type, $period)); } }