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 namespace Folour\Flavy\Extensions; |
||
10 | class Base extends Commands |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * |
||
15 | * Flavy config |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $config = [ |
||
20 | 'ffmpeg_path' => 'ffmpeg', |
||
21 | 'ffprobe_path' => 'ffprobe' |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * |
||
26 | * FFmpeg information |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | private $_info = [ |
||
31 | 'formats' => [], |
||
32 | |||
33 | 'encoders' => [ |
||
34 | 'audio' => [], |
||
35 | 'video' => [] |
||
36 | ], |
||
37 | |||
38 | 'decoders' => [ |
||
39 | 'audio' => [], |
||
40 | 'video' => [] |
||
41 | ] |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * Base constructor. |
||
46 | * |
||
47 | * @param array $config |
||
48 | */ |
||
49 | public function __construct(array $config) |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * Returns array of supported formats |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public function formats() |
||
71 | |||
72 | /** |
||
73 | * |
||
74 | * Returns array of audio and video encoders |
||
75 | * [ |
||
76 | * 'audio' => [], |
||
77 | * 'video' => [] |
||
78 | * ] |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | View Code Duplication | public function encoders() |
|
95 | |||
96 | /** |
||
97 | * |
||
98 | * Returns array of audio and video decoders |
||
99 | * [ |
||
100 | * 'audio' => [], |
||
101 | * 'video' => [] |
||
102 | * ] |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | View Code Duplication | public function decoders() |
|
119 | |||
120 | /** |
||
121 | * @param string $format |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function canEncode($format) |
||
128 | |||
129 | /** |
||
130 | * @param string $format |
||
131 | * @return bool |
||
132 | */ |
||
133 | public function canDecode($format) |
||
137 | |||
138 | //Helpers |
||
139 | |||
140 | /** |
||
141 | * @param int|string $time timestamp for conversion |
||
142 | * @param bool $isDate mode flag, if true - $time converts from hh::mm:ss string to seconds, else conversely |
||
143 | * @return string |
||
144 | */ |
||
145 | protected function timestamp($time, $isDate = true) |
||
155 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.