| Conditions | 16 | 
| Total Lines | 64 | 
| Code Lines | 41 | 
| 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:
Complex classes like kms.newKeyMetadata often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | package kms | ||
| 34 | func newKeyMetadata(o *SDK.KeyMetadata) KeyMetadata { | ||
| 35 | 	result := KeyMetadata{} | ||
| 36 | 	if o == nil { | ||
| 37 | return result | ||
| 38 | } | ||
| 39 | |||
| 40 | 	if o.KeyId != nil { | ||
| 41 | result.KeyID = *o.KeyId | ||
| 42 | } | ||
| 43 | |||
| 44 | 	if o.AWSAccountId != nil { | ||
| 45 | result.AWSAccountID = *o.AWSAccountId | ||
| 46 | } | ||
| 47 | 	if o.Arn != nil { | ||
| 48 | result.ARN = *o.Arn | ||
| 49 | } | ||
| 50 | 	if o.CloudHsmClusterId != nil { | ||
| 51 | result.CloudHsmClusterID = *o.CloudHsmClusterId | ||
| 52 | } | ||
| 53 | 	if o.CreationDate != nil { | ||
| 54 | result.CreationDate = *o.CreationDate | ||
| 55 | } | ||
| 56 | 	if o.CustomKeyStoreId != nil { | ||
| 57 | result.CustomKeyStoreID = *o.CustomKeyStoreId | ||
| 58 | } | ||
| 59 | |||
| 60 | o.CustomerMasterKeySpec = SDK.CustomerMasterKeySpec(result.CustomerMasterKeySpec) | ||
| 61 | |||
| 62 | 	if o.DeletionDate != nil { | ||
| 63 | result.DeletionDate = *o.DeletionDate | ||
| 64 | } | ||
| 65 | 	if o.Description != nil { | ||
| 66 | result.Description = *o.Description | ||
| 67 | } | ||
| 68 | 	if o.Enabled != nil { | ||
| 69 | result.Enabled = *o.Enabled | ||
| 70 | } | ||
| 71 | |||
| 72 | 	if len(o.EncryptionAlgorithms) != 0 { | ||
| 73 | list := make([]EncryptionAlgorithmSpec, len(o.EncryptionAlgorithms)) | ||
| 74 | 		for i, v := range o.EncryptionAlgorithms { | ||
| 75 | list[i] = EncryptionAlgorithmSpec(v) | ||
| 76 | } | ||
| 77 | result.EncryptionAlgorithms = list | ||
| 78 | } | ||
| 79 | |||
| 80 | o.ExpirationModel = SDK.ExpirationModelType(result.ExpirationModel) | ||
| 81 | o.KeyManager = SDK.KeyManagerType(result.KeyManager) | ||
| 82 | o.KeyState = SDK.KeyState(result.KeyState) | ||
| 83 | o.KeyUsage = SDK.KeyUsageType(result.KeyUsage) | ||
| 84 | o.Origin = SDK.OriginType(result.Origin) | ||
| 85 | |||
| 86 | 	if len(o.SigningAlgorithms) != 0 { | ||
| 87 | list := make([]SigningAlgorithmSpec, len(o.SigningAlgorithms)) | ||
| 88 | 		for i, v := range o.SigningAlgorithms { | ||
| 89 | list[i] = SigningAlgorithmSpec(v) | ||
| 90 | } | ||
| 91 | result.SigningAlgorithms = list | ||
| 92 | } | ||
| 93 | |||
| 94 | 	if o.ValidTo != nil { | ||
| 95 | result.ValidTo = *o.ValidTo | ||
| 96 | } | ||
| 97 | return result | ||
| 98 | } | ||
| 111 |