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 |
||
7 | class Parser { |
||
8 | /** |
||
9 | * @var \tomzx\IRCStats\DatabaseProxy |
||
10 | */ |
||
11 | protected $databaseProxy; |
||
12 | |||
13 | /** |
||
14 | * @param \tomzx\IRCStats\DatabaseProxy $databaseProxy |
||
15 | */ |
||
16 | 1 | public function __construct(DatabaseProxy $databaseProxy) |
|
20 | |||
21 | /** |
||
22 | * @return \Illuminate\Database\Connection |
||
23 | */ |
||
24 | 1 | protected function getConnection() |
|
28 | |||
29 | /** |
||
30 | * @param array $line |
||
31 | * @return void |
||
32 | */ |
||
33 | 1 | public function parseLine(array $line) |
|
54 | |||
55 | /** |
||
56 | * @param \Illuminate\Database\Connection $db |
||
57 | * @param string $server |
||
58 | * @return int |
||
59 | */ |
||
60 | 1 | View Code Duplication | protected function getNetworkId(Connection $db, $server) |
75 | |||
76 | /** |
||
77 | * @param \Illuminate\Database\Connection $db |
||
78 | * @param int $networkId |
||
79 | * @param string $channel |
||
80 | * @return int |
||
81 | */ |
||
82 | 1 | View Code Duplication | protected function getChannelId(Connection $db, $networkId, $channel) |
99 | |||
100 | /** |
||
101 | * @param \Illuminate\Database\Connection $db |
||
102 | * @param int $channelId |
||
103 | * @param string $nick |
||
104 | * @return int |
||
105 | */ |
||
106 | 1 | View Code Duplication | protected function getNickId(Connection $db, $channelId, $nick) |
123 | } |
||
124 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.