| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 5 |
| 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 | <?php |
||
| 34 | protected function getScriptFunction() |
||
| 35 | { |
||
| 36 | return /** language=textmate prefix=#RequireContext\n */ |
||
| 37 | <<<'EOD' |
||
| 38 | |||
| 39 | ***FML_OnInit*** |
||
| 40 | *** |
||
| 41 | declare Integer[Ident] pendingConfirms for Page = Integer[Ident]; |
||
| 42 | declare Text[Ident] pendingConfirmIds for Page = Text[Ident]; |
||
| 43 | declare CMlLabel[Ident] pendingConfirmControls for Page = CMlLabel[Ident]; |
||
| 44 | |||
| 45 | pendingConfirms.clear(); |
||
| 46 | pendingConfirmIds.clear(); |
||
| 47 | pendingConfirmControls.clear(); |
||
| 48 | *** |
||
| 49 | |||
| 50 | ***FML_Loop*** |
||
| 51 | *** |
||
| 52 | foreach (Id => Time in pendingConfirms) { |
||
| 53 | if (Now > Time + (3 * 1000) ) { |
||
| 54 | if (pendingConfirmIds.existskey(Id)) { |
||
| 55 | pendingConfirmControls[Id].Value = pendingConfirmIds[Id]; |
||
| 56 | pendingConfirmIds.removekey(Id); |
||
| 57 | pendingConfirms.removekey(Id); |
||
| 58 | pendingConfirmControls.removekey(Id); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | *** |
||
| 63 | |||
| 64 | |||
| 65 | Void TriggerConfirmButtonClick(CMlLabel Control) { |
||
| 66 | declare Integer[Ident] pendingConfirms for Page = Integer[Ident]; |
||
| 67 | declare Text[Ident] pendingConfirmIds for Page = Text[Ident]; |
||
| 68 | declare CMlLabel[Ident] pendingConfirmControls for Page = CMlLabel[Ident]; |
||
| 69 | |||
| 70 | if (Control.Parent.HasClass("uiButton")) { |
||
| 71 | if (pendingConfirmIds.existskey(Control.Id) == False) { |
||
| 72 | pendingConfirmIds[Control.Id] = Control.Value; |
||
| 73 | pendingConfirmControls[Control.Id] = Control; |
||
| 74 | pendingConfirms[Control.Id] = Now; |
||
| 75 | Control.Value = "Confirm ?"; |
||
| 76 | Control.Parent.RelativeScale = 0.75; |
||
| 77 | AnimMgr.Add(Control.Parent, "<elem scale=\"1.\" />", 200, CAnimManager::EAnimManagerEasing::QuadIn); |
||
| 78 | } else { |
||
| 79 | Control.Value = pendingConfirmIds[Control.Id]; |
||
| 80 | pendingConfirmIds.removekey(Control.Id); |
||
| 81 | pendingConfirms.removekey(Control.Id); |
||
| 82 | pendingConfirmControls.removekey(Control.Id); |
||
| 83 | Control.Parent.RelativeScale = 0.75; |
||
| 84 | AnimMgr.Add(Control.Parent, "<elem scale=\"1.\" />", 200, CAnimManager::EAnimManagerEasing::QuadIn); |
||
| 85 | TriggerPageAction(Control.Parent.DataAttributeGet("action")); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | |||
| 91 | Void TriggerConfirmButtonClick(Text ControlId) { |
||
| 92 | declare CMlLabel Control = (Page.GetFirstChild(ControlId) as CMlLabel); |
||
| 93 | TriggerConfirmButtonClick(Control); |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | EOD; |
||
| 98 | } |
||
| 99 | |||
| 101 |