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 |
||
21 | class MyAwesomeModule extends MyAwesomeBaseModule implements ModuleInterface{ |
||
22 | |||
23 | /** |
||
24 | * An array of tags the module is able to process |
||
25 | * |
||
26 | * @var array |
||
27 | * @see \chillerlan\bbcode\Modules\Tagmap::$tags |
||
28 | */ |
||
29 | protected $tags = ['mybbcode', 'somebbcode', 'whatever']; |
||
30 | |||
31 | /** |
||
32 | * Transforms the bbcode, called from BaseModuleInterface |
||
33 | * |
||
34 | * @return string a transformed snippet |
||
35 | * @see \chillerlan\bbcode\Modules\BaseModuleInterface::transform() |
||
36 | * @internal |
||
37 | */ |
||
38 | public function _transform(){ |
||
39 | if(empty($this->content)){ |
||
40 | return ''; |
||
41 | } |
||
42 | |||
43 | return '<'.$this->tag.'>'.$this->content.'</'.$this->tag.'>'; |
||
44 | } |
||
45 | |||
46 | } |
||
47 |