Skip to content

Instantly share code, notes, and snippets.

@leMaur
Last active January 19, 2021 09:57
Show Gist options
  • Save leMaur/13d1355df3951fe53f092df9f9f930af to your computer and use it in GitHub Desktop.
Save leMaur/13d1355df3951fe53f092df9f9f930af to your computer and use it in GitHub Desktop.
<?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