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 |
||
| 9 | class DoctrineRepositoryGenerator extends Generator |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var BundleStructureHelper |
||
| 13 | */ |
||
| 14 | protected $helper; |
||
| 15 | |||
| 16 | 2 | public function __construct(BundleInterface $bundle, $entity) |
|
| 20 | |||
| 21 | 1 | protected function canWriteToFile($forceOverwrite) |
|
| 25 | |||
| 26 | /** |
||
| 27 | * Generates the entity form class if it does not exist. |
||
| 28 | * |
||
| 29 | * @param bool $forceOverwrite |
||
| 30 | */ |
||
| 31 | 2 | public function generate($forceOverwrite = false) |
|
| 51 | } |
||
| 52 |
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: