| Conditions | 6 |
| Paths | 10 |
| Total Lines | 57 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 142 | public function getFieldInstanceByName($name) |
||
| 143 | { |
||
| 144 | $params = []; |
||
| 145 | switch ($name) { |
||
| 146 | case 'name': |
||
| 147 | $params = [ |
||
| 148 | 'name' => $name, |
||
| 149 | 'label' => 'FL_NAME', |
||
| 150 | 'uitype' => 1, |
||
| 151 | 'typeofdata' => 'V~M', |
||
| 152 | 'maximumlength' => '50', |
||
| 153 | 'purifyType' => \App\Purifier::TEXT, |
||
| 154 | 'blockLabel' => 'BL_BASE', |
||
| 155 | 'table' => $this->getBaseTable() |
||
| 156 | ]; |
||
| 157 | break; |
||
| 158 | case 'status': |
||
| 159 | $params = [ |
||
| 160 | 'name' => $name, |
||
| 161 | 'label' => 'FL_ACTIVE', |
||
| 162 | 'uitype' => 56, |
||
| 163 | 'typeofdata' => 'C~O', |
||
| 164 | 'maximumlength' => '1', |
||
| 165 | 'purifyType' => \App\Purifier::BOOL, |
||
| 166 | 'blockLabel' => 'BL_BASE', |
||
| 167 | 'table' => $this->getBaseTable() |
||
| 168 | ]; |
||
| 169 | break; |
||
| 170 | case 'default': |
||
| 171 | $params = [ |
||
| 172 | 'name' => $name, |
||
| 173 | 'label' => 'FL_DEFAULT', |
||
| 174 | 'uitype' => 56, |
||
| 175 | 'typeofdata' => 'C~O', |
||
| 176 | 'maximumlength' => '1', |
||
| 177 | 'purifyType' => \App\Purifier::BOOL, |
||
| 178 | 'blockLabel' => 'BL_BASE', |
||
| 179 | 'table' => $this->getBaseTable() |
||
| 180 | ]; |
||
| 181 | break; |
||
| 182 | case 'body': |
||
| 183 | $params = [ |
||
| 184 | 'name' => $name, |
||
| 185 | 'label' => 'FL_BODY', |
||
| 186 | 'uitype' => 300, |
||
| 187 | 'typeofdata' => 'V~M', |
||
| 188 | 'maximumlength' => 16777215, |
||
| 189 | 'purifyType' => \App\Purifier::HTML, |
||
| 190 | 'blockLabel' => 'FL_BODY', |
||
| 191 | 'col-md' => 'col-md-12', |
||
| 192 | 'table' => $this->getBaseTable() |
||
| 193 | ]; |
||
| 194 | break; |
||
| 195 | default: |
||
| 196 | break; |
||
| 197 | } |
||
| 198 | return $params ? \Vtiger_Field_Model::init($this->getName(true), $params, $name) : null; |
||
| 199 | } |
||
| 201 |