| Conditions | 1 | 
| Total Lines | 52 | 
| Code Lines | 30 | 
| Lines | 0 | 
| Ratio | 0 % | 
| 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:
| 1 | package tree_test  | 
            ||
| 14 | func TestNewResultTreePrinter(t *testing.T) { | 
            ||
| 15 | 	results := []scan.Result{ | 
            ||
| 16 | scan.NewResult(  | 
            ||
| 17 | 			scan.Target{ | 
            ||
| 18 | Method: http.MethodPost,  | 
            ||
| 19 | Path: "/home",  | 
            ||
| 20 | },  | 
            ||
| 21 | 			&http.Response{ | 
            ||
| 22 | StatusCode: http.StatusCreated,  | 
            ||
| 23 | 				Request: &http.Request{ | 
            ||
| 24 | URL: test.MustParseURL(t, "http://mysite/home"),  | 
            ||
| 25 | },  | 
            ||
| 26 | },  | 
            ||
| 27 | ),  | 
            ||
| 28 | scan.NewResult(  | 
            ||
| 29 | 			scan.Target{ | 
            ||
| 30 | Method: http.MethodPost,  | 
            ||
| 31 | Path: "/home/123",  | 
            ||
| 32 | },  | 
            ||
| 33 | 			&http.Response{ | 
            ||
| 34 | StatusCode: http.StatusCreated,  | 
            ||
| 35 | 				Request: &http.Request{ | 
            ||
| 36 | URL: test.MustParseURL(t, "http://mysite/home/123"),  | 
            ||
| 37 | },  | 
            ||
| 38 | },  | 
            ||
| 39 | ),  | 
            ||
| 40 | scan.NewResult(  | 
            ||
| 41 | 			scan.Target{ | 
            ||
| 42 | Method: http.MethodPost,  | 
            ||
| 43 | Path: "/about",  | 
            ||
| 44 | },  | 
            ||
| 45 | 			&http.Response{ | 
            ||
| 46 | StatusCode: http.StatusCreated,  | 
            ||
| 47 | 				Request: &http.Request{ | 
            ||
| 48 | URL: test.MustParseURL(t, "http://mysite/about"),  | 
            ||
| 49 | },  | 
            ||
| 50 | },  | 
            ||
| 51 | ),  | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 | 	buf := &bytes.Buffer{} | 
            ||
| 55 | |||
| 56 | tree.NewResultTreePrinter().Print(results, buf)  | 
            ||
| 57 | |||
| 58 | expected := `/  | 
            ||
| 59 | ├── about  | 
            ||
| 60 | └── home  | 
            ||
| 61 | └── 123  | 
            ||
| 62 | |||
| 63 | `  | 
            ||
| 64 | |||
| 65 | assert.Equal(t, expected, buf.String())  | 
            ||
| 66 | }  | 
            ||
| 67 |