| Conditions | 10 |
| Paths | 10 |
| Total Lines | 35 |
| Code Lines | 31 |
| 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 |
||
| 53 | public static function getRecords(string $datatype) |
||
| 54 | { |
||
| 55 | $records = []; |
||
| 56 | switch ($datatype) { |
||
| 57 | case 'assetTransforms': |
||
| 58 | $records = Craft::$app->assetTransforms->getAllTransforms(); |
||
| 59 | break; |
||
| 60 | case 'categoryGroups': |
||
| 61 | $records = Craft::$app->categories->getAllGroups(); |
||
| 62 | break; |
||
| 63 | case 'fields': |
||
| 64 | $records = Craft::$app->fields->getAllFields(); |
||
| 65 | break; |
||
| 66 | case 'globalSets': |
||
| 67 | $records = Craft::$app->globals->getAllSets(); |
||
| 68 | break; |
||
| 69 | case 'sections': |
||
| 70 | $records = Craft::$app->sections->getAllSections(); |
||
| 71 | break; |
||
| 72 | case 'sites': |
||
| 73 | $records = Craft::$app->sites->getAllSites(); |
||
| 74 | break; |
||
| 75 | case 'userGroups': |
||
| 76 | $records = Craft::$app->userGroups->getAllGroups(); |
||
| 77 | break; |
||
| 78 | case 'volumes': |
||
| 79 | $records = Craft::$app->volumes->getAllVolumes(); |
||
| 80 | break; |
||
| 81 | case 'tagGroups': |
||
| 82 | $records = Craft::$app->tags->getAllTagGroups(); |
||
| 83 | break; |
||
| 84 | } |
||
| 85 | |||
| 86 | return $records; |
||
| 87 | } |
||
| 88 | |||
| 145 |