Conditions | 1 |
Paths | 1 |
Total Lines | 78 |
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 |
||
52 | public function getFunctions() |
||
53 | { |
||
54 | |||
55 | return /** @lang textmate */ |
||
56 | <<<EOL |
||
57 | |||
58 | ***FML_OnInit*** |
||
59 | *** |
||
60 | declare CMlFrame exp_tooltip = (Page.GetFirstChild("exp_tooltip") as CMlFrame); |
||
61 | declare Boolean exp_tooltip_move = False; |
||
62 | declare Boolean exp_tooltip_toggle = True; |
||
63 | declare Integer exp_tooltip_delay = 0; |
||
64 | declare Vec2 mouse_pos = <0., 0.>; |
||
65 | declare Vec2 exp_tooltip_rel = <0., 0.>; |
||
66 | *** |
||
67 | |||
68 | ***FML_Loop*** |
||
69 | *** |
||
70 | if (exp_tooltip_move) { |
||
71 | exp_tooltip.RelativePosition_V3 = <MouseX, MouseY> - mouse_pos + exp_tooltip_rel; |
||
72 | |||
73 | /* if (exp_tooltip_rel.Y > -10.) { |
||
74 | exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 0.>; |
||
75 | } else { |
||
76 | exp_tooltip.RelativePosition_V3 = exp_tooltip_rel + <4., 4.>; |
||
77 | } */ |
||
78 | |||
79 | if (exp_tooltip_delay + 350 < Now) { |
||
80 | if (exp_tooltip_toggle) { |
||
81 | AnimMgr.Add(exp_tooltip.Controls[0], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
82 | AnimMgr.Add(exp_tooltip.Controls[1], "<elem scale=\"1\" />", 450, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
83 | exp_tooltip_toggle = False; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (MouseLeftButton) { |
||
89 | (exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
||
90 | (exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
||
91 | } |
||
92 | *** |
||
93 | |||
94 | ***FML_MouseOver*** |
||
95 | *** |
||
96 | if (Event.Control != Null) { |
||
97 | if (Event.Control.HasClass("uiTooltip") ) { |
||
98 | declare tooltipLabel = (exp_tooltip.Controls[0] as CMlLabel); |
||
99 | declare text = Event.Control.DataAttributeGet("tooltip"); |
||
100 | declare sizeX = tooltipLabel.ComputeWidth(text); |
||
101 | tooltipLabel.Value = text; |
||
102 | tooltipLabel.Size.X = sizeX; |
||
103 | (exp_tooltip.Controls[1] as CMlQuad).Size.X = sizeX; |
||
104 | exp_tooltip_move = True; |
||
105 | exp_tooltip_delay = Now; |
||
106 | exp_tooltip_toggle = True; |
||
107 | mouse_pos = <MouseX, MouseY>; |
||
108 | // exp_tooltip_rel = Event.Control.AbsolutePosition_V3 + Exp_Window.RelativePosition_V3; |
||
109 | exp_tooltip_rel = Event.Control.AbsolutePosition_V3 - Exp_Window.RelativePosition_V3; |
||
110 | } |
||
111 | } |
||
112 | *** |
||
113 | |||
114 | ***FML_MouseOut*** |
||
115 | *** |
||
116 | if (Event.Control != Null) { |
||
117 | if (Event.Control.HasClass("uiTooltip") ) { |
||
118 | exp_tooltip_move = False; |
||
119 | exp_tooltip_delay = 0; |
||
120 | exp_tooltip_toggle = True; |
||
121 | (exp_tooltip.Controls[0] as CMlLabel).RelativeScale = 0.; |
||
122 | (exp_tooltip.Controls[1] as CMlQuad).RelativeScale = 0.; |
||
123 | } |
||
124 | } |
||
125 | *** |
||
126 | |||
127 | EOL; |
||
128 | |||
129 | } |
||
130 | |||
176 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: