Conditions | 13 |
Paths | 11 |
Total Lines | 45 |
Code Lines | 31 |
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 |
||
45 | private function dnsResolve(string $target, int $recursionCount) : array { |
||
46 | if ($recursionCount >= 10) { |
||
47 | return []; |
||
48 | } |
||
49 | |||
50 | $recursionCount = $recursionCount++; |
||
51 | $targetIps = []; |
||
52 | |||
53 | $soaDnsEntry = dns_get_record($target, DNS_SOA); |
||
54 | if (isset($soaDnsEntry[0]) && isset($soaDnsEntry[0]['minimum-ttl'])) { |
||
55 | $dnsNegativeTtl = $soaDnsEntry[0]['minimum-ttl']; |
||
56 | } else { |
||
57 | $dnsNegativeTtl = null; |
||
58 | } |
||
59 | |||
60 | $dnsTypes = [DNS_A, DNS_AAAA, DNS_CNAME]; |
||
61 | foreach ($dnsTypes as $key => $dnsType) { |
||
62 | if ($this->negativeDnsCache->isNegativeCached($target, $dnsType)) { |
||
63 | unset($dnsTypes[$key]); |
||
64 | continue; |
||
65 | } |
||
66 | |||
67 | $dnsResponses = dns_get_record($target, $dnsType); |
||
68 | $canHaveCnameRecord = true; |
||
69 | if (count($dnsResponses) > 0) { |
||
70 | foreach ($dnsResponses as $key => $dnsResponse) { |
||
|
|||
71 | if (isset($dnsResponse['ip'])) { |
||
72 | $targetIps[] = $dnsResponse['ip']; |
||
73 | $canHaveCnameRecord = false; |
||
74 | } elseif (isset($dnsResponse['ipv6'])) { |
||
75 | $targetIps[] = $dnsResponse['ipv6']; |
||
76 | $canHaveCnameRecord = false; |
||
77 | } elseif (isset($dnsResponse['target']) && $canHaveCnameRecord) { |
||
78 | $targetIps = array_merge($targetIps, $this->dnsResolve($dnsResponse['target'], $recursionCount)); |
||
79 | $canHaveCnameRecord = true; |
||
80 | } |
||
81 | } |
||
82 | } else { |
||
83 | if ($dnsNegativeTtl !== null) { |
||
84 | $this->negativeDnsCache->setNegativeCacheForDnsType($target, $dnsType, $dnsNegativeTtl); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | return $targetIps; |
||
90 | } |
||
130 |