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 PagerFactory |
|
| 14 | { |
||
| 15 | use CommandFactoryTrait; |
||
| 16 | |||
| 17 | /** @type \Nubs\Sensible\Strategy\PagerFactory The pager strategy. */ |
||
| 18 | private $_strategy; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Create the pager. |
||
| 22 | * |
||
| 23 | * @api |
||
| 24 | * @param \Nubs\Which\Locator $commandLocator The command locator. This |
||
| 25 | * helps locate commands using PATH. |
||
| 26 | * @param string[] $pagers The names to the potential pagers. 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 $pagers = ['sensible-pager', 'less', 'more'], Environment $environment = null) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Create the pager object using the strategy. |
||
| 39 | * |
||
| 40 | * @api |
||
| 41 | * @return \Nubs\Sensible\Pager The created pager object. |
||
| 42 | * @throws \Exception if no pager can be found. |
||
| 43 | */ |
||
| 44 | public function create() |
||
| 48 | } |
||
| 49 |