| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| 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 |
||
| 53 | public function getFunctions() |
||
| 54 | { |
||
| 55 | |||
| 56 | return /** @lang textmate */ |
||
| 57 | <<<EOL |
||
| 58 | |||
| 59 | ***FML_OnInit*** |
||
| 60 | *** |
||
| 61 | declare CMlFrame exp_tooltip = (Page.GetFirstChild("exp_tooltip") as CMlFrame); |
||
| 62 | declare Boolean exp_tooltip_move = False; |
||
| 63 | declare Boolean exp_tooltip_toggle = True; |
||
| 64 | declare Integer exp_tooltip_delay = 0; |
||
| 65 | declare Vec2 mouse_pos = <0., 0.>; |
||
| 66 | declare Vec2 exp_tooltip_rel = <0., 0.>; |
||
| 67 | *** |
||
| 68 | |||
| 69 | ***FML_Loop*** |
||
| 70 | *** |
||
| 71 | if (exp_tooltip_move) { |
||
| 72 | exp_tooltip.RelativePosition_V3 = <MouseX, MouseY> - mouse_pos + exp_tooltip_rel; |
||
| 73 | |||
| 74 | /* if (exp_tooltip_rel.Y > -10.) { |
||
| 75 | exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 0.>; |
||
| 76 | } else { |
||
| 77 | exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 4.>; |
||
| 78 | } */ |
||
| 79 | |||
| 80 | if (exp_tooltip_delay + 350 < Now) { |
||
| 81 | if (exp_tooltip_toggle) { |
||
| 82 | AnimMgr.Add(exp_tooltip.Controls[0], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
| 83 | AnimMgr.Add(exp_tooltip.Controls[1], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
| 84 | exp_tooltip_toggle = False; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | if (MouseLeftButton) { |
||
| 90 | (exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
||
| 91 | (exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
||
| 92 | } |
||
| 93 | *** |
||
| 94 | |||
| 95 | ***FML_MouseOver*** |
||
| 96 | *** |
||
| 97 | if (Event.Control != Null) { |
||
| 98 | if (Event.Control.HasClass("tooltip") ) { |
||
| 99 | declare tooltipLabel = (exp_tooltip.Controls[0] as CMlLabel); |
||
| 100 | declare text = Event.Control.DataAttributeGet("tooltip"); |
||
| 101 | declare sizeX = tooltipLabel.ComputeWidth(text); |
||
| 102 | tooltipLabel.Value = text; |
||
| 103 | tooltipLabel.Size.X = sizeX; |
||
| 104 | (exp_tooltip.Controls[1] as CMlQuad).Size.X = sizeX; |
||
| 105 | exp_tooltip_move = True; |
||
| 106 | exp_tooltip_delay = Now; |
||
| 107 | exp_tooltip_toggle = True; |
||
| 108 | mouse_pos = <MouseX, MouseY>; |
||
| 109 | // exp_tooltip_rel = Event.Control.AbsolutePosition_V3 + Exp_Window.RelativePosition_V3; |
||
| 110 | exp_tooltip_rel = Event.Control.AbsolutePosition_V3 - Exp_Window.RelativePosition_V3; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | *** |
||
| 114 | |||
| 115 | ***FML_MouseOut*** |
||
| 116 | *** |
||
| 117 | if (Event.Control != Null) { |
||
| 118 | if (Event.Control.HasClass("tooltip") ) { |
||
| 119 | exp_tooltip_move = False; |
||
| 120 | exp_tooltip_delay = 0; |
||
| 121 | exp_tooltip_toggle = True; |
||
| 122 | (exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
||
| 123 | (exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | *** |
||
| 127 | |||
| 128 | EOL; |
||
| 129 | |||
| 130 | } |
||
| 131 | |||
| 177 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: