Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 25 | class TimeServerTest extends PHPUnit_Framework_TestCase |
||
| 26 | { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var TimeServer |
||
| 30 | */ |
||
| 31 | private $exercise; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var TcpSocketFactory |
||
| 35 | */ |
||
| 36 | private $socketFactory; |
||
| 37 | |||
| 38 | public function setUp() |
||
| 43 | |||
| 44 | public function testGetters() |
||
| 53 | |||
| 54 | public function testFailureIsReturnedIfCannotConnect() |
||
| 55 | { |
||
| 56 | $this->socketFactory |
||
|
|
|||
| 57 | ->expects($this->once()) |
||
| 58 | ->method('createClient') |
||
| 59 | ->with('127.0.0.1', $this->logicalAnd( |
||
| 60 | $this->greaterThan(1024), |
||
| 61 | $this->lessThan(655356) |
||
| 62 | )) |
||
| 63 | ->will($this->returnValue(new Client('tcp://127.0.0.1:655355'))); |
||
| 64 | |||
| 65 | $failure = $this->exercise->check('program.php'); |
||
| 66 | |||
| 67 | $this->assertInstanceOf(Failure::class, $failure); |
||
| 68 | |||
| 69 | |||
| 70 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
||
| 71 | $reason = '/^Client returns an error \(number \d+\): No connection could be made because'; |
||
| 72 | $reason .= ' the target machine actively refused it\.\r\n'; |
||
| 73 | $reason .= ' while trying to join tcp:\/\/127\.0\.0\.1:655355\.$/'; |
||
| 74 | } else { |
||
| 75 | $reason = '/^Client returns an error \(number \d+\): Connection refused'; |
||
| 76 | $reason .= ' while trying to join tcp:\/\/127\.0\.0\.1:655355\.$/'; |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->assertRegExp($reason, $failure->getReason()); |
||
| 80 | $this->assertEquals('Time Server', $failure->getCheckName()); |
||
| 81 | } |
||
| 82 | |||
| 83 | View Code Duplication | public function testFailureIsReturnedIfOutputWasNotCorrect() |
|
| 91 | |||
| 92 | public function testSuccessIsReturnedIfOutputIsCorrect() |
||
| 98 | |||
| 99 | View Code Duplication | public function testProcessIsStoppedIfStillRunning() |
|
| 107 | |||
| 108 | View Code Duplication | public function testFailureIsReturnedIfProcessWasNotSuccessful() |
|
| 116 | } |
||
| 117 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.