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.

main.main   C
last analyzed

Complexity

Conditions 10

Size

Total Lines 58
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 11.2294

Importance

Changes 0
Metric Value
cc 10
eloc 48
nop 0
dl 0
loc 58
ccs 20
cts 26
cp 0.7692
crap 11.2294
rs 5.9018
c 0
b 0
f 0

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.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.
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
// ghstat - statistical multi-criteria decision-making comparator for Github's projects.
6
package main
7
8
import (
9
	"flag"
10
	"os"
11
	"strings"
12
	"sync"
13
14
	"github.com/fedir/ghstat/github"
15
)
16
17
func main() {
18 1
	var (
19
		clearHTTPCache         = flag.Bool("cc", false, "Clear HTTP cache")
20
		clearHTTPCacheDryRun   = flag.Bool("ccdr", false, "Clear HTTP cache (dry run)")
21
		debug                  = flag.Bool("d", false, "Debug mode")
22
		resultFileSavePath     = flag.String("f", "", "File path where result CSV file will be saved")
23
		rateLimitCheck         = flag.Bool("l", false, "Rate limit check")
24
		repositoriesKeysManual = flag.String("r", "", "Repositories keys")
25
		tmpFolder              = flag.String("t", "test_data", "Temporary folder path")
26
		repositoriesKeys       = []string{}
27
	)
28 1
	flag.Parse()
29 1
	if *clearHTTPCache || *clearHTTPCacheDryRun {
30
		clearHTTPCacheFolder(*tmpFolder, *clearHTTPCacheDryRun)
31
		os.Exit(0)
32
	}
33 1
	if *rateLimitCheck {
34
		github.CheckAndPrintRateLimit()
35
		os.Exit(0)
36
	}
37 1
	if *repositoriesKeysManual != "" {
38
		repositoriesKeys = uniqSlice(strings.Split(*repositoriesKeysManual, ","))
39
	} else {
40 1
		repositoriesKeys = uniqSlice([]string{
41
			"astaxie/beego",
42
			"gohugoio/hugo",
43
			"gin-gonic/gin",
44
			"labstack/echo",
45
			"revel/revel",
46
			"gobuffalo/buffalo",
47
			"go-chi/chi",
48
			"kataras/iris",
49
			"zenazn/goji",
50
			"go-macaron/macaron",
51
			"go-aah/aah",
52
		})
53
	}
54
55 1
	csvFilePath := ""
56 1
	if *resultFileSavePath != "" {
57
		csvFilePath = *resultFileSavePath
58
	} else {
59 1
		csvFilePath = "result.csv"
60
	}
61 1
	var ghData = []Repository{}
62 1
	var wg sync.WaitGroup
63 1
	wg.Add(len(repositoriesKeys))
64
65 1
	dataChan := make(chan Repository, len(repositoriesKeys))
66 1
	for _, rKey := range repositoriesKeys {
67 1
		go repositoryData(rKey, *tmpFolder, *debug, dataChan, &wg)
68
	}
69 1
	for range repositoriesKeys {
70 1
		ghData = append(ghData, <-dataChan)
71
	}
72 1
	wg.Wait()
73 1
	rateAndPrintGreetings(ghData)
74 1
	writeCSVStatistics(ghData, csvFilePath)
75
}
76
77
func uniqSlice(s []string) []string {
78 1
	unique := make(map[string]bool, len(s))
79 1
	us := make([]string, len(unique))
80 1
	for _, elem := range s {
81 1
		if len(elem) != 0 {
82 1
			if !unique[elem] {
83 1
				us = append(us, elem)
84 1
				unique[elem] = true
85
			}
86
		}
87
	}
88 1
	return us
89
}
90