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 | * Stored original XML output from MediaInfo. |
||
| 28 | * |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $originalXml = ''; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param $filePath |
||
| 35 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
| 36 | * default behavior (false) is throw an exception on unknown track types. |
||
| 37 | * |
||
| 38 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
| 39 | * |
||
| 40 | * @return MediaInfoContainer |
||
| 41 | */ |
||
| 42 | public function getInfo($filePath, $ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Call to start asynchronous process. |
||
| 57 | * |
||
| 58 | * Make call to MediaInfo::getInfoWaitAsync() afterwards to received MediaInfoContainer object. |
||
| 59 | * |
||
| 60 | * @param $filePath |
||
| 61 | */ |
||
| 62 | public function getInfoStartAsync($filePath): void |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The |
||
| 74 | * default behavior (false) is throw an exception on unknown track types. |
||
| 75 | * |
||
| 76 | * @throws \Exception If this function is called before getInfoStartAsync() |
||
| 77 | * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException |
||
| 78 | * |
||
| 79 | * @return MediaInfoContainer |
||
| 80 | */ |
||
| 81 | public function getInfoWaitAsync($ignoreUnknownTrackTypes = false): MediaInfoContainer |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param string $key |
||
| 98 | * @param string $value |
||
| 99 | * |
||
| 100 | * @throws \Exception |
||
| 101 | */ |
||
| 102 | 1 | View Code Duplication | public function setConfig($key, $value) |
| 112 | |||
| 113 | /** |
||
| 114 | * @param $key |
||
| 115 | * |
||
| 116 | * @throws \Exception |
||
| 117 | * |
||
| 118 | * @return mixed |
||
| 119 | */ |
||
| 120 | 2 | View Code Duplication | public function getConfig($key) |
| 130 | |||
| 131 | /** |
||
| 132 | * Get last received XML output of MediaInfo. |
||
| 133 | * |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | public function getOriginalXml() |
||
| 140 | } |
||
| 141 |