Conditions | 10 |
Paths | 10 |
Total Lines | 40 |
Code Lines | 34 |
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 |
||
95 | protected function extractPhpRdata(array $resourceRecord) |
||
96 | { |
||
97 | $type = RecordTypeEnum::getTypeIndex($resourceRecord['type']); |
||
98 | |||
99 | switch ($type) { |
||
100 | case RecordTypeEnum::TYPE_A: |
||
101 | return $resourceRecord['ip']; |
||
102 | case RecordTypeEnum::TYPE_AAAA: |
||
103 | return $resourceRecord['ipv6']; |
||
104 | case RecordTypeEnum::TYPE_NS: |
||
105 | case RecordTypeEnum::TYPE_CNAME: |
||
106 | case RecordTypeEnum::TYPE_PTR: |
||
107 | return $resourceRecord['target']; |
||
108 | case RecordTypeEnum::TYPE_SOA: |
||
109 | return [ |
||
110 | 'mname' => $resourceRecord['mname'], |
||
111 | 'rname' => $resourceRecord['rname'], |
||
112 | 'serial' => $resourceRecord['serial'], |
||
113 | 'refresh' => $resourceRecord['refresh'], |
||
114 | 'retry' => $resourceRecord['retry'], |
||
115 | 'expire' => $resourceRecord['expire'], |
||
116 | 'minimum' => $resourceRecord['minimum-ttl'], |
||
117 | ]; |
||
118 | case RecordTypeEnum::TYPE_MX: |
||
119 | return [ |
||
120 | 'preference' => $resourceRecord['pri'], |
||
121 | 'exchange' => $resourceRecord['host'], |
||
122 | ]; |
||
123 | case RecordTypeEnum::TYPE_TXT: |
||
124 | return $resourceRecord['txt']; |
||
125 | case RecordTypeEnum::TYPE_SRV: |
||
126 | return [ |
||
127 | 'priority' => $resourceRecord['pri'], |
||
128 | 'port' => $resourceRecord['port'], |
||
129 | 'weight' => $resourceRecord['weight'], |
||
130 | 'target' => $resourceRecord['target'], |
||
131 | ]; |
||
132 | default: |
||
133 | throw new UnsupportedTypeException( |
||
134 | sprintf('Record type "%s" is not a supported type.', RecordTypeEnum::getName($type)) |
||
135 | ); |
||
155 |