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 |
||
| 18 | abstract class Controller extends \yii\console\Controller |
||
| 19 | { |
||
| 20 | use GettersTrait; |
||
| 21 | |||
| 22 | public $layout = false; |
||
| 23 | |||
| 24 | protected $_before = []; |
||
| 25 | protected $_after = []; |
||
| 26 | |||
| 27 | public function behaviors() |
||
| 33 | |||
| 34 | public function setBefore($requests) |
||
| 38 | |||
| 39 | public function getBefore() |
||
| 43 | |||
| 44 | public function setAfter($requests) |
||
| 48 | |||
| 49 | public function getAfter() |
||
| 53 | |||
| 54 | public function readline($prompt) |
||
| 58 | |||
| 59 | View Code Duplication | public function readpassword($prompt) |
|
| 69 | } |
||
| 70 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: