requestStack->getCurrentRequest(); $tax = $request?->query->get('tax', 'th'); $year = $request?->query->getInt('year', 2023); $rateColumn = $this->resolveRateColumn($tax); $sql = <<connection->fetchAllAssociative($sql, ['year' => $year]); foreach ($rows as $row) { $item = new RegionalDistribution(); $item->regionCode = (string) $row['region_code']; $item->regionName = (string) $row['region_name']; $item->collectedVolume = (float) $row['collected_volume']; yield $item; } } private function resolveRateColumn(?string $tax): string { return match (strtolower((string) $tax)) { 'tfpnb' => 'rate_tfpnb', 'tfpb' => 'rate_tfpb', 'th' => 'rate_th', 'cfe' => 'rate_cfe', default => 'rate_tfpb', }; } }