Conditions | 15 |
Paths | 19 |
Total Lines | 52 |
Code Lines | 44 |
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 |
||
52 | return $res; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param int $type |
||
57 | * @param string|array $rdata |
||
58 | * |
||
59 | * @return string |
||
60 | * |
||
61 | * @throws UnsupportedTypeException|\InvalidArgumentException |
||
62 | */ |
||
63 | public static function encodeRdata(int $type, $rdata): string |
||
64 | { |
||
65 | switch ($type) { |
||
66 | case RecordTypeEnum::TYPE_A: |
||
67 | case RecordTypeEnum::TYPE_AAAA: |
||
68 | if (!filter_var($rdata, FILTER_VALIDATE_IP)) { |
||
69 | throw new \InvalidArgumentException(sprintf('The IP address "%s" is invalid.', $rdata)); |
||
|
|||
70 | } |
||
71 | |||
72 | return inet_pton($rdata); |
||
73 | case RecordTypeEnum::TYPE_NS: |
||
74 | case RecordTypeEnum::TYPE_CNAME: |
||
75 | case RecordTypeEnum::TYPE_PTR: |
||
76 | return self::encodeDomainName($rdata); |
||
77 | case RecordTypeEnum::TYPE_SOA: |
||
78 | return self::encodeSOA($rdata); |
||
79 | case RecordTypeEnum::TYPE_MX: |
||
80 | return pack('n', (int) $rdata['preference']).self::encodeDomainName($rdata['exchange']); |
||
81 | case RecordTypeEnum::TYPE_TXT: |
||
82 | $rdata = substr($rdata, 0, 255); |
||
83 | |||
84 | return chr(strlen($rdata)).$rdata; |
||
85 | case RecordTypeEnum::TYPE_SRV: |
||
86 | return pack('nnn', (int) $rdata['priority'], (int) $rdata['weight'], (int) $rdata['port']). |
||
87 | self::encodeDomainName($rdata['target']); |
||
88 | case RecordTypeEnum::TYPE_AXFR: |
||
89 | case RecordTypeEnum::TYPE_ANY: |
||
90 | return ''; |
||
91 | default: |
||
92 | throw new UnsupportedTypeException( |
||
93 | sprintf('Record type "%s" is not a supported type.', RecordTypeEnum::getName($type)) |
||
94 | ); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param ResourceRecord[] $resourceRecords |
||
100 | * |
||
101 | * @return string |
||
102 | * |
||
103 | * @throws UnsupportedTypeException |
||
104 | */ |
||
182 |