From cc0090f0d2871f4d4feb61a3214b0831a392ee3f Mon Sep 17 00:00:00 2001 From: Sarai Misidjan Date: Tue, 14 Nov 2023 11:14:33 +0100 Subject: [PATCH 1/2] merge conflic --- src/Service/GithubApiService.php | 958 +++++++++++++++---------------- 1 file changed, 478 insertions(+), 480 deletions(-) diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index 158d2035..b95d57f4 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -81,39 +81,40 @@ class GithubApiService /** - * @param EntityManagerInterface $entityManager The Entity Manager Interface - * @param CallService $callService The Call Service - * @param SynchronizationService $syncService The Synchronisation Service - * @param CacheService $cacheService The Cache Service - * @param MappingService $mappingService The Mapping Service - * @param RatingService $ratingService The Rating Service. - * @param LoggerInterface $pluginLogger The plugin version of the logger interface - * @param GatewayResourceService $resourceService The Gateway Resource Service. - * @param HydrationService $hydrationService The Hydration Service. + * @param EntityManagerInterface $entityManager The Entity Manager Interface + * @param CallService $callService The Call Service + * @param SynchronizationService $syncService The Synchronisation Service + * @param CacheService $cacheService The Cache Service + * @param MappingService $mappingService The Mapping Service + * @param RatingService $ratingService The Rating Service. + * @param LoggerInterface $pluginLogger The plugin version of the logger interface + * @param GatewayResourceService $resourceService The Gateway Resource Service. + * @param HydrationService $hydrationService The Hydration Service. */ public function __construct( EntityManagerInterface $entityManager, - CallService $callService, + CallService $callService, SynchronizationService $syncService, - CacheService $cacheService, - MappingService $mappingService, - RatingService $ratingService, - LoggerInterface $pluginLogger, + CacheService $cacheService, + MappingService $mappingService, + RatingService $ratingService, + LoggerInterface $pluginLogger, GatewayResourceService $resourceService, - HydrationService $hydrationService - ) { - $this->entityManager = $entityManager; - $this->callService = $callService; - $this->syncService = $syncService; - $this->cacheService = $cacheService; - $this->mappingService = $mappingService; - $this->ratingService = $ratingService; - $this->pluginLogger = $pluginLogger; - $this->resourceService = $resourceService; + HydrationService $hydrationService + ) + { + $this->entityManager = $entityManager; + $this->callService = $callService; + $this->syncService = $syncService; + $this->cacheService = $cacheService; + $this->mappingService = $mappingService; + $this->ratingService = $ratingService; + $this->pluginLogger = $pluginLogger; + $this->resourceService = $resourceService; $this->hydrationService = $hydrationService; $this->configuration = []; - $this->data = []; + $this->data = []; }//end __construct() @@ -128,7 +129,7 @@ public function __construct( public function checkGithubAuth(Source $source): ?bool { if ($source->getApiKey() === null) { - $this->pluginLogger->error('No auth set for Source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->error('No auth set for Source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return false; }//end if @@ -141,15 +142,15 @@ public function checkGithubAuth(Source $source): ?bool /** * This function gets repository and enriches it. * - * @param string $repositoryUrl The url of the repository + * @param string $repositoryUrl The url of the repository * @param array|null $repositoryArray The repository array from the github api. * * @return ObjectEntity|null * @throws Exception */ - public function getGithubRepository(string $repositoryUrl, ?array $repositoryArray=null): ?ObjectEntity + public function getGithubRepository(string $repositoryUrl, ?array $repositoryArray = null): ?ObjectEntity { - $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); + $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); $repositoryMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubRepository.mapping.json', 'open-catalogi/open-catalogi-bundle'); if ($repositorySchema instanceof Entity === false || $repositoryMapping instanceof Mapping === false @@ -209,9 +210,6 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr }//end getGithubRepository() -}//end class - - /** * This function does a cleanup for the repository. * @@ -219,421 +217,421 @@ public function getGithubRepository(string $repositoryUrl, ?array $repositoryArr * * @return ObjectEntity|null Return the repository */ -public function cleanupRepository(ObjectEntity $repository): ?ObjectEntity -{ - // If the repository has one or less components return. - if ($repository->getValue('components')->count() <= 1) { - return null; - } - - // Loop through the components and remove the component we created. - foreach ($repository->getValue('components') as $component) { - $componentSourceId = $component->getSynchronizations()->first()->getSourceId(); - - // If the component source id is the same as the repository url remove the component. - if ($componentSourceId === $repository->getValue('url')) { - $this->entityManager->remove($component); - $this->entityManager->flush(); + public function cleanupRepository(ObjectEntity $repository): ?ObjectEntity + { + // If the repository has one or less components return. + if ($repository->getValue('components')->count() <= 1) { + return null; + } + + // Loop through the components and remove the component we created. + foreach ($repository->getValue('components') as $component) { + $componentSourceId = $component->getSynchronizations()->first()->getSourceId(); + + // If the component source id is the same as the repository url remove the component. + if ($componentSourceId === $repository->getValue('url')) { + $this->entityManager->remove($component); + $this->entityManager->flush(); + } } - } - return $repository; + return $repository; -}//end cleanupRepository() + }//end cleanupRepository() /** * This function enriches the repository with a organization. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. - * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. + * @param Source $source The github api source. * * @throws GuzzleException */ -public function enrichWithOrganization(ObjectEntity $repository, array $repositoryArray, Source $source): void -{ - $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); + public function enrichWithOrganization(ObjectEntity $repository, array $repositoryArray, Source $source): void + { + $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $repositoryArray['owner']['html_url']); + $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $repositoryArray['owner']['html_url']); - if ($organizationSync->getObject() === null) { - $organizationMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOrganisation.mapping.json', 'open-catalogi/open-catalogi-bundle'); + if ($organizationSync->getObject() === null) { + $organizationMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOrganisation.mapping.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSync->setMapping($organizationMapping); - $organizationSync = $this->syncService->synchronize($organizationSync, $repositoryArray['owner']); - $this->entityManager->persist($organizationSync); - } + $organizationSync->setMapping($organizationMapping); + $organizationSync = $this->syncService->synchronize($organizationSync, $repositoryArray['owner']); + $this->entityManager->persist($organizationSync); + } - $repository->hydrate(['organisation' => $organizationSync->getObject()]); - $this->entityManager->persist($repository); - $this->entityManager->flush(); + $repository->hydrate(['organisation' => $organizationSync->getObject()]); + $this->entityManager->persist($repository); + $this->entityManager->flush(); -}//end enrichWithOrganization() + }//end enrichWithOrganization() /** * This function enriches the repository with a component. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. - * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. + * @param Source $source The github api source. * * @throws GuzzleException */ -public function enrichWithComponent(ObjectEntity $repository, array $repositoryArray, Source $source): void -{ - $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); + public function enrichWithComponent(ObjectEntity $repository, array $repositoryArray, Source $source): void + { + $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); - $componentSync = $this->syncService->findSyncBySource($source, $componentSchema, $repositoryArray['html_url']); - $componentSync = $this->syncService->synchronize($componentSync, ['url' => $repository, 'name' => $repository->getValue('name')]); - $this->entityManager->persist($componentSync); - $this->entityManager->flush(); + $componentSync = $this->syncService->findSyncBySource($source, $componentSchema, $repositoryArray['html_url']); + $componentSync = $this->syncService->synchronize($componentSync, ['url' => $repository, 'name' => $repository->getValue('name')]); + $this->entityManager->persist($componentSync); + $this->entityManager->flush(); -}//end enrichWithComponent() + }//end enrichWithComponent() /** * This function enriches the repository with a organization and/or component. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. * + * @return ObjectEntity The repository object * @throws GuzzleException * - * @return ObjectEntity The repository object */ -public function enrichRepository(ObjectEntity $repository, array $repositoryArray, Source $source): ObjectEntity -{ - // If there is no organization create one. - if ($repository->getValue('organisation') === false) { - $this->enrichWithOrganization($repository, $repositoryArray, $source); - } + public function enrichRepository(ObjectEntity $repository, array $repositoryArray, Source $source): ObjectEntity + { + // If there is no organization create one. + if ($repository->getValue('organisation') === false) { + $this->enrichWithOrganization($repository, $repositoryArray, $source); + } - // If there is no component create one. - if ($repository->getValue('components')->count() === 0) { - $this->enrichWithComponent($repository, $repositoryArray, $source); - } + // If there is no component create one. + if ($repository->getValue('components')->count() === 0) { + $this->enrichWithComponent($repository, $repositoryArray, $source); + } - // @TODO: enrich the null values with what we have. - return $repository; + // @TODO: enrich the null values with what we have. + return $repository; -}//end enrichRepository() + }//end enrichRepository() /** * This function enriches the repository with a organization and/or component. * * @param ObjectEntity $organization The organization object. - * @param array $opencatalogi opencatalogi file array from the github usercontent/github api call. - * @param Source $source The github api source. + * @param array $opencatalogi opencatalogi file array from the github usercontent/github api call. + * @param Source $source The github api source. * + * @return ObjectEntity The repository object * @throws Exception * - * @return ObjectEntity The repository object */ -public function getConnectedComponents(ObjectEntity $organization, array $opencatalogi, Source $source): ObjectEntity -{ - $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); - $organizationMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOrganisation.mapping.json', 'open-catalogi/open-catalogi-bundle'); - - if (key_exists('softwareOwned', $opencatalogi) === true) { - $ownedComponents = []; - foreach ($opencatalogi['softwareOwned'] as $repositoryUrl) { - $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $repositoryUrl); - - // Get the object of the sync if there is one. - if ($repositorySync->getObject() !== null) { - $repository = $repositorySync->getObject(); - } + public function getConnectedComponents(ObjectEntity $organization, array $opencatalogi, Source $source): ObjectEntity + { + $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); + $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); + $organizationMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOrganisation.mapping.json', 'open-catalogi/open-catalogi-bundle'); - // Get the github repository from the given url if the object is null. - if ($repositorySync->getObject() === null) { - $repository = $this->getGithubRepository($repositoryUrl); + if (key_exists('softwareOwned', $opencatalogi) === true) { + $ownedComponents = []; + foreach ($opencatalogi['softwareOwned'] as $repositoryUrl) { + $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $repositoryUrl); + + // Get the object of the sync if there is one. + if ($repositorySync->getObject() !== null) { + $repository = $repositorySync->getObject(); + } + + // Get the github repository from the given url if the object is null. + if ($repositorySync->getObject() === null) { + $repository = $this->getGithubRepository($repositoryUrl); + } + + // Set the components of the repository to the array. + foreach ($repository->getValue('components') as $component) { + $ownedComponents[] = $component; + } } - // Set the components of the repository to the array. - foreach ($repository->getValue('components') as $component) { - $ownedComponents[] = $component; - } - } + $organization->hydrate(['owns' => $ownedComponents]); + $this->entityManager->persist($organization); + $this->entityManager->flush(); + }//end if - $organization->hydrate(['owns' => $ownedComponents]); - $this->entityManager->persist($organization); - $this->entityManager->flush(); - }//end if + if (key_exists('softwareSupported', $opencatalogi) === true) { + $supportedComponents = []; + foreach ($opencatalogi['softwareSupported'] as $supports) { + if (key_exists('software', $supports) === false) { + continue; + } + + $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $supports['software']); + + // Get the object of the sync if there is one. + if ($repositorySync->getObject() !== null) { + $repository = $repositorySync->getObject(); + } + + // Get the github repository from the given url if the object is null. + if ($repositorySync->getObject() === null) { + $repository = $this->getGithubRepository($supports['software']); + } + + // Set the components of the repository + foreach ($repository->getValue('components') as $component) { + $supportedComponents[] = $component; + } + }//end foreach + + $organization->hydrate(['supports' => $supportedComponents]); + $this->entityManager->persist($organization); + $this->entityManager->flush(); + }//end if - if (key_exists('softwareSupported', $opencatalogi) === true) { - $supportedComponents = []; - foreach ($opencatalogi['softwareSupported'] as $supports) { - if (key_exists('software', $supports) === false) { - continue; + if (key_exists('softwareUsed', $opencatalogi) === true) { + $usedComponents = []; + foreach ($opencatalogi['softwareUsed'] as $repositoryUrl) { + $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $repositoryUrl); + + // Get the object of the sync if there is one. + if ($repositorySync->getObject() !== null) { + $repository = $repositorySync->getObject(); + } + + // Get the github repository from the given url if the object is null. + if ($repositorySync->getObject() === null) { + $repository = $this->getGithubRepository($repositoryUrl); + } + + // Set the components of the repository + foreach ($repository->getValue('components') as $component) { + $usedComponents[] = $component; + } } - $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $supports['software']); - - // Get the object of the sync if there is one. - if ($repositorySync->getObject() !== null) { - $repository = $repositorySync->getObject(); - } + $organization->hydrate(['uses' => $usedComponents]); + $this->entityManager->persist($organization); + $this->entityManager->flush(); + }//end if - // Get the github repository from the given url if the object is null. - if ($repositorySync->getObject() === null) { - $repository = $this->getGithubRepository($supports['software']); + if (key_exists('members', $opencatalogi) === true) { + $members = []; + foreach ($opencatalogi['members'] as $organizationUrl) { + $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $organizationUrl); + + if ($organizationSync->getObject() === null) { + // Do we want to get the organization from the repository + // $organizationName = \Safe\parse_url($organizationUrl)['path']; + // $organizationSync = $this->syncService->synchronize($organizationSync, ['github' => $organizationUrl, 'name' => $organizationName]); + // + // $members[] = $organizationSync->getObject(); + } + + if ($organizationSync->getObject() !== null) { + $members[] = $organizationSync->getObject(); + } } - // Set the components of the repository - foreach ($repository->getValue('components') as $component) { - $supportedComponents[] = $component; - } - }//end foreach + $organization->hydrate(['members' => $members]); + $this->entityManager->persist($organization); + $this->entityManager->flush(); + }//end if - $organization->hydrate(['supports' => $supportedComponents]); - $this->entityManager->persist($organization); $this->entityManager->flush(); - }//end if - if (key_exists('softwareUsed', $opencatalogi) === true) { - $usedComponents = []; - foreach ($opencatalogi['softwareUsed'] as $repositoryUrl) { - $repositorySync = $this->syncService->findSyncBySource($source, $repositorySchema, $repositoryUrl); + return $organization; - // Get the object of the sync if there is one. - if ($repositorySync->getObject() !== null) { - $repository = $repositorySync->getObject(); - } + }//end getConnectedComponents() - // Get the github repository from the given url if the object is null. - if ($repositorySync->getObject() === null) { - $repository = $this->getGithubRepository($repositoryUrl); - } - // Set the components of the repository - foreach ($repository->getValue('components') as $component) { - $usedComponents[] = $component; - } + /** + * This function loops through the array with publiccode/opencatalogi files. + * + * @param array $opencatalogiArray The opencatalogi array from the github api. + * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. + * + * @return ObjectEntity|null + * @throws Exception + * + */ + public function handleOpencatalogiFile(array $opencatalogiArray, Source $source, ObjectEntity $repository): ?ObjectEntity + { + $opencatalogiMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOpenCatalogiYamlToOrg.mapping.json', 'open-catalogi/open-catalogi-bundle'); + $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); + if ($opencatalogiMapping instanceof Mapping === false + || $organizationSchema instanceof Entity === false + ) { + return null; } - $organization->hydrate(['uses' => $usedComponents]); - $this->entityManager->persist($organization); - $this->entityManager->flush(); - }//end if - - if (key_exists('members', $opencatalogi) === true) { - $members = []; - foreach ($opencatalogi['members'] as $organizationUrl) { - $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $organizationUrl); - - if ($organizationSync->getObject() === null) { - // Do we want to get the organization from the repository - // $organizationName = \Safe\parse_url($organizationUrl)['path']; - // $organizationSync = $this->syncService->synchronize($organizationSync, ['github' => $organizationUrl, 'name' => $organizationName]); - // - // $members[] = $organizationSync->getObject(); - } + // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent. + $publiccodeUrlQuery = \Safe\parse_url($opencatalogiArray['url'])['query']; + // Remove the ref= part of the query. + $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; + // Create the publiccode/opencatalogi url + $opencatalogiUrl = "https://raw.githubusercontent.com/{$opencatalogiArray['repository']['full_name']}/{$urlReference}/{$opencatalogiArray['path']}"; - if ($organizationSync->getObject() !== null) { - $members[] = $organizationSync->getObject(); - } + // Get the file from the usercontent or github api source. + $opencatalogi = $this->getFileFromRawUserContent($opencatalogiUrl, $opencatalogiArray['git_url']); + + // Check if the publiccodeYmlVersion is set otherwise this is not a valid file. + if (key_exists('publiccodeYmlVersion', $opencatalogi) === false) { + return null; } - $organization->hydrate(['members' => $members]); - $this->entityManager->persist($organization); - $this->entityManager->flush(); - }//end if + $opencatalogi['github'] = $opencatalogiArray['repository']['owner']['html_url']; - $this->entityManager->flush(); + // Find the sync with the source and opencatalogi url. + $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $opencatalogiArray['repository']['owner']['html_url']); - return $organization; + // Check the sha of the sync with the sha in the array. + if ($this->syncService->doesShaMatch($organizationSync, $opencatalogiArray['sha']) === true) { + $repository->setValue('organisation', $organizationSync->getObject()); -}//end getConnectedComponents() + $this->entityManager->persist($repository); + $this->entityManager->flush(); + return $repository; + } - /** - * This function loops through the array with publiccode/opencatalogi files. - * - * @param array $opencatalogiArray The opencatalogi array from the github api. - * @param Source $source The github api source. - * @param ObjectEntity $repository The repository object. - * - * @throws Exception - * - * @return ObjectEntity|null - */ -public function handleOpencatalogiFile(array $opencatalogiArray, Source $source, ObjectEntity $repository): ?ObjectEntity -{ - $opencatalogiMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOpenCatalogiYamlToOrg.mapping.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); - if ($opencatalogiMapping instanceof Mapping === false - || $organizationSchema instanceof Entity === false - ) { - return null; - } - - // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent. - $publiccodeUrlQuery = \Safe\parse_url($opencatalogiArray['url'])['query']; - // Remove the ref= part of the query. - $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; - // Create the publiccode/opencatalogi url - $opencatalogiUrl = "https://raw.githubusercontent.com/{$opencatalogiArray['repository']['full_name']}/{$urlReference}/{$opencatalogiArray['path']}"; - - // Get the file from the usercontent or github api source. - $opencatalogi = $this->getFileFromRawUserContent($opencatalogiUrl, $opencatalogiArray['git_url']); - - // Check if the publiccodeYmlVersion is set otherwise this is not a valid file. - if (key_exists('publiccodeYmlVersion', $opencatalogi) === false) { - return null; - } - - $opencatalogi['github'] = $opencatalogiArray['repository']['owner']['html_url']; - - // Find the sync with the source and opencatalogi url. - $organizationSync = $this->syncService->findSyncBySource($source, $organizationSchema, $opencatalogiArray['repository']['owner']['html_url']); - - // Check the sha of the sync with the sha in the array. - if ($this->syncService->doesShaMatch($organizationSync, $opencatalogiArray['sha']) === true) { - $repository->setValue('organisation', $organizationSync->getObject()); + $organizationSync->setMapping($opencatalogiMapping); - $this->entityManager->persist($repository); + // Synchronize the organization with the opencatalogi file. + $organizationSync = $this->syncService->synchronize($organizationSync, $opencatalogi, true); + $this->entityManager->persist($organizationSync); $this->entityManager->flush(); - return $repository; - } - - $organizationSync->setMapping($opencatalogiMapping); + // Get the softwareSupported/softwareOwned/softwareUsed repositories. + $organization = $this->getConnectedComponents($organizationSync->getObject(), $opencatalogi, $source, $opencatalogiArray); - // Synchronize the organization with the opencatalogi file. - $organizationSync = $this->syncService->synchronize($organizationSync, $opencatalogi, true); - $this->entityManager->persist($organizationSync); - $this->entityManager->flush(); + // Set the organization to the repository. + $repository->hydrate(['organisation' => $organization]); - // Get the softwareSupported/softwareOwned/softwareUsed repositories. - $organization = $this->getConnectedComponents($organizationSync->getObject(), $opencatalogi, $source, $opencatalogiArray); - - // Set the organization to the repository. - $repository->hydrate(['organisation' => $organization]); - - $this->entityManager->persist($repository); - $this->entityManager->flush(); + $this->entityManager->persist($repository); + $this->entityManager->flush(); - return $repository; + return $repository; -}//end handleOpencatalogiFile() + }//end handleOpencatalogiFile() /** * This function loops through the array with publiccode/opencatalogi files. * - * @param array $publiccodeArray The publiccode array from the github api. - * @param Source $source The github api source. - * @param ObjectEntity $repository The repository object. + * @param array $publiccodeArray The publiccode array from the github api. + * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. * * @return ObjectEntity|null */ -public function handlePubliccodeFile(array $publiccodeArray, Source $source, ObjectEntity $repository): ?ObjectEntity -{ - $publiccodeMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubPubliccodeComponent.mapping.json', 'open-catalogi/open-catalogi-bundle'); - $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); - if ($publiccodeMapping instanceof Mapping === false - || $componentSchema instanceof Entity === false - ) { - return null; - } + public function handlePubliccodeFile(array $publiccodeArray, Source $source, ObjectEntity $repository): ?ObjectEntity + { + $publiccodeMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubPubliccodeComponent.mapping.json', 'open-catalogi/open-catalogi-bundle'); + $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); + if ($publiccodeMapping instanceof Mapping === false + || $componentSchema instanceof Entity === false + ) { + return null; + } - // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent. - $publiccodeUrlQuery = \Safe\parse_url($publiccodeArray['url'])['query']; - // Remove the ref= part of the query. - $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; - // Create the publiccode/opencatalogi url - $publiccodeUrl = "https://raw.githubusercontent.com/{$publiccodeArray['repository']['full_name']}/{$urlReference}/{$publiccodeArray['path']}"; + // Get the ref query from the url. This way we can get the publiccode file with the raw.gitgubusercontent. + $publiccodeUrlQuery = \Safe\parse_url($publiccodeArray['url'])['query']; + // Remove the ref= part of the query. + $urlReference = explode('ref=', $publiccodeUrlQuery)[1]; + // Create the publiccode/opencatalogi url + $publiccodeUrl = "https://raw.githubusercontent.com/{$publiccodeArray['repository']['full_name']}/{$urlReference}/{$publiccodeArray['path']}"; - $this->pluginLogger->info('Map the publiccode file with url: '.$publiccodeUrl); + $this->pluginLogger->info('Map the publiccode file with url: ' . $publiccodeUrl); - // Get the file from the usercontent or github api source - $publiccode = $this->getFileFromRawUserContent($publiccodeUrl, $publiccodeArray['git_url']); + // Get the file from the usercontent or github api source + $publiccode = $this->getFileFromRawUserContent($publiccodeUrl, $publiccodeArray['git_url']); - // Check if the publiccodeYmlVersion is set otherwise this is not a valid file. - if (key_exists('publiccodeYmlVersion', $publiccode) === false) { - return null; - } + // Check if the publiccodeYmlVersion is set otherwise this is not a valid file. + if (key_exists('publiccodeYmlVersion', $publiccode) === false) { + return null; + } - // Get the forked_from from the repository. - $forkedFrom = $repository->getValue('forked_from'); - // Set the isBasedOn. - if ($forkedFrom !== null && isset($publiccode['isBasedOn']) === false) { - $publiccode['isBasedOn'] = $forkedFrom; - } + // Get the forked_from from the repository. + $forkedFrom = $repository->getValue('forked_from'); + // Set the isBasedOn. + if ($forkedFrom !== null && isset($publiccode['isBasedOn']) === false) { + $publiccode['isBasedOn'] = $forkedFrom; + } - // Set developmentStatus obsolete when repository is archived. - if ($repository->getValue('archived') === true) { - $publiccode['developmentStatus'] = 'obsolete'; - } + // Set developmentStatus obsolete when repository is archived. + if ($repository->getValue('archived') === true) { + $publiccode['developmentStatus'] = 'obsolete'; + } - // @TODO: Check the sha of the sync with the sha in the array - // Map the publiccode file. - $componentArray = $this->mappingService->mapping($publiccodeMapping, $publiccode); + // @TODO: Check the sha of the sync with the sha in the array + // Map the publiccode file. + $componentArray = $this->mappingService->mapping($publiccodeMapping, $publiccode); - // Set the publiccode url as _sourceId. - $componentArray['_sourceId'] = $publiccodeUrl; + // Set the publiccode url as _sourceId. + $componentArray['_sourceId'] = $publiccodeUrl; - // Find the sync with the source and publiccode url. - $component = $this->hydrationService->searchAndReplaceSynchronizations($componentArray, $source, $componentSchema, true, true); + // Find the sync with the source and publiccode url. + $component = $this->hydrationService->searchAndReplaceSynchronizations($componentArray, $source, $componentSchema, true, true); - $component->hydrate(['url' => $repository]); - $this->entityManager->persist($component); - $this->entityManager->flush(); + $component->hydrate(['url' => $repository]); + $this->entityManager->persist($component); + $this->entityManager->flush(); - return $repository; + return $repository; -}//end handlePubliccodeFile() + }//end handlePubliccodeFile() /** * This function loops through the array with publiccode/opencatalogi files. * - * @param array $dataArray An array with publiccode/opencatalogi files. - * @param Source $source The github api source. + * @param array $dataArray An array with publiccode/opencatalogi files. + * @param Source $source The github api source. * @param ObjectEntity $repository The repository object. * + * @return ObjectEntity|null * @throws Exception * - * @return ObjectEntity|null */ -public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $repository): ?ObjectEntity -{ - $opencatalogiNames = [ - 'opencatalogi.yaml', - 'opencatalogi.yml', - ]; - - $publiccodeNames = [ - 'publiccode.yaml', - 'publiccode.yml', - ]; - - // Loop through the array of publiccode/opencatalogi files. - $opencatalogiUrls = []; - $publiccodeUrls = []; - foreach ($dataArray as $item) { - // Check if the item name is the same as the openCatalogiNames array. - // If so go the the function for the opencatalogi file. - if (in_array($item['name'], $opencatalogiNames) === true) { - $this->pluginLogger->info('The item is a opencatalogi file.'); - $repository = $this->handleOpencatalogiFile($item, $source, $repository); - } + public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $repository): ?ObjectEntity + { + $opencatalogiNames = [ + 'opencatalogi.yaml', + 'opencatalogi.yml', + ]; + + $publiccodeNames = [ + 'publiccode.yaml', + 'publiccode.yml', + ]; + + // Loop through the array of publiccode/opencatalogi files. + $opencatalogiUrls = []; + $publiccodeUrls = []; + foreach ($dataArray as $item) { + // Check if the item name is the same as the openCatalogiNames array. + // If so go the the function for the opencatalogi file. + if (in_array($item['name'], $opencatalogiNames) === true) { + $this->pluginLogger->info('The item is a opencatalogi file.'); + $repository = $this->handleOpencatalogiFile($item, $source, $repository); + } - // Check if the item name is the same as the publiccodeNames array. - // If so go the the function for the publiccode file. - if (in_array($item['name'], $publiccodeNames) === true) { - $this->pluginLogger->info('The item is a publiccode file.'); - $repository = $this->handlePubliccodeFile($item, $source, $repository); + // Check if the item name is the same as the publiccodeNames array. + // If so go the the function for the publiccode file. + if (in_array($item['name'], $publiccodeNames) === true) { + $this->pluginLogger->info('The item is a publiccode file.'); + $repository = $this->handlePubliccodeFile($item, $source, $repository); + } } - } - return $repository; + return $repository; -}//end importRepoFiles() + }//end importRepoFiles() /** @@ -643,257 +641,257 @@ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $ * * @return array|null */ -public function getFileFromRawGithubApi(string $gitUrl): ?array -{ - $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle'); - if ($source === null) { - return $this->data; - } + public function getFileFromRawGithubApi(string $gitUrl): ?array + { + $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle'); + if ($source === null) { + return $this->data; + } - // Get the path from the git url to make the call. - $endpoint = \Safe\parse_url($gitUrl)['path']; + // Get the path from the git url to make the call. + $endpoint = \Safe\parse_url($gitUrl)['path']; - try { - $response = $this->callService->call($source, $endpoint); - } catch (Exception $e) { - $this->pluginLogger->error('Error found trying to fetch '.$gitUrl.' '.$e->getMessage()); - } + try { + $response = $this->callService->call($source, $endpoint); + } catch (Exception $e) { + $this->pluginLogger->error('Error found trying to fetch ' . $gitUrl . ' ' . $e->getMessage()); + } - if (isset($response) === false) { - return null; - } + if (isset($response) === false) { + return null; + } - // Decode the response from the call. - $response = $this->callService->decodeResponse($source, $response, 'application/json'); + // Decode the response from the call. + $response = $this->callService->decodeResponse($source, $response, 'application/json'); - // Check if there is a key content. This is the base64 of the file. - if (key_exists('content', $response) === false) { - return null; - } + // Check if there is a key content. This is the base64 of the file. + if (key_exists('content', $response) === false) { + return null; + } - // Decode the base64 string. - $content = \Safe\base64_decode($response['content']); + // Decode the base64 string. + $content = \Safe\base64_decode($response['content']); - $yamlEncoder = new YamlEncoder(); + $yamlEncoder = new YamlEncoder(); - // Decode the string. - return $yamlEncoder->decode($content, 'yaml'); + // Decode the string. + return $yamlEncoder->decode($content, 'yaml'); -}//end getFileFromRawGithubApi() + }//end getFileFromRawGithubApi() /** * This function gets the publiccode/opencatalogi file from the github user content. * * @param string $repositoryUrl The url of the repository - * @param string $gitUrl The git url of the repository + * @param string $gitUrl The git url of the repository * + * @return array|null * @throws GuzzleException * - * @return array|null */ -public function getFileFromRawUserContent(string $repositoryUrl, string $gitUrl): ?array -{ - $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubusercontent.source.json', 'open-catalogi/open-catalogi-bundle'); - if ($source === null) { - return $this->data; - } + public function getFileFromRawUserContent(string $repositoryUrl, string $gitUrl): ?array + { + $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubusercontent.source.json', 'open-catalogi/open-catalogi-bundle'); + if ($source === null) { + return $this->data; + } - // Get the path from the url to make the call. - $endpoint = \Safe\parse_url($repositoryUrl)['path']; - try { - $response = $this->callService->call($source, $endpoint); - } catch (Exception $e) { - $this->pluginLogger->error('Error found trying to fetch '.$repositoryUrl.' '.$e->getMessage()); - } + // Get the path from the url to make the call. + $endpoint = \Safe\parse_url($repositoryUrl)['path']; + try { + $response = $this->callService->call($source, $endpoint); + } catch (Exception $e) { + $this->pluginLogger->error('Error found trying to fetch ' . $repositoryUrl . ' ' . $e->getMessage()); + } - if (isset($response) === false) { - // Call the github api for the publiccode/opencatalogi files. - return $this->getFileFromRawGithubApi($gitUrl); - } + if (isset($response) === false) { + // Call the github api for the publiccode/opencatalogi files. + return $this->getFileFromRawGithubApi($gitUrl); + } - return $this->callService->decodeResponse($source, $response, 'text/yaml'); + return $this->callService->decodeResponse($source, $response, 'text/yaml'); -}//end getFileFromRawUserContent() + }//end getFileFromRawUserContent() /** * Get a repository from github with the given repository url * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ -public function getRepository(string $repositoryUrl, Source $source): ?array -{ - $this->pluginLogger->debug('Getting repository with url'.$repositoryUrl.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + public function getRepository(string $repositoryUrl, Source $source): ?array + { + $this->pluginLogger->debug('Getting repository with url' . $repositoryUrl . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - $path = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); + $path = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); - // Get the repository from github with the path as endpoint. - try { - $response = $this->callService->call($source, '/repos/'.$path); - } catch (ClientException $exception) { - $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); - } + // Get the repository from github with the path as endpoint. + try { + $response = $this->callService->call($source, '/repos/' . $path); + } catch (ClientException $exception) { + $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + } - // Check if we have a response if not then return null. - if (isset($response) === false) { - return null; - } + // Check if we have a response if not then return null. + if (isset($response) === false) { + return null; + } - // Decode the response with the source. - $repository = $this->callService->decodeResponse($source, $response, 'application/json'); + // Decode the response with the source. + $repository = $this->callService->decodeResponse($source, $response, 'application/json'); - // If we cannot decode the response then return null. - if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with url: '.$repositoryUrl.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + // If we cannot decode the response then return null. + if ($repository === null) { + $this->pluginLogger->error('Could not find a repository with url: ' . $repositoryUrl . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - return null; - }//end if + return null; + }//end if - return $repository; + return $repository; -}//end getRepository() + }//end getRepository() /** * Get the publiccode/opencatalogi files of the given repository * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The publiccode/opencatalogi files as array. */ -public function getFilesFromRepo(string $repositoryUrl, Source $source): ?array -{ - $path = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); + public function getFilesFromRepo(string $repositoryUrl, Source $source): ?array + { + $path = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); - // Call the search/code endpoint for publiccode files in this repository. - $queryConfig['query'] = ['q' => "filename:publiccode filename:opencatalogi extension:yaml extension:yml repo:{$path}"]; + // Call the search/code endpoint for publiccode files in this repository. + $queryConfig['query'] = ['q' => "filename:publiccode filename:opencatalogi extension:yaml extension:yml repo:{$path}"]; - // Find the publiccode.yaml file(s). - try { - $response = $this->callService->call($source, '/search/code', 'GET', $queryConfig); - } catch (Exception $exception) { - $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); - } + // Find the publiccode.yaml file(s). + try { + $response = $this->callService->call($source, '/search/code', 'GET', $queryConfig); + } catch (Exception $exception) { + $this->pluginLogger->error('Error found trying to fetch ' . $source->getLocation() . '/search/code' . ' ' . $exception->getMessage()); + } - if (isset($response) === false) { - return null; - } + if (isset($response) === false) { + return null; + } - $dataArray = $this->callService->decodeResponse($source, $response); + $dataArray = $this->callService->decodeResponse($source, $response); - $this->pluginLogger->debug('Found '.$dataArray['total_count'].' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Found ' . $dataArray['total_count'] . ' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - return $dataArray['items']; + return $dataArray['items']; -}//end getFilesFromRepo() + }//end getFilesFromRepo() /** * Get the publiccode/opencatalogi files of the given repository * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The publiccode/opencatalogi files as array. */ -public function getGithubFiles(): ?array -{ - $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle'); + public function getGithubFiles(): ?array + { + $source = $this->resourceService->getSource('https://opencatalogi.nl/source/oc.GitHubAPI.source.json', 'open-catalogi/open-catalogi-bundle'); - // Call the search/code endpoint for publiccode files in this repository. - $queryConfig['query'] = ['q' => "filename:publiccode filename:opencatalogi extension:yaml extension:yml"]; + // Call the search/code endpoint for publiccode files in this repository. + $queryConfig['query'] = ['q' => "filename:publiccode filename:opencatalogi extension:yaml extension:yml"]; - // Find the publiccode.yaml file(s). - try { - $response = $this->callService->getAllResults($source, '/search/code', $queryConfig); - } catch (Exception $exception) { - $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); - } + // Find the publiccode.yaml file(s). + try { + $response = $this->callService->getAllResults($source, '/search/code', $queryConfig); + } catch (Exception $exception) { + $this->pluginLogger->error('Error found trying to fetch ' . $source->getLocation() . '/search/code' . ' ' . $exception->getMessage()); + } - if (isset($response) === false) { - return null; - } + if (isset($response) === false) { + return null; + } - $this->pluginLogger->debug('Found '.count($response).' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Found ' . count($response) . ' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - return $response; + return $response; -}//end getGithubFiles() + }//end getGithubFiles() /** * Get a repository through the repositories of the given source * - * @param string $name The name of the repository. + * @param string $name The name of the repository. * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ -public function getOrganisation(string $name, Source $source): ?array -{ - $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + public function getOrganisation(string $name, Source $source): ?array + { + $this->pluginLogger->debug('Getting repository ' . $name . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - try { - $response = $this->callService->call($source, '/repos/'.$name); - } catch (ClientException $exception) { - $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); - } + try { + $response = $this->callService->call($source, '/repos/' . $name); + } catch (ClientException $exception) { + $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + } - if (isset($response) === false) { - return null; - } + if (isset($response) === false) { + return null; + } - $repository = \Safe\json_decode($response->getBody()->getContents(), true); + $repository = \Safe\json_decode($response->getBody()->getContents(), true); - if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + if ($repository === null) { + $this->pluginLogger->error('Could not find a repository with name: ' . $name . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - return null; - }//end if + return null; + }//end if - return $repository; + return $repository; -}//end getOrganisation() + }//end getOrganisation() /** * Get a repository through the repositories of the given source * - * @param string $name The name of the repository. + * @param string $name The name of the repository. * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ -public function getOrganisationRepos(string $name, Source $source): ?array -{ - $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + public function getOrganisationRepos(string $name, Source $source): ?array + { + $this->pluginLogger->debug('Getting repository ' . $name . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - try { - $response = $this->callService->call($source, '/repos/'.$name); - } catch (ClientException $exception) { - $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); - } + try { + $response = $this->callService->call($source, '/repos/' . $name); + } catch (ClientException $exception) { + $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); + } - if (isset($response) === false) { - return null; - } + if (isset($response) === false) { + return null; + } - $repository = \Safe\json_decode($response->getBody()->getContents(), true); + $repository = \Safe\json_decode($response->getBody()->getContents(), true); - if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + if ($repository === null) { + $this->pluginLogger->error('Could not find a repository with name: ' . $name . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); - return null; - }//end if + return null; + }//end if - return $repository; + return $repository; -}//end getOrganisationRepos() + }//end getOrganisationRepos() }//end class From dde32c29338359d4eed0de0eb2ec497284571787 Mon Sep 17 00:00:00 2001 From: GitHub Actions <> Date: Tue, 14 Nov 2023 10:14:59 +0000 Subject: [PATCH 2/2] Update src from PHP Codesniffer --- src/Service/GithubApiService.php | 154 +++++++++++++++---------------- 1 file changed, 74 insertions(+), 80 deletions(-) diff --git a/src/Service/GithubApiService.php b/src/Service/GithubApiService.php index b95d57f4..bd9b0457 100644 --- a/src/Service/GithubApiService.php +++ b/src/Service/GithubApiService.php @@ -81,40 +81,39 @@ class GithubApiService /** - * @param EntityManagerInterface $entityManager The Entity Manager Interface - * @param CallService $callService The Call Service - * @param SynchronizationService $syncService The Synchronisation Service - * @param CacheService $cacheService The Cache Service - * @param MappingService $mappingService The Mapping Service - * @param RatingService $ratingService The Rating Service. - * @param LoggerInterface $pluginLogger The plugin version of the logger interface - * @param GatewayResourceService $resourceService The Gateway Resource Service. - * @param HydrationService $hydrationService The Hydration Service. + * @param EntityManagerInterface $entityManager The Entity Manager Interface + * @param CallService $callService The Call Service + * @param SynchronizationService $syncService The Synchronisation Service + * @param CacheService $cacheService The Cache Service + * @param MappingService $mappingService The Mapping Service + * @param RatingService $ratingService The Rating Service. + * @param LoggerInterface $pluginLogger The plugin version of the logger interface + * @param GatewayResourceService $resourceService The Gateway Resource Service. + * @param HydrationService $hydrationService The Hydration Service. */ public function __construct( EntityManagerInterface $entityManager, - CallService $callService, + CallService $callService, SynchronizationService $syncService, - CacheService $cacheService, - MappingService $mappingService, - RatingService $ratingService, - LoggerInterface $pluginLogger, + CacheService $cacheService, + MappingService $mappingService, + RatingService $ratingService, + LoggerInterface $pluginLogger, GatewayResourceService $resourceService, - HydrationService $hydrationService - ) - { - $this->entityManager = $entityManager; - $this->callService = $callService; - $this->syncService = $syncService; - $this->cacheService = $cacheService; - $this->mappingService = $mappingService; - $this->ratingService = $ratingService; - $this->pluginLogger = $pluginLogger; - $this->resourceService = $resourceService; + HydrationService $hydrationService + ) { + $this->entityManager = $entityManager; + $this->callService = $callService; + $this->syncService = $syncService; + $this->cacheService = $cacheService; + $this->mappingService = $mappingService; + $this->ratingService = $ratingService; + $this->pluginLogger = $pluginLogger; + $this->resourceService = $resourceService; $this->hydrationService = $hydrationService; $this->configuration = []; - $this->data = []; + $this->data = []; }//end __construct() @@ -129,7 +128,7 @@ public function __construct( public function checkGithubAuth(Source $source): ?bool { if ($source->getApiKey() === null) { - $this->pluginLogger->error('No auth set for Source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->error('No auth set for Source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return false; }//end if @@ -142,15 +141,15 @@ public function checkGithubAuth(Source $source): ?bool /** * This function gets repository and enriches it. * - * @param string $repositoryUrl The url of the repository + * @param string $repositoryUrl The url of the repository * @param array|null $repositoryArray The repository array from the github api. * * @return ObjectEntity|null * @throws Exception */ - public function getGithubRepository(string $repositoryUrl, ?array $repositoryArray = null): ?ObjectEntity + public function getGithubRepository(string $repositoryUrl, ?array $repositoryArray=null): ?ObjectEntity { - $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); + $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); $repositoryMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubRepository.mapping.json', 'open-catalogi/open-catalogi-bundle'); if ($repositorySchema instanceof Entity === false || $repositoryMapping instanceof Mapping === false @@ -243,9 +242,9 @@ public function cleanupRepository(ObjectEntity $repository): ?ObjectEntity /** * This function enriches the repository with a organization. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. - * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. + * @param Source $source The github api source. * * @throws GuzzleException */ @@ -273,9 +272,9 @@ public function enrichWithOrganization(ObjectEntity $repository, array $reposito /** * This function enriches the repository with a component. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. - * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. + * @param Source $source The github api source. * * @throws GuzzleException */ @@ -294,12 +293,11 @@ public function enrichWithComponent(ObjectEntity $repository, array $repositoryA /** * This function enriches the repository with a organization and/or component. * - * @param ObjectEntity $repository The repository object. - * @param array $repositoryArray The repository array from the github api call. + * @param ObjectEntity $repository The repository object. + * @param array $repositoryArray The repository array from the github api call. * * @return ObjectEntity The repository object * @throws GuzzleException - * */ public function enrichRepository(ObjectEntity $repository, array $repositoryArray, Source $source): ObjectEntity { @@ -323,17 +321,16 @@ public function enrichRepository(ObjectEntity $repository, array $repositoryArra * This function enriches the repository with a organization and/or component. * * @param ObjectEntity $organization The organization object. - * @param array $opencatalogi opencatalogi file array from the github usercontent/github api call. - * @param Source $source The github api source. + * @param array $opencatalogi opencatalogi file array from the github usercontent/github api call. + * @param Source $source The github api source. * * @return ObjectEntity The repository object * @throws Exception - * */ public function getConnectedComponents(ObjectEntity $organization, array $opencatalogi, Source $source): ObjectEntity { - $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); + $repositorySchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.repository.schema.json', 'open-catalogi/open-catalogi-bundle'); + $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); $organizationMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOrganisation.mapping.json', 'open-catalogi/open-catalogi-bundle'); if (key_exists('softwareOwned', $opencatalogi) === true) { @@ -451,18 +448,17 @@ public function getConnectedComponents(ObjectEntity $organization, array $openca /** * This function loops through the array with publiccode/opencatalogi files. * - * @param array $opencatalogiArray The opencatalogi array from the github api. - * @param Source $source The github api source. - * @param ObjectEntity $repository The repository object. + * @param array $opencatalogiArray The opencatalogi array from the github api. + * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. * * @return ObjectEntity|null * @throws Exception - * */ public function handleOpencatalogiFile(array $opencatalogiArray, Source $source, ObjectEntity $repository): ?ObjectEntity { $opencatalogiMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubOpenCatalogiYamlToOrg.mapping.json', 'open-catalogi/open-catalogi-bundle'); - $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); + $organizationSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.organisation.schema.json', 'open-catalogi/open-catalogi-bundle'); if ($opencatalogiMapping instanceof Mapping === false || $organizationSchema instanceof Entity === false ) { @@ -523,16 +519,16 @@ public function handleOpencatalogiFile(array $opencatalogiArray, Source $source, /** * This function loops through the array with publiccode/opencatalogi files. * - * @param array $publiccodeArray The publiccode array from the github api. - * @param Source $source The github api source. - * @param ObjectEntity $repository The repository object. + * @param array $publiccodeArray The publiccode array from the github api. + * @param Source $source The github api source. + * @param ObjectEntity $repository The repository object. * * @return ObjectEntity|null */ public function handlePubliccodeFile(array $publiccodeArray, Source $source, ObjectEntity $repository): ?ObjectEntity { $publiccodeMapping = $this->resourceService->getMapping('https://api.github.com/oc.githubPubliccodeComponent.mapping.json', 'open-catalogi/open-catalogi-bundle'); - $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); + $componentSchema = $this->resourceService->getSchema('https://opencatalogi.nl/oc.component.schema.json', 'open-catalogi/open-catalogi-bundle'); if ($publiccodeMapping instanceof Mapping === false || $componentSchema instanceof Entity === false ) { @@ -546,7 +542,7 @@ public function handlePubliccodeFile(array $publiccodeArray, Source $source, Obj // Create the publiccode/opencatalogi url $publiccodeUrl = "https://raw.githubusercontent.com/{$publiccodeArray['repository']['full_name']}/{$urlReference}/{$publiccodeArray['path']}"; - $this->pluginLogger->info('Map the publiccode file with url: ' . $publiccodeUrl); + $this->pluginLogger->info('Map the publiccode file with url: '.$publiccodeUrl); // Get the file from the usercontent or github api source $publiccode = $this->getFileFromRawUserContent($publiccodeUrl, $publiccodeArray['git_url']); @@ -590,13 +586,12 @@ public function handlePubliccodeFile(array $publiccodeArray, Source $source, Obj /** * This function loops through the array with publiccode/opencatalogi files. * - * @param array $dataArray An array with publiccode/opencatalogi files. - * @param Source $source The github api source. + * @param array $dataArray An array with publiccode/opencatalogi files. + * @param Source $source The github api source. * @param ObjectEntity $repository The repository object. * * @return ObjectEntity|null * @throws Exception - * */ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $repository): ?ObjectEntity { @@ -612,7 +607,7 @@ public function importRepoFiles(array $dataArray, Source $source, ObjectEntity $ // Loop through the array of publiccode/opencatalogi files. $opencatalogiUrls = []; - $publiccodeUrls = []; + $publiccodeUrls = []; foreach ($dataArray as $item) { // Check if the item name is the same as the openCatalogiNames array. // If so go the the function for the opencatalogi file. @@ -654,7 +649,7 @@ public function getFileFromRawGithubApi(string $gitUrl): ?array try { $response = $this->callService->call($source, $endpoint); } catch (Exception $e) { - $this->pluginLogger->error('Error found trying to fetch ' . $gitUrl . ' ' . $e->getMessage()); + $this->pluginLogger->error('Error found trying to fetch '.$gitUrl.' '.$e->getMessage()); } if (isset($response) === false) { @@ -684,11 +679,10 @@ public function getFileFromRawGithubApi(string $gitUrl): ?array * This function gets the publiccode/opencatalogi file from the github user content. * * @param string $repositoryUrl The url of the repository - * @param string $gitUrl The git url of the repository + * @param string $gitUrl The git url of the repository * * @return array|null * @throws GuzzleException - * */ public function getFileFromRawUserContent(string $repositoryUrl, string $gitUrl): ?array { @@ -702,7 +696,7 @@ public function getFileFromRawUserContent(string $repositoryUrl, string $gitUrl) try { $response = $this->callService->call($source, $endpoint); } catch (Exception $e) { - $this->pluginLogger->error('Error found trying to fetch ' . $repositoryUrl . ' ' . $e->getMessage()); + $this->pluginLogger->error('Error found trying to fetch '.$repositoryUrl.' '.$e->getMessage()); } if (isset($response) === false) { @@ -719,19 +713,19 @@ public function getFileFromRawUserContent(string $repositoryUrl, string $gitUrl) * Get a repository from github with the given repository url * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ public function getRepository(string $repositoryUrl, Source $source): ?array { - $this->pluginLogger->debug('Getting repository with url' . $repositoryUrl . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Getting repository with url'.$repositoryUrl.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); $path = trim(\Safe\parse_url($repositoryUrl, PHP_URL_PATH), '/'); // Get the repository from github with the path as endpoint. try { - $response = $this->callService->call($source, '/repos/' . $path); + $response = $this->callService->call($source, '/repos/'.$path); } catch (ClientException $exception) { $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); } @@ -746,7 +740,7 @@ public function getRepository(string $repositoryUrl, Source $source): ?array // If we cannot decode the response then return null. if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with url: ' . $repositoryUrl . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->error('Could not find a repository with url: '.$repositoryUrl.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return null; }//end if @@ -760,7 +754,7 @@ public function getRepository(string $repositoryUrl, Source $source): ?array * Get the publiccode/opencatalogi files of the given repository * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The publiccode/opencatalogi files as array. */ @@ -775,7 +769,7 @@ public function getFilesFromRepo(string $repositoryUrl, Source $source): ?array try { $response = $this->callService->call($source, '/search/code', 'GET', $queryConfig); } catch (Exception $exception) { - $this->pluginLogger->error('Error found trying to fetch ' . $source->getLocation() . '/search/code' . ' ' . $exception->getMessage()); + $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); } if (isset($response) === false) { @@ -784,7 +778,7 @@ public function getFilesFromRepo(string $repositoryUrl, Source $source): ?array $dataArray = $this->callService->decodeResponse($source, $response); - $this->pluginLogger->debug('Found ' . $dataArray['total_count'] . ' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Found '.$dataArray['total_count'].' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return $dataArray['items']; @@ -795,7 +789,7 @@ public function getFilesFromRepo(string $repositoryUrl, Source $source): ?array * Get the publiccode/opencatalogi files of the given repository * * @param string $repositoryUrl The url of the repository. - * @param Source $source The source to sync from. + * @param Source $source The source to sync from. * * @return array|null The publiccode/opencatalogi files as array. */ @@ -810,14 +804,14 @@ public function getGithubFiles(): ?array try { $response = $this->callService->getAllResults($source, '/search/code', $queryConfig); } catch (Exception $exception) { - $this->pluginLogger->error('Error found trying to fetch ' . $source->getLocation() . '/search/code' . ' ' . $exception->getMessage()); + $this->pluginLogger->error('Error found trying to fetch '.$source->getLocation().'/search/code'.' '.$exception->getMessage()); } if (isset($response) === false) { return null; } - $this->pluginLogger->debug('Found ' . count($response) . ' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Found '.count($response).' publiccode/opencatalogi file(s).', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return $response; @@ -827,17 +821,17 @@ public function getGithubFiles(): ?array /** * Get a repository through the repositories of the given source * - * @param string $name The name of the repository. + * @param string $name The name of the repository. * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ public function getOrganisation(string $name, Source $source): ?array { - $this->pluginLogger->debug('Getting repository ' . $name . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); try { - $response = $this->callService->call($source, '/repos/' . $name); + $response = $this->callService->call($source, '/repos/'.$name); } catch (ClientException $exception) { $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); } @@ -849,7 +843,7 @@ public function getOrganisation(string $name, Source $source): ?array $repository = \Safe\json_decode($response->getBody()->getContents(), true); if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with name: ' . $name . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return null; }//end if @@ -862,17 +856,17 @@ public function getOrganisation(string $name, Source $source): ?array /** * Get a repository through the repositories of the given source * - * @param string $name The name of the repository. + * @param string $name The name of the repository. * @param Source $source The source to sync from. * * @return array|null The imported repository as array. */ public function getOrganisationRepos(string $name, Source $source): ?array { - $this->pluginLogger->debug('Getting repository ' . $name . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->debug('Getting repository '.$name.'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); try { - $response = $this->callService->call($source, '/repos/' . $name); + $response = $this->callService->call($source, '/repos/'.$name); } catch (ClientException $exception) { $this->pluginLogger->error($exception->getMessage(), ['plugin' => 'open-catalogi/open-catalogi-bundle']); } @@ -884,7 +878,7 @@ public function getOrganisationRepos(string $name, Source $source): ?array $repository = \Safe\json_decode($response->getBody()->getContents(), true); if ($repository === null) { - $this->pluginLogger->error('Could not find a repository with name: ' . $name . ' and with source: ' . $source->getName() . '.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); + $this->pluginLogger->error('Could not find a repository with name: '.$name.' and with source: '.$source->getName().'.', ['plugin' => 'open-catalogi/open-catalogi-bundle']); return null; }//end if