Conditions | 21 |
Total Lines | 80 |
Code Lines | 62 |
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:
Complex classes like components.PasswordEntropy 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 | // Code generated by templ - DO NOT EDIT. |
||
76 | func PasswordEntropy(value float64, err error) templ.Component { |
||
77 | return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { |
||
78 | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) |
||
79 | if !templ_7745c5c3_IsBuffer { |
||
80 | templ_7745c5c3_Buffer = templ.GetBuffer() |
||
81 | defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) |
||
82 | } |
||
83 | ctx = templ.InitializeContext(ctx) |
||
84 | templ_7745c5c3_Var4 := templ.GetChildren(ctx) |
||
85 | if templ_7745c5c3_Var4 == nil { |
||
86 | templ_7745c5c3_Var4 = templ.NopComponent |
||
87 | } |
||
88 | ctx = templ.ClearChildren(ctx) |
||
89 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div id=\"password-entropy\" hx-swap-oob=\"true\"><span class=\"label-text\">Strength of password</span> ") |
||
90 | if templ_7745c5c3_Err != nil { |
||
91 | return templ_7745c5c3_Err |
||
92 | } |
||
93 | var templ_7745c5c3_Var5 = []any{"progress w-full transition-all ease-out duration-[6s]", templ.KV("progress-error", value < 72), |
||
94 | templ.KV("progress-warning", value >= 72 && value < 80), templ.KV("progress-success", value >= 80)} |
||
95 | templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var5...) |
||
96 | if templ_7745c5c3_Err != nil { |
||
97 | return templ_7745c5c3_Err |
||
98 | } |
||
99 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<progress id=\"pb\" class=\"") |
||
100 | if templ_7745c5c3_Err != nil { |
||
101 | return templ_7745c5c3_Err |
||
102 | } |
||
103 | var templ_7745c5c3_Var6 string |
||
104 | templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var5).String()) |
||
105 | if templ_7745c5c3_Err != nil { |
||
106 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/components/register.component.templ`, Line: 1, Col: 0} |
||
107 | } |
||
108 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) |
||
109 | if templ_7745c5c3_Err != nil { |
||
110 | return templ_7745c5c3_Err |
||
111 | } |
||
112 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" value=\"") |
||
113 | if templ_7745c5c3_Err != nil { |
||
114 | return templ_7745c5c3_Err |
||
115 | } |
||
116 | var templ_7745c5c3_Var7 string |
||
117 | templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(int(value))) |
||
118 | if templ_7745c5c3_Err != nil { |
||
119 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/components/register.component.templ`, Line: 76, Col: 35} |
||
120 | } |
||
121 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) |
||
122 | if templ_7745c5c3_Err != nil { |
||
123 | return templ_7745c5c3_Err |
||
124 | } |
||
125 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" max=\"100\"></progress> ") |
||
126 | if templ_7745c5c3_Err != nil { |
||
127 | return templ_7745c5c3_Err |
||
128 | } |
||
129 | if err != nil { |
||
130 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"text-xs text-gray-500\">") |
||
131 | if templ_7745c5c3_Err != nil { |
||
132 | return templ_7745c5c3_Err |
||
133 | } |
||
134 | var templ_7745c5c3_Var8 string |
||
135 | templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(err.Error()) |
||
136 | if templ_7745c5c3_Err != nil { |
||
137 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/components/register.component.templ`, Line: 81, Col: 17} |
||
138 | } |
||
139 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) |
||
140 | if templ_7745c5c3_Err != nil { |
||
141 | return templ_7745c5c3_Err |
||
142 | } |
||
143 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span>") |
||
144 | if templ_7745c5c3_Err != nil { |
||
145 | return templ_7745c5c3_Err |
||
146 | } |
||
147 | } |
||
148 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") |
||
149 | if templ_7745c5c3_Err != nil { |
||
150 | return templ_7745c5c3_Err |
||
151 | } |
||
152 | if !templ_7745c5c3_IsBuffer { |
||
153 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) |
||
154 | } |
||
155 | return templ_7745c5c3_Err |
||
156 | }) |
||
158 |