File tree 1 file changed +41
-0
lines changed
4. What's Your Github Score/imperative
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ function getGitHubScore (string $ username ):int
4
+ {
5
+ $ opts = [
6
+ 'http ' => [
7
+ 'method ' => 'GET ' ,
8
+ 'header ' => [
9
+ 'User-Agent: PHP '
10
+ ]
11
+ ]
12
+ ];
13
+
14
+ $ context = stream_context_create ($ opts );
15
+
16
+ $ url = "https://api.github.com/users/ " . $ username . "/events " ;
17
+
18
+ $ content = file_get_contents ($ url , false , $ context );
19
+
20
+ $ events = json_decode ($ content , true );
21
+
22
+ $ eventTypes = [];
23
+
24
+ foreach ($ events as $ event ) {
25
+ $ eventTypes [] = $ event ['type ' ];
26
+ }
27
+
28
+ $ score = 0 ;
29
+
30
+ foreach ($ eventTypes as $ eventType ) {
31
+ $ score = match ($ eventType ) {
32
+ 'PushEvent ' => $ score += 5 ,
33
+ 'CreateEvent ' => $ score += 4 ,
34
+ 'IssuesEvent ' => $ score += 3 ,
35
+ 'CommitCommentEvent ' => $ score += 2 ,
36
+ default => $ score += 1 ,
37
+ };
38
+ }
39
+
40
+ return $ score ;
41
+ }
You can’t perform that action at this time.
0 commit comments