value}' since '{$since->format(\DATE_ATOM)}'"; $this->logger->debug("Fetching {$action}"); $result = $this->employeeService->streamAllOfSitesSince( sites: $this->mapSiteCodeToLib($site), pageSize: new LibPageSize(self::DEFAULT_PAGE_SIZE), since: $since ); $this->logger->debug("Succeed fetching {$action}"); /** @var \App\Services\ArcadiaEmployee[] $output */ $output = []; $apiError = $result->each( function (LibEmployee $libEmployee) use (&$output) { $output[] = $this->mapLibEmployees($libEmployee); } ); if ($apiError instanceof ApiError) { $message = "Failed to fetch {$action}, reason {$apiError->message()}"; $this->logger->error($message); report(new \RuntimeException($message)); return false; } return $output; } /** @return \App\Services\ArcadiaEmployee|null|false Returns false when fetching fails. */ public function employeeExists(Matricule $matricule): ArcadiaEmployee | null | false { $action = 'specific employee using matricule'; $this->logger->debug("Fetching {$action}"); $arcadiaEmployeeId = $this->mapMatriculeToLib($matricule); $result = $this->employeeService->findBy($arcadiaEmployeeId); if ($result instanceof ApiError) { $message = "Failed to fetch {$action}, reason {$result->message()}"; $this->logger->error($message); report(new \RuntimeException($message)); return false; } if ($result instanceof LibEmployee) { return $this->mapLibEmployees($result); } $this->logger->debug("Succeed fething {$action}"); return null; } private function mapLibEmployees(LibEmployee $libEmployee): ArcadiaEmployee { return new ArcadiaEmployee( new Matricule($libEmployee->matriculePublique->value), $libEmployee->lastname, $libEmployee->firstname, $libEmployee->start_date, $libEmployee->end_date, new ShopperEstablishmentCode($libEmployee->establishment->value), new ShopperSiteCode($libEmployee->site->value), new ShopperServiceCode($libEmployee->service->value), ); } private function mapSiteCodeToLib(ShopperSiteCode $site): LibSiteId { return new LibSiteId($site->value); } private function mapMatriculeToLib(Matricule $value): LibArcadiaEmployeeId { return new LibArcadiaEmployeeId($value->value); } }