| Conditions | 12 |
| Paths | 12 |
| Total Lines | 49 |
| Code Lines | 37 |
| 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 |
||
| 112 | case RecordTypeEnum::TYPE_CNAME: |
||
| 113 | case RecordTypeEnum::TYPE_PTR: |
||
| 114 | return self::decodeDomainName($rdata); |
||
| 115 | case RecordTypeEnum::TYPE_SOA: |
||
| 116 | $offset = 0; |
||
| 117 | |||
| 118 | return array_merge( |
||
| 119 | [ |
||
| 120 | 'mname' => self::decodeDomainName($rdata, $offset), |
||
| 121 | 'rname' => self::decodeDomainName($rdata, $offset), |
||
| 122 | ], |
||
| 123 | unpack('Nserial/Nrefresh/Nretry/Nexpire/Nminimum', substr($rdata, $offset)) |
||
| 124 | ); |
||
| 125 | case RecordTypeEnum::TYPE_MX: |
||
| 126 | return [ |
||
| 127 | 'preference' => unpack('npreference', $rdata)['preference'], |
||
| 128 | 'exchange' => self::decodeDomainName(substr($rdata, 2)), |
||
| 129 | ]; |
||
| 130 | case RecordTypeEnum::TYPE_TXT: |
||
| 131 | $len = ord($rdata[0]); |
||
| 132 | if ((strlen($rdata) + 1) < $len) { |
||
| 133 | return null; |
||
| 134 | } |
||
| 135 | |||
| 136 | return substr($rdata, 1, $len); |
||
| 137 | case RecordTypeEnum::TYPE_SRV: |
||
| 138 | $offset = 6; |
||
| 139 | $values = unpack('npriority/nweight/nport', $rdata); |
||
| 140 | $values['target'] = self::decodeDomainName($rdata, $offset); |
||
| 141 | |||
| 142 | return $values; |
||
| 143 | case RecordTypeEnum::TYPE_AXFR: |
||
| 144 | case RecordTypeEnum::TYPE_ANY: |
||
| 145 | return null; |
||
| 146 | default: |
||
| 147 | throw new UnsupportedTypeException( |
||
| 148 | sprintf('Record type "%s" is not a supported type.', RecordTypeEnum::getName($type)) |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param string $pkt |
||
| 155 | * @param int $offset |
||
| 156 | * |
||
| 157 | * @return Header |
||
| 158 | */ |
||
| 159 | public static function decodeHeader(string $pkt, int &$offset = 0): Header |
||
| 160 | { |
||
| 161 | $data = unpack('nid/nflags/nqdcount/nancount/nnscount/narcount', $pkt); |
||
| 200 |