*/ private array $revenues = [ '01' => 0, // ... '12' => 0, ]; public function __construct(private string $year) {} public function increaseMonthlyRevenue(string $month, float $amount): void { $this->revenues[$month] += $amount; } /** * @return array<int, array{month: string, year: string, profit: float}> */ public function toArray(): array { $results = []; foreach ($this->revenues as $month => $revenue) { $results[] = [ 'year' => $this->year, 'month' => $month, 'profit' => $revenue, ]; } return $results; } }