| Conditions | 11 |
| Paths | 6 |
| Total Lines | 38 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 66 | private function dnsResolve(string $target, int $recursionCount) : array { |
||
| 67 | if ($recursionCount >= 10) { |
||
| 68 | return []; |
||
| 69 | } |
||
| 70 | |||
| 71 | $recursionCount = $recursionCount++; |
||
| 72 | $targetIps = []; |
||
| 73 | |||
| 74 | $soaDnsEntry = $this->soaRecord($target); |
||
| 75 | $dnsNegativeTtl = $soaDnsEntry['minimum-ttl'] ?? null; |
||
| 76 | |||
| 77 | $dnsTypes = [DNS_A, DNS_AAAA, DNS_CNAME]; |
||
| 78 | foreach ($dnsTypes as $dnsType) { |
||
| 79 | if ($this->negativeDnsCache->isNegativeCached($target, $dnsType)) { |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | |||
| 83 | $dnsResponses = dns_get_record($target, $dnsType); |
||
| 84 | $canHaveCnameRecord = true; |
||
| 85 | if (count($dnsResponses) > 0) { |
||
| 86 | foreach ($dnsResponses as $dnsResponse) { |
||
| 87 | if (isset($dnsResponse['ip'])) { |
||
| 88 | $targetIps[] = $dnsResponse['ip']; |
||
| 89 | $canHaveCnameRecord = false; |
||
| 90 | } elseif (isset($dnsResponse['ipv6'])) { |
||
| 91 | $targetIps[] = $dnsResponse['ipv6']; |
||
| 92 | $canHaveCnameRecord = false; |
||
| 93 | } elseif (isset($dnsResponse['target']) && $canHaveCnameRecord) { |
||
| 94 | $targetIps = array_merge($targetIps, $this->dnsResolve($dnsResponse['target'], $recursionCount)); |
||
| 95 | $canHaveCnameRecord = true; |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } elseif ($dnsNegativeTtl !== null) { |
||
| 99 | $this->negativeDnsCache->setNegativeCacheForDnsType($target, $dnsType, $dnsNegativeTtl); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | return $targetIps; |
||
| 104 | } |
||
| 151 |