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 Editor extends Field |
||
8 | { |
||
9 | protected static $js = [ |
||
10 | '//cdn.ckeditor.com/4.5.10/standard/ckeditor.js', |
||
11 | ]; |
||
12 | |||
13 | public function __construct($column, array $arguments = []) |
||
21 | |||
22 | /** |
||
23 | * set `direction` . |
||
24 | * https://docs-old.ckeditor.com/ckeditor_api/symbols/CKEDITOR.config.html#.contentsLangDirection |
||
25 | * 'ui' – indicates that content direction will be the same as the user interface language direction; |
||
26 | * 'ltr' – for Left-To-Right language (like English); |
||
27 | * 'rtl' – for Right-To-Left languages (like Arabic). |
||
28 | * @param string $dir |
||
29 | * @return $this |
||
30 | */ |
||
31 | public function dir($dir) |
||
35 | |||
36 | /** |
||
37 | * set language for editor |
||
38 | * @param string $dir |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function lang($dir) |
||
45 | |||
46 | View Code Duplication | public function render() |
|
53 | } |
||
54 |
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.