unprocessable[] = $rawEntry; throw $e; } if(in_array(trim(mb_strtolower($inputEntity->description)), $this->descriptions)) { $this->unprocessable[] = $rawEntry; throw new \InvalidArgumentException('Duplicate description'); } $entity = $this->create($inputEntity); Log::channel('parser')->info('Created entity ', [ 'number' => $inputEntity->number, 'type' => $entity->type->value, ]); if($entity) { $this->entities[] = $entity; $this->descriptions[] = trim(mb_strtolower($inputEntity->description)); return true; } $this->unprocessable[] = $rawEntry; return false; } public function getUnprocessable(): array { return $this->unprocessable; } public function getInspections(): array { return $this->getEntities(Inspection::class)->map->__toArray()->all(); } public function getInspectionsCount(): int { return $this->getEntities(Inspection::class)->count(); } public function getFailureReports(): array { return $this->getEntities(FailureReport::class)->map->__toArray()->all();; } public function getFailureReportsCount(): int { return $this->getEntities(FailureReport::class)->count(); } private function getEntities($type): Collection { return collect($this->entities) ->whereInstanceOf($type) ->values(); } private function create(InputEntity $inputEntity) { foreach ($this->types as $type) { if($type::isValid($inputEntity)) { return new $type($inputEntity); } } return null; } }