/**
  * Get the edges of a contributor (i.e. all contributors of packages he worked on)
  *
  * @param string $contributor
  *
  * @return array
  */
 protected static function getRelatedContributors($contributor)
 {
     // Get all contributors he worked with on all projects
     $contributors = Contributor::getRelatedContributors($contributor);
     // In PHP5, array_column does NOT work on objects. In PHP7, it does.
     // I could have done some json_encode/json_decode to make it an array, but that just seems dirty.
     // So I'd usually do:
     //   $contributors = array_column($contributors, 'name');
     // ... PHP5 you just do an array_map
     $contributors = array_map(function ($contributor) {
         return ['name' => $contributor->name, 'package' => $contributor->package];
     }, $contributors);
     return $contributors;
 }
 /**
  * Execute the console command.
  *
  * @param Client $client
  *
  * @return mixed
  */
 public function handle(Client $client)
 {
     // Basic setup for offset-building
     $maxNumPackages = 5;
     $totalNumPackages = Package::count();
     $numResultSets = ceil($totalNumPackages / $maxNumPackages);
     // Paginate through results
     for ($numResultSet = 0; $numResultSet < $numResultSets; $numResultSet++) {
         // Get current result set
         $packages = Package::skip($numResultSet * $maxNumPackages)->take($maxNumPackages)->get();
         // Go through current result set
         foreach ($packages as $package) {
             $this->info("Fetching package information for {$package->name}...");
             // Get package info
             $packageInfo = $this->getPackageInfo($package->name, $client);
             // Validate
             if ($packageInfo === false) {
                 $this->warn('Package skipped.');
                 continue;
             }
             // Check if it is a GitHub repository
             if (!$this->isGitHubRepository($packageInfo->package->repository)) {
                 $this->warn("Package {$packageName} is NOT a GitHub repository and will be skipped!");
                 continue;
             }
             // Get GitHub package name
             $packageName = $this->getPackageNameFromUrl($packageInfo->package->repository);
             $this->info("Fetching contributors for {$packageName}...");
             // Get contributors on GitHub of this repository
             $contributors = $this->getContributors($packageName, $client);
             // Validate
             if ($contributors === false) {
                 $this->warn('Package skipped.');
                 continue;
             }
             // Go through contributors
             foreach ($contributors as $contributor) {
                 // Find or create contributor
                 $contributor = Contributor::firstOrCreate(['name' => $contributor]);
                 // Attach contributor to current package if it isn't yet
                 if (!$package->contributors->contains($contributor->contributor_id)) {
                     $package->contributors()->attach($contributor->contributor_id);
                 }
             }
             $this->info('OK');
         }
     }
 }