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 |
||
118 | public function testGetStatsd() |
||
119 | { |
||
120 | $command = $this->getMockBuilder('Petrica\StatsdSystem\Command\NotifyCommand') |
||
121 | ->disableOriginalConstructor() |
||
122 | ->getMock(); |
||
123 | |||
124 | $input = $this->getInputInterface(); |
||
125 | |||
126 | $map = array( |
||
127 | [ 'statsd-host', 'localhost' ], |
||
128 | [ 'statsd-port', '8125' ], |
||
129 | [ 'statsd-namespace', 'test' ] |
||
130 | ); |
||
131 | |||
132 | $input->expects($this->atLeastOnce()) |
||
133 | ->method('getOption') |
||
134 | ->will($this->returnValueMap($map)); |
||
135 | |||
136 | $class = new \ReflectionClass('Petrica\StatsdSystem\Command\NotifyCommand'); |
||
137 | $getStatsd = $class->getMethod('getStatsd'); |
||
138 | $getStatsd->setAccessible(true); |
||
139 | |||
140 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
141 | |||
142 | $connection = new UdpSocket('localhost', 8125); |
||
143 | $expects = new Client($connection, 'test'); |
||
144 | |||
145 | $this->assertEquals($expects, $statsd); |
||
146 | |||
147 | // Not equal host |
||
148 | $connection = new UdpSocket('localhost1', 8125); |
||
149 | $expects = new Client($connection, 'test'); |
||
150 | |||
151 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
152 | |||
153 | $this->assertNotEquals($expects, $statsd); |
||
154 | |||
155 | // Not equal port |
||
156 | $connection = new UdpSocket('localhost', 8126); |
||
157 | $expects = new Client($connection, 'test'); |
||
158 | |||
159 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
160 | |||
161 | $this->assertNotEquals($expects, $statsd); |
||
162 | |||
163 | // Not equal namespace |
||
164 | $connection = new UdpSocket('localhost', 8125); |
||
165 | $expects = new Client($connection, 'test1'); |
||
166 | |||
167 | $statsd = $getStatsd->invokeArgs($command, array($input)); |
||
168 | |||
169 | $this->assertNotEquals($expects, $statsd); |
||
170 | } |
||
171 | |||
187 | } |