未验证 提交 1169387b 编写于 作者: P Phodal Huang

feat: add method num filter

上级 1acd669d
......@@ -22,6 +22,10 @@ Todo:
- Evaluate API
- [ ] Average Method Length
- [ ] Average Class Method Count
- Date Collections
- [ ] monolithic
- [ ] microservice
- [ ] big data
## Usage
......
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{
......
......@@ -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)
......
......@@ -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
}
}
}
......
......@@ -20,6 +20,8 @@ type Summary struct {
UtilsCount int
ClassCount int
MethodCount int
NormalMethodCount int
TotalMethodLength int
StaticMethodCount int
}
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册