Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
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 |
||
136 | public function testGetStatsd() |
||
137 | { |
||
138 | $command = $this->getMockBuilder('Petrica\StatsdSystem\Command\NotifyCommand') |
||
139 | ->disableOriginalConstructor() |
||
140 | ->getMock(); |
||
141 | |||
142 | $input = $this->getInputInterface(); |
||
143 | |||
144 | $map = array( |
||
145 | [ 'statsd-host', 'localhost' ], |
||
146 | [ 'statsd-port', '8125' ], |
||
147 | [ 'statsd-namespace', 'test' ] |
||
148 | ); |
||
149 | |||
150 | $input->expects($this->atLeastOnce()) |
||
151 | ->method('getOption') |
||
152 | ->will($this->returnValueMap($map)); |
||
153 | |||
154 | $class = new \ReflectionClass('Petrica\StatsdSystem\Command\NotifyCommand'); |
||
155 | $getStatsd = $class->getMethod('getStatsd'); |
||
156 | $getStatsd->setAccessible(true); |
||
157 | |||
158 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
159 | |||
160 | $connection = new UdpSocket('localhost', 8125); |
||
161 | $expects = new Client($connection, 'test'); |
||
162 | |||
163 | $this->assertEquals($expects, $statsd); |
||
164 | |||
165 | // Not equal host |
||
166 | $connection = new UdpSocket('localhost1', 8125); |
||
167 | $expects = new Client($connection, 'test'); |
||
168 | |||
169 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
170 | |||
171 | $this->assertNotEquals($expects, $statsd); |
||
172 | |||
173 | // Not equal port |
||
174 | $connection = new UdpSocket('localhost', 8126); |
||
175 | $expects = new Client($connection, 'test'); |
||
176 | |||
177 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
178 | |||
179 | $this->assertNotEquals($expects, $statsd); |
||
180 | |||
181 | // Not equal namespace |
||
182 | $connection = new UdpSocket('localhost', 8125); |
||
183 | $expects = new Client($connection, 'test1'); |
||
184 | |||
185 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
186 | |||
187 | $this->assertNotEquals($expects, $statsd); |
||
188 | } |
||
189 | |||
205 | } |