| 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 |
||
| 44 | public static function getRecords(string $datatype) |
||
| 45 | { |
||
| 46 | $records = []; |
||
| 47 | switch ($datatype) { |
||
| 48 | case 'assetTransforms': |
||
| 49 | $records = Craft::$app->assetTransforms->getAllTransforms(); |
||
| 50 | break; |
||
| 51 | case 'categoryGroups': |
||
| 52 | $records = Craft::$app->categories->getAllGroups(); |
||
| 53 | break; |
||
| 54 | case 'fields': |
||
| 55 | $records = Craft::$app->fields->getAllFields(); |
||
| 56 | break; |
||
| 57 | case 'globalSets': |
||
| 58 | $records = Craft::$app->globals->getAllSets(); |
||
| 59 | break; |
||
| 60 | case 'sections': |
||
| 61 | $records = Craft::$app->sections->getAllSections(); |
||
| 62 | break; |
||
| 63 | case 'sites': |
||
| 64 | $records = Craft::$app->sites->getAllSites(); |
||
| 65 | break; |
||
| 66 | case 'userGroups': |
||
| 67 | $records = Craft::$app->userGroups->getAllGroups(); |
||
| 68 | break; |
||
| 69 | case 'volumes': |
||
| 70 | $records = Craft::$app->volumes->getAllVolumes(); |
||
| 71 | break; |
||
| 72 | case 'tagGroups': |
||
| 73 | $records = Craft::$app->tags->getAllTagGroups(); |
||
| 74 | break; |
||
| 75 | } |
||
| 76 | |||
| 77 | return $records; |
||
| 78 | } |
||
| 79 | |||
| 120 |