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 MediaInfoCommandRunner |
||
8 | { |
||
9 | const MEDIAINFO_COMMAND = 'mediainfo'; |
||
10 | const MEDIAINFO_OLDXML_OUTPUT_ARGUMENT = '--OUTPUT=OLDXML'; |
||
11 | const MEDIAINFO_XML_OUTPUT_ARGUMENT = '--OUTPUT=XML'; |
||
12 | const MEDIAINFO_FULL_DISPLAY_ARGUMENT = '-f'; |
||
13 | |||
14 | /** |
||
15 | * @var Process |
||
16 | */ |
||
17 | protected $process; |
||
18 | |||
19 | /** |
||
20 | * @param Process $process |
||
21 | */ |
||
22 | 8 | public function __construct(Process $process) |
|
26 | |||
27 | /** |
||
28 | * @throws \RuntimeException |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | 2 | View Code Duplication | public function run() |
41 | |||
42 | /** |
||
43 | * Asynchronously start mediainfo operation. |
||
44 | * Make call to MediaInfoCommandRunner::wait() afterwards to receive output. |
||
45 | */ |
||
46 | 2 | public function start() |
|
52 | |||
53 | /** |
||
54 | * Blocks until call is complete. |
||
55 | * |
||
56 | * @throws \Exception If this function is called before start() |
||
57 | * @throws \RuntimeException |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | 2 | View Code Duplication | public function wait() |
72 | } |
||
73 |