| Conditions | 1 |
| Paths | 1 |
| Total Lines | 63 |
| Code Lines | 13 |
| 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 |
||
| 66 | protected function updateContent(ManialinkInterface $manialink) |
||
| 67 | { |
||
| 68 | // Do stuff Here. |
||
| 69 | $manialink->removeAllChildren(); |
||
|
|
|||
| 70 | $manialink->getFmlManialink()->getScript()->addScriptFunction("", |
||
| 71 | <<<EOL |
||
| 72 | |||
| 73 | Void onButtonOver(CMlControl Element) { |
||
| 74 | Audio.PlaySoundEvent( CAudioManager::ELibSound::ScoreIncrease, 0, 0.); |
||
| 75 | |||
| 76 | if (Element is CMlLabel) { |
||
| 77 | declare El = (Element as CMlLabel); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (Element.HasClass("noAnim") == False) { |
||
| 81 | AnimMgr.Add(Element, "<elem scale=\"1.3\" />", 300, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | Void onButtonOut(CMlControl Element) { |
||
| 86 | if (Element.HasClass("noAnim") == False) { |
||
| 87 | AnimMgr.Add(Element, "<elem scale=\"1.0\" />", 300, CAnimManager::EAnimManagerEasing::ElasticOut); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | |||
| 92 | ***FML_OnInit*** |
||
| 93 | *** |
||
| 94 | declare CMlFrame Exp_Window <=> (Page.GetFirstChild("Window") as CMlFrame); |
||
| 95 | Exp_Window.ZIndex = 10000.; |
||
| 96 | *** |
||
| 97 | |||
| 98 | ***FML_Loop*** |
||
| 99 | *** |
||
| 100 | |||
| 101 | |||
| 102 | // handle pending events |
||
| 103 | foreach (Event in PendingEvents) { |
||
| 104 | |||
| 105 | // mouse hover states |
||
| 106 | if (Event.Type == CMlScriptEvent::Type::MouseOver && Event.Control.HasClass("menuItem")) { |
||
| 107 | onButtonOver(Event.Control); |
||
| 108 | } |
||
| 109 | |||
| 110 | if (Event.Type == CMlScriptEvent::Type::MouseOut && Event.Control.HasClass("menuItem")) { |
||
| 111 | onButtonOut(Event.Control); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | *** |
||
| 115 | |||
| 116 | EOL |
||
| 117 | ); |
||
| 118 | |||
| 119 | |||
| 120 | $button = $this->uiFactory->createButton("Admin", uiButton::TYPE_DECORATED); |
||
| 121 | $button->setPosition(-150, 70); |
||
| 122 | $button->setScale(1); |
||
| 123 | |||
| 124 | $button->setAction($this->actionFactory->createManialinkAction($manialink, [$this, 'createMenu'], |
||
| 125 | [$manialink])); |
||
| 126 | $manialink->addChild($button); |
||
| 127 | $manialink->addChild($this->currentMenuView); |
||
| 128 | } |
||
| 129 | |||
| 240 |
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 implementation 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 interface: