From 5dcc17f78f1e8a2e0e3754cb8afb819d60c8ce01 Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Tue, 14 Nov 2023 11:55:21 +0100 Subject: [PATCH] fix return --- src/Service/GithubApiService.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index bd9b0457..f251ae7e 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -187,14 +187,8 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr // Get the publiccode/opencatalogi files of the given repository. $dataArray = $this->getFilesFromRepo($repositoryUrl, $source); - if ($dataArray !== null) { - // Import the publiccode/opencatalogi files and connect it to the repository. - $repository = $this->importRepoFiles($dataArray, $source, $repositorySync->getObject()); - } - - if (isset($repository) === false) { - $repository = $repositorySync->getObject(); - } + // Import the publiccode/opencatalogi files and connect it to the repository. + $repository = $this->importRepoFiles($dataArray, $source, $repositorySync->getObject()); // Cleanup the repository. $repository = $this->cleanupRepository($repository); @@ -220,7 +214,7 @@ public function cleanupRepository(ObjectEntity $repository): ?ObjectEntity { // If the repository has one or less components return. if ($repository->getValue('components')->count() <= 1) { - return null; + return $repository; } // Loop through the components and remove the component we created. @@ -247,8 +241,10 @@ public function cleanupRepository(ObjectEntity $repository): ?ObjectEntity * @param Source $source The github api source. * * @throws GuzzleException + * + * @return ObjectEntity */ - public function enrichWithOrganization(ObjectEntity $repository, array $repositoryArray, Source $source): void + public function enrichWithOrganization(ObjectEntity $repository, array $repositoryArray, Source $source): ObjectEntity { $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); @@ -266,6 +262,8 @@ public function enrichWithOrganization(ObjectEntity $repository, array $reposito $this->entityManager->persist($repository); $this->entityManager->flush(); + return $repository; + }//end enrichWithOrganization() @@ -277,8 +275,10 @@ public function enrichWithOrganization(ObjectEntity $repository, array $reposito * @param Source $source The github api source. * * @throws GuzzleException + * + * @return ObjectEntity */ - public function enrichWithComponent(ObjectEntity $repository, array $repositoryArray, Source $source): void + public function enrichWithComponent(ObjectEntity $repository, array $repositoryArray, Source $source): ObjectEntity { $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); @@ -287,6 +287,8 @@ public function enrichWithComponent(ObjectEntity $repository, array $repositoryA $this->entityManager->persist($componentSync); $this->entityManager->flush(); + return $repository; + }//end enrichWithComponent() @@ -303,12 +305,12 @@ public function enrichRepository(ObjectEntity $repository, array $repositoryArra { // If there is no organization create one. if ($repository->getValue('organisation') === false) { - $this->enrichWithOrganization($repository, $repositoryArray, $source); + $repository = $this->enrichWithOrganization($repository, $repositoryArray, $source); } // If there is no component create one. if ($repository->getValue('components')->count() === 0) { - $this->enrichWithComponent($repository, $repositoryArray, $source); + $repository = $this->enrichWithComponent($repository, $repositoryArray, $source); } // @TODO: enrich the null values with what we have.