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 |
||
32 | View Code Duplication | class WebServerListener implements TestListener |
|
33 | { |
||
34 | /** @var WebServerListenerTrait */ |
||
35 | private $trait; |
||
36 | |||
37 | public function __construct() |
||
41 | |||
42 | /** |
||
43 | * Make sure the PHP built-in web server is running for tests with group |
||
44 | * 'webserver'. |
||
45 | */ |
||
46 | public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) |
||
50 | |||
51 | /** |
||
52 | * We don't need these. |
||
53 | */ |
||
54 | public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) |
||
57 | |||
58 | public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
||
61 | |||
62 | public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) |
||
65 | |||
66 | public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
||
69 | |||
70 | public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
||
73 | |||
74 | public function startTest(\PHPUnit_Framework_Test $test) |
||
77 | |||
78 | public function endTest(\PHPUnit_Framework_Test $test, $time) |
||
81 | |||
82 | public function addRiskyTest(\PHPUnit_Framework_Test $test, \Exception $e, $time) |
||
85 | |||
86 | /** |
||
87 | * Get web server hostname. |
||
88 | * |
||
89 | * @throws \Exception |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | protected function getHostName() |
||
97 | |||
98 | /** |
||
99 | * Get web server port. |
||
100 | * |
||
101 | * @throws \Exception |
||
102 | * |
||
103 | * @return int |
||
104 | */ |
||
105 | protected function getPort() |
||
109 | |||
110 | /** |
||
111 | * Get web server port. |
||
112 | * |
||
113 | * @throws \Exception |
||
114 | * |
||
115 | * @return int |
||
116 | */ |
||
117 | protected function getDocRoot() |
||
121 | |||
122 | /** |
||
123 | * Start PHP built-in web server. |
||
124 | * |
||
125 | * @return int PID |
||
126 | */ |
||
127 | protected function startPhpWebServer() |
||
131 | |||
132 | /** |
||
133 | * Wait for caching proxy to be started up and reachable. |
||
134 | * |
||
135 | * @param string $ip |
||
136 | * @param int $port |
||
137 | * @param int $timeout Timeout in milliseconds |
||
138 | * |
||
139 | * @throws \RuntimeException If proxy is not reachable within timeout |
||
140 | */ |
||
141 | protected function waitFor($ip, $port, $timeout) |
||
145 | } |
||
146 |