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 |
||
10 | class MediaInfo |
||
11 | { |
||
12 | /** |
||
13 | * @var MediaInfoCommandRunner|null |
||
14 | */ |
||
15 | private $mediaInfoCommandRunnerAsync = null; |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | private $configuration = [ |
||
21 | 'command' => null, |
||
22 | 'use_oldxml_mediainfo_output_format' => true, |
||
23 | 'urlencode' => false, |
||
24 | 'include_cover_data' => false, |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * @param $filePath |
||
29 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
30 | * default behavior (false) is throw an exception on unknown track types. |
||
31 | * |
||
32 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
33 | * |
||
34 | * @return MediaInfoContainer |
||
35 | */ |
||
36 | public function getInfo($filePath, $ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
46 | |||
47 | /** |
||
48 | * Call to start asynchronous process. |
||
49 | * |
||
50 | * Make call to MediaInfo::getInfoWaitAsync() afterwards to received MediaInfoContainer object. |
||
51 | * |
||
52 | * @param $filePath |
||
53 | */ |
||
54 | public function getInfoStartAsync($filePath): void |
||
63 | |||
64 | /** |
||
65 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
66 | * default behavior (false) is throw an exception on unknown track types. |
||
67 | * |
||
68 | * @throws \Exception If this function is called before getInfoStartAsync() |
||
69 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
70 | * |
||
71 | * @return MediaInfoContainer |
||
72 | */ |
||
73 | public function getInfoWaitAsync($ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
87 | |||
88 | /** |
||
89 | * @param string $key |
||
90 | * @param string $value |
||
91 | * |
||
92 | * @throws \Exception |
||
93 | */ |
||
94 | 1 | View Code Duplication | public function setConfig($key, $value) |
104 | |||
105 | /** |
||
106 | * @param $key |
||
107 | * |
||
108 | * @throws \Exception |
||
109 | * |
||
110 | * @return mixed |
||
111 | */ |
||
112 | 2 | View Code Duplication | public function getConfig($key) |
122 | } |
||
123 |