diff --git a/README.md b/README.md index 0c72dc2cddaf1c25ca453893936fb74171f25430..2d7a3d2d2f4c4cbda379802314e1aa0ede7bbe7c 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,10 @@ Todo: - Evaluate API - [ ] Average Method Length - [ ] Average Class Method Count + - Date Collections + - [ ] monolithic + - [ ] microservice + - [ ] big data ## Usage diff --git a/cmd/api.go b/cmd/api.go index 0d97ce3947252198c179283c8d850e403bc45458..ca8e9ae7cb986042bcd13b85908e43d27d88aade 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -1,14 +1,14 @@ package cmd import ( + "encoding/json" + "github.com/olekukonko/tablewriter" "github.com/phodal/coca/config" "github.com/phodal/coca/core/adapter" . "github.com/phodal/coca/core/adapter/api" "github.com/phodal/coca/core/domain/call_graph" "github.com/phodal/coca/core/models" . "github.com/phodal/coca/core/support" - "encoding/json" - "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "log" "os" @@ -31,11 +31,11 @@ type ApiCmdConfig struct { var ( apiCmdConfig ApiCmdConfig - restApis []RestApi + restApis []RestApi - identifiers = adapter.LoadIdentify(apiCmdConfig.DependencePath) + identifiers = adapter.LoadIdentify(apiCmdConfig.DependencePath) identifiersMap = adapter.BuildIdentifierMap(identifiers) - diMap = adapter.BuildDIMap(identifiers, identifiersMap) + diMap = adapter.BuildDIMap(identifiers, identifiersMap) ) var apiCmd = &cobra.Command{ diff --git a/cmd/evaluate.go b/cmd/evaluate.go index f3fd18aa3306b9fe6ea2758167aa1077daf1b32d..4296cf538bc4cd3ea0e25c64bceac2f08678ea55 100644 --- a/cmd/evaluate.go +++ b/cmd/evaluate.go @@ -61,6 +61,12 @@ var evaluateCmd = &cobra.Command{ staticCount := result.Summary.StaticMethodCount table.Append([]string{"Static Method", strconv.Itoa(staticCount), "Method", strconv.Itoa(methodCount), Percent(utilsCount, methodCount)}) + table.Append([]string{"Average Method Num", strconv.Itoa(methodCount), "Method/Class", strconv.Itoa(classCount), Rate(methodCount, classCount)}) + + totalLength := result.Summary.TotalMethodLength + normalMethodCount := result.Summary.NormalMethodCount + table.Append([]string{"Average Method Length", strconv.Itoa(totalLength), "Without Getter/Setter", strconv.Itoa(normalMethodCount), Rate(totalLength, normalMethodCount)}) + table.Render() }, } @@ -70,6 +76,11 @@ func Percent(pcent int, all int) string { return fmt.Sprintf("%3.2f%%", percent) } +func Rate(pcent int, all int) string { + percent := float64(pcent) / float64(all) + return fmt.Sprintf("%f", percent) +} + func init() { rootCmd.AddCommand(evaluateCmd) diff --git a/core/domain/evaluate/analyser.go b/core/domain/evaluate/analyser.go index 5adb0cbc76ce1b17c863a925ba8c4efa63f0f7e8..f075f98918dd6aa7eb192b66ba68e016459ebd34 100644 --- a/core/domain/evaluate/analyser.go +++ b/core/domain/evaluate/analyser.go @@ -46,6 +46,11 @@ func (a Analyser) Analysis(classNodes []models.JClassNode, identifiers []models. if support.Contains(method.Modifiers, "static") { result.Summary.StaticMethodCount++ } + + if !strings.HasPrefix(method.Name, "set") && !strings.HasPrefix(method.Name, "get") { + result.Summary.NormalMethodCount++ + result.Summary.TotalMethodLength = result.Summary.TotalMethodLength + method.StopLine - method.StartLine + 1 + } } } diff --git a/core/domain/evaluate/evaluator/models.go b/core/domain/evaluate/evaluator/models.go index d358327381f85d484a17143c4623520ec811f388..d90410f7ec2e16f733f861dcc1c001985566464e 100644 --- a/core/domain/evaluate/evaluator/models.go +++ b/core/domain/evaluate/evaluator/models.go @@ -20,6 +20,8 @@ type Summary struct { UtilsCount int ClassCount int MethodCount int + NormalMethodCount int + TotalMethodLength int StaticMethodCount int } diff --git a/docs/patterns/evaluate.md b/docs/patterns/evaluate.md new file mode 100644 index 0000000000000000000000000000000000000000..23791777ed3144719246f60298bb6d2dd3d63e72 --- /dev/null +++ b/docs/patterns/evaluate.md @@ -0,0 +1,116 @@ +url: https://github.com/macrozheng/mall + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 22 | Method | 12682 | 0.17% | +| Utils | 2 | Class | 458 | 0.44% | +| Static Method | 7 | Method | 12682 | 0.02% | +| Average Method Num | 12682 | Method/Class | 458 | 27.689956 | +| Average Method Length | 45091 | Without Getter/Setter | 10205 | 4.418520 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// issues: big data class / god service + +url: https://github.com/shuzheng/zheng + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 0 | Method | 5256 | 0.00% | +| Utils | 18 | Class | 366 | 4.92% | +| Static Method | 0 | Method | 5256 | 0.34% | +| Average Method Num | 5256 | Method/Class | 366 | 14.360656 | +| Average Method Length | 19644 | Without Getter/Setter | 4328 | 4.538817 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// data class + +big data + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 128 | Method | 3041 | 4.21% | +| Utils | 18 | Class | 496 | 7.06% | +| Static Method | 400 | Method | 3041 | 1.15% | +| Average Method Num | 3041 | Method/Class | 496 | 6.13 | +| Average Method Length | 17730 | Without Getter/Setter | 1551 | 11.43 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// null issues + +Common Project + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 234 | Method | 16642 | 1.41% | +| Utils | 26 | Class | 1007 | 7.06% | +| Static Method | 2062 | Method | 16642 | 0.16% | +| Average Method Num | 16642 | Method/Class | 1007 | 16.52 | +| Average Method Length | 69012 | Without Getter/Setter | 6020 | 11.46 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// static projects + +Algo Project + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 101 | Method | 4914 | 2.06% | +| Utils | 43 | Class | 926 | 4.64% | +| Static Method | 542 | Method | 4914 | 0.88% | +| Average Method Num | 4914 | Method/Class | 927 | 5.30 | +| Average Method Length | 51056 | Without Getter/Setter | 2603 | 19.61 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// longest method + +CMS + +url: https://github.com/sanluan/PublicCMS + +``` ++------------------------+-------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+-------+-----------------------+-------+-----------+ +| Nullable / Return Null | 131 | Method | 2707 | 4.84% | +| Utils | 21 | Class | 483 | 4.35% | +| Static Method | 246 | Method | 2707 | 0.78% | +| Average Method Num | 2707 | Method/Class | 483 | 5.604555 | +| Average Method Length | 13622 | Without Getter/Setter | 1350 | 10.090370 | ++------------------------+-------+-----------------------+-------+-----------+ +``` + +// to many null + +ERP + +url: https://github.com/ilscipio/scipio-erp + +``` ++------------------------+--------+-----------------------+-------+-----------+ +| TYPE | COUNT | LEVEL | TOTAL | RATE | ++------------------------+--------+-----------------------+-------+-----------+ +| Nullable / Return Null | 1660 | Method | 23461 | 7.08% | +| Utils | 86 | Class | 2288 | 3.76% | +| Static Method | 6469 | Method | 23461 | 0.37% | +| Average Method Num | 23461 | Method/Class | 2288 | 10.253934 | +| Average Method Length | 228550 | Without Getter/Setter | 14080 | 16.232244 | ++------------------------+--------+-----------------------+-------+-----------+ +``` + +// longest method +// to many null (bugs) \ No newline at end of file