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 Pager |
||
| 10 | { |
||
| 11 | /** @type string The pager command to use. */ |
||
| 12 | private $_pagerCommand; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Initialize the pager command. |
||
| 16 | * |
||
| 17 | * @api |
||
| 18 | * @param string $pagerCommand The pager command to use. |
||
| 19 | */ |
||
| 20 | public function __construct($pagerCommand) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * View the given file using the symfony process builder to build the |
||
| 27 | * symfony process to execute. |
||
| 28 | * |
||
| 29 | * @api |
||
| 30 | * @param \Symfony\Component\Process\ProcessBuilder $processBuilder The |
||
| 31 | * process builder. |
||
| 32 | * @param string $filePath The path to the file to view. |
||
| 33 | * @return \Symfony\Component\Process\Process The already-executed process. |
||
| 34 | */ |
||
| 35 | View Code Duplication | public function viewFile(ProcessBuilder $processBuilder, $filePath) |
|
| 42 | |||
| 43 | /** |
||
| 44 | * View the given data using the symfony process builder to build the |
||
| 45 | * symfony process to execute. |
||
| 46 | * |
||
| 47 | * @api |
||
| 48 | * @param \Symfony\Component\Process\ProcessBuilder $processBuilder The |
||
| 49 | * process builder. |
||
| 50 | * @param string $data The data to view. |
||
| 51 | * @return \Symfony\Component\Process\Process The already-executed process. |
||
| 52 | */ |
||
| 53 | View Code Duplication | public function viewData(ProcessBuilder $processBuilder, $data) |
|
| 60 | } |
||
| 61 |