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 | ]; |
||
25 | |||
26 | /** |
||
27 | * @param $filePath |
||
28 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
29 | * default behavior (false) is throw an exception on unknown track types. |
||
30 | * |
||
31 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
32 | * |
||
33 | * @return MediaInfoContainer |
||
34 | */ |
||
35 | public function getInfo($filePath, $ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
45 | |||
46 | /** |
||
47 | * Call to start asynchronous process. |
||
48 | * |
||
49 | * Make call to MediaInfo::getInfoWaitAsync() afterwards to received MediaInfoContainer object. |
||
50 | * |
||
51 | * @param $filePath |
||
52 | */ |
||
53 | public function getInfoStartAsync($filePath): void |
||
62 | |||
63 | /** |
||
64 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
65 | * default behavior (false) is throw an exception on unknown track types. |
||
66 | * |
||
67 | * @throws \Exception If this function is called before getInfoStartAsync() |
||
68 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
69 | * |
||
70 | * @return MediaInfoContainer |
||
71 | */ |
||
72 | public function getInfoWaitAsync($ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
86 | |||
87 | /** |
||
88 | * @param string $key |
||
89 | * @param string $value |
||
90 | * |
||
91 | * @throws \Exception |
||
92 | */ |
||
93 | 1 | View Code Duplication | public function setConfig($key, $value) |
103 | |||
104 | /** |
||
105 | * @param $key |
||
106 | * |
||
107 | * @throws \Exception |
||
108 | * |
||
109 | * @return mixed |
||
110 | */ |
||
111 | 2 | View Code Duplication | public function getConfig($key) |
121 | } |
||
122 |