| Conditions | 19 |
| Total Lines | 70 |
| Code Lines | 54 |
| 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 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ.CSSClasses(templ_7745c5c3_Var5).String())) |
||
| 104 | if templ_7745c5c3_Err != nil { |
||
| 105 | return templ_7745c5c3_Err |
||
| 106 | } |
||
| 107 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" value=\"") |
||
| 108 | if templ_7745c5c3_Err != nil { |
||
| 109 | return templ_7745c5c3_Err |
||
| 110 | } |
||
| 111 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.Itoa(int(value)))) |
||
| 112 | if templ_7745c5c3_Err != nil { |
||
| 113 | return templ_7745c5c3_Err |
||
| 114 | } |
||
| 115 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" max=\"100\"></progress> ") |
||
| 116 | if templ_7745c5c3_Err != nil { |
||
| 117 | return templ_7745c5c3_Err |
||
| 118 | } |
||
| 119 | if err != nil { |
||
| 120 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<span class=\"text-xs text-gray-500\">") |
||
| 121 | if templ_7745c5c3_Err != nil { |
||
| 122 | return templ_7745c5c3_Err |
||
| 123 | } |
||
| 124 | var templ_7745c5c3_Var6 string |
||
| 125 | templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(err.Error()) |
||
| 126 | if templ_7745c5c3_Err != nil { |
||
| 127 | return templ.Error{Err: templ_7745c5c3_Err, FileName: `app/v2/views/components/register.component.templ`, Line: 80, Col: 17} |
||
| 128 | } |
||
| 129 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) |
||
| 130 | if templ_7745c5c3_Err != nil { |
||
| 131 | return templ_7745c5c3_Err |
||
| 132 | } |
||
| 133 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span>") |
||
| 134 | if templ_7745c5c3_Err != nil { |
||
| 135 | return templ_7745c5c3_Err |
||
| 136 | } |
||
| 137 | } |
||
| 138 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") |
||
| 139 | if templ_7745c5c3_Err != nil { |
||
| 140 | return templ_7745c5c3_Err |
||
| 141 | } |
||
| 142 | if !templ_7745c5c3_IsBuffer { |
||
| 143 | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W) |
||
| 144 | } |
||
| 145 | return templ_7745c5c3_Err |
||
| 146 | }) |
||
| 148 |