GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2e7cbb...9fc785 )
by Fedir
02:21
created

main.rateGhData   F

Complexity

Conditions 25

Size

Total Lines 87
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 51
CRAP Score 25

Importance

Changes 0
Metric Value
cc 25
eloc 52
nop 1
dl 0
loc 87
rs 0
c 0
b 0
f 0
ccs 51
cts 51
cp 1
crap 25

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like main.rateGhData often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
// Copyright 2018 Fedir RYKHTIK. All rights reserved.
2
// Use of this source code is governed by the GNU GPL 3.0
3
// license that can be found in the LICENSE file.
4
5
package main
6
7
import (
8
	"fmt"
9
	"sort"
10
)
11
12
func rateAndPrintGreetings(ghData []Repository) {
13 1
	greetings := rateGhData(ghData)
14 1
	fmt.Println(greetings)
15
}
16
17
func rateGhData(ghData []Repository) string {
18
19 1
	greetings := ""
20
21
	// Add points by repository total popularity (more popular is better)
22 1
	sort.Slice(ghData[:], func(i, j int) bool {
23 1
		return ghData[i].Watchers > ghData[j].Watchers
24
	})
25 1
	greetings += fmt.Sprintf("* The most popular project is `%s`\n", ghData[0].Name)
26 1
	for i := range ghData {
27 1
		ghData[i].PlacementPopularity = ghData[i].PlacementPopularity + i
28 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
29
	}
30
31 1
	greetings += fmt.Sprintf("* The newest project is `%s`\n", ghData[0].Name)
32 1
	for i := range ghData {
33 1
		ghData[i].PlacementAge = ghData[i].PlacementAge + i
34 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
35
	}
36
37
	// Add points by number of commits (more commits is better)
38 1
	sort.Slice(ghData[:], func(i, j int) bool {
39 1
		return ghData[i].TotalCommits > ghData[j].TotalCommits
40
	})
41 1
	greetings += fmt.Sprintf("* The project with more commits is `%s`\n", ghData[0].Name)
42 1
	for i := range ghData {
43 1
		ghData[i].PlacementTotalCommits = ghData[i].PlacementTotalCommits + i
44 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
45
	}
46
47
	// Add points by number of tags (more tags is better)
48 1
	sort.Slice(ghData[:], func(i, j int) bool {
49 1
		return ghData[i].TotalTags > ghData[j].TotalTags
50
	})
51 1
	greetings += fmt.Sprintf("* The project with more tags is `%s`\n", ghData[0].Name)
52 1
	for i := range ghData {
53 1
		ghData[i].PlacementTotalTags = ghData[i].PlacementTotalTags + i
54 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
55
	}
56
57
	// Add points by Top10 contributors followers
58 1
	sort.Slice(ghData[:], func(i, j int) bool {
59 1
		return ghData[i].Top10ContributorsFollowers > ghData[j].Top10ContributorsFollowers
60
	})
61 1
	greetings += fmt.Sprintf("* The project made by most notable top contributors is `%s`\n", ghData[0].Name)
62 1
	for i := range ghData {
63 1
		ghData[i].PlacementTop10ContributorsFollowers = ghData[i].PlacementTop10ContributorsFollowers + i
64 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
65
	}
66
67
	// Add points by Top10 contributors followers
68 1
	sort.Slice(ghData[:], func(i, j int) bool {
69 1
		return ghData[i].ClosedIssuesPercentage > ghData[j].ClosedIssuesPercentage
70
	})
71 1
	greetings += fmt.Sprintf("* The project with best errors resolving rate is `%s`\n", ghData[0].Name)
72 1
	for i := range ghData {
73 1
		ghData[i].PlacementClosedIssuesPercentage = ghData[i].PlacementClosedIssuesPercentage + i
74 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
75
	}
76
77
	// Add points by commits by day (more commits shows good healthy community)
78 1
	sort.Slice(ghData[:], func(i, j int) bool {
79 1
		return ghData[i].CommitsByDay > ghData[j].CommitsByDay
80
	})
81 1
	greetings += fmt.Sprintf("* The project with more commits by day is `%s`\n", ghData[0].Name)
82 1
	for i := range ghData {
83 1
		ghData[i].PlacementCommitsByDay = ghData[i].PlacementCommitsByDay + i
84 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
85
	}
86
87
	// Add points by active forkers (more active forkers shows good open source spirit of the community)
88 1
	sort.Slice(ghData[:], func(i, j int) bool {
89 1
		return ghData[i].ActiveForkersPercentage > ghData[j].ActiveForkersPercentage
90
	})
91 1
	greetings += fmt.Sprintf("* The project with the most active community is `%s`\n", ghData[0].Name)
92 1
	for i := range ghData {
93 1
		ghData[i].PlacementActiveForkersColumn = ghData[i].PlacementActiveForkersColumn + i
94 1
		ghData[i].PlacementOverall = ghData[i].PlacementOverall + i
95
	}
96
97
	// Assign places to projects by all metrics
98 1
	sort.Slice(ghData[:], func(i, j int) bool {
99 1
		return ghData[i].PlacementOverall < ghData[j].PlacementOverall
100
	})
101 1
	greetings += fmt.Sprintf("* The best project (taking in account placements in all competitions) is `%s`\n", ghData[0].Name)
102
103 1
	return greetings
104
}
105