| Conditions | 16 |
| Paths | 3074 |
| Total Lines | 61 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 68 | public function create($type) |
||
| 69 | { |
||
| 70 | $twig = $this->getTwigEnvironment(); |
||
| 71 | if (!$twig) { |
||
| 72 | throw new \Exception('Twig Engine not found. Please see https://github.com/mmucklo/DtcGridBundle/README.md for instructions.'); |
||
| 73 | } |
||
| 74 | switch ($type) { |
||
| 75 | case 'datatables': |
||
| 76 | $renderer = new DataTablesRenderer($this->twig, $this->router, $this->translator, $this->dataTablesOptions); |
||
| 77 | break; |
||
| 78 | case 'jq_grid': |
||
| 79 | $renderer = new JQGridRenderer($this->twig, $this->router, $this->translator, $this->jqGridOptions); |
||
| 80 | break; |
||
| 81 | case 'table': |
||
| 82 | $renderer = new TableGridRenderer($this->twig, $this->router, $this->translator, $this->tableOptions); |
||
| 83 | break; |
||
| 84 | default: |
||
| 85 | throw new \Exception("No renderer for type '$type''"); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (method_exists($renderer, 'setThemeCss')) { |
||
| 89 | $renderer->setThemeCss($this->themeCss); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (method_exists($renderer, 'setThemeJs')) { |
||
| 93 | $renderer->setThemeJs($this->themeJs); |
||
| 94 | } |
||
| 95 | |||
| 96 | if (method_exists($renderer, 'setJQuery')) { |
||
| 97 | $renderer->setJQuery($this->jQuery); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (method_exists($renderer, 'setPurl')) { |
||
| 101 | $renderer->setPurl($this->purl); |
||
| 102 | } |
||
| 103 | |||
| 104 | if (method_exists($renderer, 'setPageDivStyle')) { |
||
| 105 | $renderer->setPageDivStyle($this->pageDivStyle); |
||
| 106 | } |
||
| 107 | |||
| 108 | if (method_exists($renderer, 'setJqGridCss')) { |
||
| 109 | $renderer->setJqGridCss($this->jqGridCss); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (method_exists($renderer, 'setJqGridJs')) { |
||
| 113 | $renderer->setJqGridJs($this->jqGridJs); |
||
| 114 | } |
||
| 115 | |||
| 116 | if (method_exists($renderer, 'setDataTablesCss')) { |
||
| 117 | $renderer->setDataTablesCss($this->dataTablesCss); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (method_exists($renderer, 'setDataTablesJs')) { |
||
| 121 | $renderer->setDataTablesJs($this->dataTablesJs); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (method_exists($renderer, 'setDatatablesClass') && $this->dataTablesClass) { |
||
| 125 | $renderer->setDatatablesClass($this->dataTablesClass); |
||
| 126 | } |
||
| 127 | |||
| 128 | return $renderer; |
||
| 129 | } |
||
| 131 |