Conditions | 11 |
Total Lines | 105 |
Code Lines | 94 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 13.5412 |
Changes | 0 |
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:
If many parameters/temporary variables are present:
Complex classes like main.main 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. |
||
24 | func main() { |
||
25 | 1 | var ( |
|
26 | clearHTTPCache = flag.Bool("cc", false, "Clear HTTP cache") |
||
27 | clearHTTPCacheDryRun = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)") |
||
28 | debug = flag.Bool("d", false, "Debug mode") |
||
29 | resultFileSavePath = flag.String("f", "", "File path where result CSV file will be saved") |
||
30 | rateLimitCheck = flag.Bool("l", false, "Rate limit check") |
||
31 | repositoriesKeysManual = flag.String("r", "", "Repositories keys") |
||
32 | tmpFolder = flag.String("t", "test_data", "Clear HTTP cache (dry run)") |
||
33 | repositoriesKeys = []string{} |
||
34 | ) |
||
35 | 1 | flag.Parse() |
|
36 | 1 | if *clearHTTPCache || *clearHTTPCacheDryRun { |
|
37 | clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun) |
||
38 | os.Exit(0) |
||
39 | } |
||
40 | 1 | if *rateLimitCheck { |
|
41 | checkAndPrintRateLimit() |
||
42 | os.Exit(0) |
||
43 | } |
||
44 | 1 | if *rateLimitCheck { |
|
45 | checkAndPrintRateLimit() |
||
46 | os.Exit(0) |
||
47 | } |
||
48 | 1 | if *repositoriesKeysManual != "" { |
|
49 | repositoriesKeys = strings.Split(*repositoriesKeysManual, ",") |
||
50 | } else { |
||
51 | 1 | repositoriesKeys = []string{ |
|
52 | "astaxie/beego", |
||
53 | "gohugoio/hugo", |
||
54 | "gin-gonic/gin", |
||
55 | "labstack/echo", |
||
56 | "revel/revel", |
||
57 | "gobuffalo/buffalo", |
||
58 | "go-chi/chi", |
||
59 | "kataras/iris", |
||
60 | "zenazn/goji", |
||
61 | } |
||
62 | } |
||
63 | 1 | csvFilePath := "" |
|
64 | 1 | if *resultFileSavePath != "" { |
|
65 | csvFilePath = *resultFileSavePath |
||
66 | } else { |
||
67 | 1 | csvFilePath = "result.csv" |
|
68 | } |
||
69 | 1 | var ghData = [][]string{} |
|
70 | 1 | headers := []string{ |
|
71 | "Name", |
||
72 | "URL", |
||
73 | "Author", |
||
74 | "License", |
||
75 | "Author's followers", |
||
76 | "Top 10 contributors followers", |
||
77 | "Created at", |
||
78 | "Age in days", |
||
79 | "Total commits", |
||
80 | "Total additions", |
||
81 | "Total deletions", |
||
82 | "Total code changes", |
||
83 | "Last commit date", |
||
84 | "Commits/day", |
||
85 | "Medium commit size", |
||
86 | "Total releases", |
||
87 | "Stargazers", |
||
88 | "Forks", |
||
89 | "Contributors", |
||
90 | "Active forkers, %", |
||
91 | "Open issues", |
||
92 | "Total issues", |
||
93 | "Issue/day", |
||
94 | "Closed issues, %", |
||
95 | "Place", |
||
96 | } |
||
97 | 1 | ghDataColumnIndexes := map[string]int{ |
|
98 | "nameColumn": 0, |
||
99 | "urlColumn": 1, |
||
100 | "authorColumn": 2, |
||
101 | "licenseColumn": 3, |
||
102 | "authorsFollowersColumn": 4, |
||
103 | "top10ContributorsFollowersColumn": 5, |
||
104 | "ageColumn": 7, |
||
105 | "totalCommitsColumn": 8, |
||
106 | "totalAdditionsColumn": 9, |
||
107 | "totalDeletionsColumn": 10, |
||
108 | "totalCodeChangesColumn": 11, |
||
109 | "lastCommitDateColumn": 12, |
||
110 | "commitsByDayColumn": 13, |
||
111 | "mediCommitSizeColumn": 14, |
||
112 | "totalTagsColumn": 15, |
||
113 | "stargazersColumn": 16, |
||
114 | "activeForkersColumn": 19, |
||
115 | "issuesByDayColumn": 22, |
||
116 | "closedIssuesPercentageColumn": 23, |
||
117 | "totalPointsColumnIndex": 24, |
||
118 | } |
||
119 | 1 | dataChan := make(chan []string, len(repositoriesKeys)) |
|
120 | 1 | for _, rKey := range repositoriesKeys { |
|
121 | 1 | go fillRepositoryStatistics(rKey, *tmpFolder, *debug, dataChan) |
|
122 | } |
||
123 | 1 | for range repositoriesKeys { |
|
124 | 1 | ghData = append(ghData, <-dataChan) |
|
125 | } |
||
126 | 1 | greetings := rateGhData(ghData, ghDataColumnIndexes) |
|
127 | 1 | fmt.Println(greetings) |
|
128 | 1 | writeCsv(csvFilePath, headers, ghData) |
|
129 | } |
||
270 |