| Conditions | 1 |
| Paths | 1 |
| Total Lines | 143 |
| Code Lines | 115 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 158 | protected function createGrid(ManialinkInterface $manialink) |
||
| 159 | { |
||
| 160 | $collection = $this->dataCollectionFactory->create($this->getData()); |
||
| 161 | $collection->setPageSize(20); |
||
| 162 | |||
| 163 | $x = 0; |
||
| 164 | |||
| 165 | $tooltip = $this->uiFactory->createTooltip(); |
||
| 166 | $manialink->addChild($tooltip); |
||
| 167 | |||
| 168 | $this->modebox = $this->uiFactory->createDropdown("mode", $this->tracksearch, 0); |
||
| 169 | $this->modebox->setPosition($x, -6, 2); |
||
| 170 | $manialink->addChild($this->modebox); |
||
| 171 | |||
| 172 | $label = $this->uiFactory->createLabel("Sort by", uiLabel::TYPE_HEADER); |
||
| 173 | $label->setPosition($x, 0); |
||
| 174 | $manialink->addChild($label); |
||
| 175 | |||
| 176 | $x += 32; |
||
| 177 | $this->orderbox = $this->uiFactory->createDropdown("order", $this->order, 0); |
||
| 178 | $this->orderbox->setPosition($x, -6, 2); |
||
| 179 | $manialink->addChild($this->orderbox); |
||
| 180 | |||
| 181 | $label = $this->uiFactory->createLabel("Order", uiLabel::TYPE_HEADER); |
||
| 182 | $label->setPosition($x, 0); |
||
| 183 | $manialink->addChild($label); |
||
| 184 | |||
| 185 | $x += 32; |
||
| 186 | $this->opbox = $this->uiFactory->createDropdown("operator", $this->operator, 0); |
||
| 187 | $this->opbox->setPosition($x, -6, 2); |
||
| 188 | $manialink->addChild($this->opbox); |
||
| 189 | |||
| 190 | $label = $this->uiFactory->createLabel("Operator", uiLabel::TYPE_HEADER); |
||
| 191 | $label->setPosition($x, 0); |
||
| 192 | $manialink->addChild($label); |
||
| 193 | |||
| 194 | $x += 32; |
||
| 195 | $this->lengthBox = $this->uiFactory->createDropdown("length", $this->length, 0); |
||
| 196 | $this->lengthBox->setPosition($x, -6, 2); |
||
| 197 | $manialink->addChild($this->lengthBox); |
||
| 198 | |||
| 199 | $label = $this->uiFactory->createLabel("Length", uiLabel::TYPE_HEADER); |
||
| 200 | $label->setPosition($x, 0); |
||
| 201 | $manialink->addChild($label); |
||
| 202 | |||
| 203 | $x += 32; |
||
| 204 | $this->stylebox = $this->uiFactory->createDropdown("style", $this->map_styles_tm, 0); |
||
| 205 | $this->stylebox->setPosition($x, -6, 2); |
||
| 206 | $manialink->addChild($this->stylebox); |
||
| 207 | |||
| 208 | $label = $this->uiFactory->createLabel("Style", uiLabel::TYPE_HEADER); |
||
| 209 | $label->setPosition($x, 0); |
||
| 210 | $manialink->addChild($label); |
||
| 211 | |||
| 212 | $x += 32; |
||
| 213 | $this->difficultiesBox = $this->uiFactory->createDropdown("difficulties", $this->difficulties, 0); |
||
| 214 | $this->difficultiesBox->setPosition($x, -6, 2); |
||
| 215 | $manialink->addChild($this->difficultiesBox); |
||
| 216 | |||
| 217 | $label = $this->uiFactory->createLabel("Difficulty", uiLabel::TYPE_HEADER); |
||
| 218 | $label->setPosition($x, 0); |
||
| 219 | $manialink->addChild($label); |
||
| 220 | |||
| 221 | /// second line |
||
| 222 | |||
| 223 | $this->sitebox = $this->uiFactory->createDropdown("site", ["Trackmania" => "tm", "Storm" => "sm"], 0); |
||
| 224 | $this->sitebox->setPosition(0, -14, 2); |
||
| 225 | $manialink->addChild($this->sitebox); |
||
| 226 | |||
| 227 | $this->tpackBox = $this->uiFactory->createDropdown("tpack", $this->tpack, 0); |
||
| 228 | $this->tpackBox->setPosition(32, -14, 2); |
||
| 229 | $manialink->addChild($this->tpackBox); |
||
| 230 | |||
| 231 | $mapname = $this->uiFactory->createInput("map"); |
||
| 232 | $mapname->setHeight(6); |
||
| 233 | $author = $this->uiFactory->createInput("author"); |
||
| 234 | $author->setHeight(6); |
||
| 235 | |||
| 236 | $search = $this->uiFactory->createButton('🔍 Search', uiButton::TYPE_DECORATED); |
||
| 237 | $search->setAction($this->actionFactory->createManialinkAction($manialink, [$this, 'callbackSearch'], null)); |
||
|
|
|||
| 238 | $search->setHeight(6); |
||
| 239 | |||
| 240 | $line = $this->uiFactory->createLayoutLine(64, -14, [$mapname, $author, $search], 2); |
||
| 241 | $manialink->addChild($line); |
||
| 242 | |||
| 243 | $addButton = $this->uiFactory->createButton('Install', uiButton::TYPE_DEFAULT); |
||
| 244 | $addButton->setSize(20, 5); |
||
| 245 | |||
| 246 | $gridBuilder = $this->gridBuilderFactory->create(); |
||
| 247 | $gridBuilder->setManialink($manialink) |
||
| 248 | ->setDataCollection($collection) |
||
| 249 | ->setManialinkFactory($this) |
||
| 250 | ->addTextColumn( |
||
| 251 | 'index', |
||
| 252 | 'expansion_mx.gui.mxsearch.column.index', |
||
| 253 | 1, |
||
| 254 | true, |
||
| 255 | false |
||
| 256 | )->addTextColumn( |
||
| 257 | 'name', |
||
| 258 | 'expansion_mx.gui.mxsearch.column.name', |
||
| 259 | 5, |
||
| 260 | true, |
||
| 261 | false |
||
| 262 | )->addTextColumn( |
||
| 263 | 'author', |
||
| 264 | 'expansion_mx.gui.mxsearch.column.author', |
||
| 265 | 3, |
||
| 266 | false |
||
| 267 | )->addTextColumn( |
||
| 268 | 'envir', |
||
| 269 | 'expansion_mx.gui.mxsearch.column.envir', |
||
| 270 | 2, |
||
| 271 | true, |
||
| 272 | false |
||
| 273 | )->addTextColumn( |
||
| 274 | 'awards', |
||
| 275 | 'expansion_mx.gui.mxsearch.column.awards', |
||
| 276 | 1, |
||
| 277 | true, |
||
| 278 | false |
||
| 279 | )->addTextColumn( |
||
| 280 | 'length', |
||
| 281 | 'expansion_mx.gui.mxsearch.column.length', |
||
| 282 | 2, |
||
| 283 | true, |
||
| 284 | false |
||
| 285 | )->addTextColumn( |
||
| 286 | 'style', |
||
| 287 | 'expansion_mx.gui.mxsearch.column.style', |
||
| 288 | 2, |
||
| 289 | true, |
||
| 290 | false |
||
| 291 | ) |
||
| 292 | ->addActionColumn('add', 'expansion_mx.gui.mxsearch.column.add', 2, array($this, 'callbackAdd'), |
||
| 293 | $addButton); |
||
| 294 | $this->setGridPosition(0, -24); |
||
| 295 | |||
| 296 | $content = $manialink->getContentFrame(); |
||
| 297 | $this->setGridSize($content->getWidth(), $content->getHeight() - 24); |
||
| 298 | $manialink->setData('grid', $gridBuilder); |
||
| 299 | |||
| 300 | } |
||
| 301 | |||
| 384 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: