Conditions | 4 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 29 |
Lines | 0 |
Ratio | 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 |
||
72 | private function doQuery($nameServer, $transport, $queryData, $name) : PromiseInterface |
||
73 | { |
||
74 | $response = new Message(); |
||
75 | $deferred = new Deferred(); |
||
76 | |||
77 | $retryWithTcp = function () use ($nameServer, $queryData, $name) { |
||
78 | return $this->doQuery($nameServer, 'tcp', $queryData, $name); |
||
79 | }; |
||
80 | |||
81 | $connection = $this->createConnection($nameServer, $transport); |
||
82 | |||
83 | $timer = $this->loop->addTimer($this->timeout, function () use ($connection, $name, $deferred) { |
||
84 | $connection->close(); |
||
85 | |||
86 | $deferred->reject(new TimeoutException($name)); |
||
87 | }); |
||
88 | |||
89 | |||
90 | $connection->on( |
||
91 | 'data', |
||
92 | function ($data) use ($retryWithTcp, $connection, &$response, $transport, $deferred, $timer) { |
||
93 | $responseReady = $this->parser->parseChunk($data, $response); |
||
94 | |||
95 | if (!$responseReady) { |
||
96 | return; |
||
97 | } |
||
98 | |||
99 | $timer->cancel(); |
||
100 | |||
101 | if ($response->header->isTruncated()) { |
||
102 | if ('tcp' === $transport) { |
||
103 | $deferred->reject( |
||
104 | new BadServerException( |
||
105 | 'The server set the truncated bit although we issued a TCP request' |
||
106 | ) |
||
107 | ); |
||
108 | } else { |
||
109 | $connection->end(); |
||
110 | $deferred->resolve($retryWithTcp()); |
||
111 | } |
||
112 | |||
113 | return; |
||
114 | } |
||
115 | |||
116 | $connection->end(); |
||
117 | $deferred->resolve($response); |
||
118 | } |
||
119 | ); |
||
120 | |||
121 | $connection->write($queryData); |
||
122 | |||
123 | return $deferred->promise(); |
||
124 | } |
||
125 | |||
159 |