books = $books; $this->from = $from; $this->to = $to; } public function sheets(): array { $sheets = []; foreach ($this->books as $book) { $sheets[] = $this->getSheet($book); } return $sheets; } protected function getSheet(Book $book) { if($book->isComeIn()){ return new ComeInDocumentsExport($book->documents, $book->name, $this->from, $this->to); } if($book->isComeOut()){ return new ComeOutDocumentsExport($book->documents, $book->name, $this->from, $this->to); } if($book->isPrivate()){ return new PrivateDocumentsExport($book->documents, $book->name, $this->from, $this->to); } } }