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 |
||
| 13 | View Code Duplication | class EditorFactory |
|
| 14 | { |
||
| 15 | use CommandFactoryTrait; |
||
| 16 | |||
| 17 | /** @type \Nubs\Sensible\Strategy\PagerStrategy The pager strategy. */ |
||
| 18 | private $_strategy; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Create the editor. |
||
| 22 | * |
||
| 23 | * @api |
||
| 24 | * @param \Nubs\Which\Locator $commandLocator The command locator. This |
||
| 25 | * helps locate commands using PATH. |
||
| 26 | * @param string[] $editors The names to the potential editors. The first |
||
| 27 | * command in the list that can be located will be used. |
||
| 28 | * @param \Habitat\Environment\Environment $environment The environment |
||
| 29 | * variable wrapper. Defaults to null, which just uses the built-in |
||
| 30 | * getenv. |
||
| 31 | */ |
||
| 32 | public function __construct(CommandLocator $commandLocator, array $editors = ['sensible-editor', 'nano', 'vim', 'ed'], Environment $environment = null) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Create the editor object using the strategy. |
||
| 39 | * |
||
| 40 | * @api |
||
| 41 | * @return \Nubs\Sensible\Editor The created editor object. |
||
| 42 | * @throws \Exception if no editor can be found. |
||
| 43 | */ |
||
| 44 | public function create() |
||
| 48 | } |
||
| 49 |