Last active
January 19, 2021 09:57
-
-
Save leMaur/13d1355df3951fe53f092df9f9f930af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculates a score for the given | |
* Github's user based on public events. | |
* | |
* @param string $username The Github's username. | |
* @return int The calculated score. | |
*/ | |
function getScoreForGithubUser(string $username): int | |
{ | |
$url = "https://api.github.com/users/{$username}/events/public"; | |
try { | |
return collect(\Illuminate\Support\Facades\Http::get($url)->json()) | |
->reduce(function($carry, $event) { | |
$rules = [ | |
'PushEvent' => 10, | |
'PullRequestEvent' => 5, | |
'IssueCommentEvent' => 4, | |
]; | |
return $carry + data_get($rules, $event['type'], 1); | |
}, 0); | |
} catch(\Exception $e) { | |
return 0; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment