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 | const MEDIAINFO_URLENCODE = '--urlencode'; |
||
14 | const MEDIAINFO_INCLUDE_COVER_DATA = '--Cover_Data=base64'; |
||
15 | |||
16 | /** |
||
17 | * @var Process |
||
18 | */ |
||
19 | protected $process; |
||
20 | |||
21 | /** |
||
22 | * @param Process $process |
||
23 | */ |
||
24 | 8 | public function __construct(Process $process) |
|
28 | |||
29 | /** |
||
30 | * @throws \RuntimeException |
||
31 | * |
||
32 | * @return string |
||
33 | */ |
||
34 | 2 | View Code Duplication | public function run(): string |
43 | |||
44 | /** |
||
45 | * Asynchronously start mediainfo operation. |
||
46 | * Make call to MediaInfoCommandRunner::wait() afterwards to receive output. |
||
47 | */ |
||
48 | 2 | public function start(): void |
|
54 | |||
55 | /** |
||
56 | * Blocks until call is complete. |
||
57 | * |
||
58 | * @throws \Exception If this function is called before start() |
||
59 | * @throws \RuntimeException |
||
60 | * |
||
61 | * @return string |
||
62 | */ |
||
63 | 2 | View Code Duplication | public function wait(): string |
74 | } |
||
75 |