| Conditions | 10 |
| Paths | 7 |
| Total Lines | 35 |
| 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 namespace XoopsModules\Smartobject; |
||
| 87 | public function render($filename) |
||
| 88 | { |
||
| 89 | $this->filename = $filename; |
||
| 90 | |||
| 91 | $objects = $this->handler->getObjects($this->criteria); |
||
| 92 | $rows = []; |
||
| 93 | $columnsHeaders = []; |
||
| 94 | $firstObject = true; |
||
| 95 | foreach ($objects as $object) { |
||
| 96 | $row = []; |
||
| 97 | foreach ($object->vars as $key => $var) { |
||
| 98 | if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
||
| 99 | if ($this->outputMethods && isset($this->outputMethods[$key]) |
||
| 100 | && method_exists($object, $this->outputMethods[$key])) { |
||
| 101 | $method = $this->outputMethods[$key]; |
||
| 102 | $row[$key] = $object->$method(); |
||
| 103 | } else { |
||
| 104 | $row[$key] = $object->getVar($key); |
||
| 105 | } |
||
| 106 | if ($firstObject) { |
||
| 107 | // then set the columnsHeaders array as well |
||
| 108 | $columnsHeaders[$key] = $var['form_caption']; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | $firstObject = false; |
||
| 113 | $rows[] = $row; |
||
| 114 | unset($row); |
||
| 115 | } |
||
| 116 | $data = []; |
||
| 117 | $data['rows'] = $rows; |
||
| 118 | $data['columnsHeaders'] = $columnsHeaders; |
||
| 119 | $smartExportRenderer = new ExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
||
| 120 | $smartExportRenderer->execute(); |
||
| 121 | } |
||
| 122 | |||
| 157 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.