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 |
||
12 | class InfluxDbClientFactoryTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | |||
15 | const TEST_HOST = 'localhost'; |
||
16 | const TEST_DB = 'udp'; |
||
17 | const TEST_UDP = '4444'; |
||
18 | const TEST_HTTP = '8086'; |
||
19 | |||
20 | public function test_client_factory_test_exists() |
||
25 | |||
26 | View Code Duplication | public function test_build_udp_client_returns_a_valid_client() |
|
35 | |||
36 | View Code Duplication | public function test_build_http_client_returns_a_valid_client() |
|
45 | |||
46 | } |
||
47 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.