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 |
||
| 22 | abstract class PdfPublisher extends BasePublisher |
||
| 23 | { |
||
| 24 | |||
| 25 | public function loadContents() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * If the book defines a custom PDF cover, this method prepends it |
||
| 49 | * to the PDF book. |
||
| 50 | * |
||
| 51 | * @param string $bookFilePath The path of the original PDF book without the cover |
||
| 52 | * @param string $coverFilePath The path of the PDF file which will be displayed as the cover of the book |
||
| 53 | * |
||
| 54 | * @protected (set to public to be able to unit test it) |
||
| 55 | */ |
||
| 56 | View Code Duplication | public function addBookCover($bookFilePath, $coverFilePath) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * It looks for custom book cover PDF. The search order is: |
||
| 71 | * 1. <book>/Resources/Templates/<edition-name>/cover.pdf |
||
| 72 | * 2. <book>/Resources/Templates/pdf/cover.pdf |
||
| 73 | * 3. <book>/Resources/Templates/cover.pdf |
||
| 74 | * |
||
| 75 | * @param string $coverFileName The name of the PDF file that defines the book cover |
||
| 76 | * |
||
| 77 | * @return null|string The filePath of the PDF cover or null if none exists |
||
| 78 | * |
||
| 79 | * @protected (set to public to be able to unit test it) |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function getCustomCover($coverFileName = 'cover.pdf') |
|
| 91 | |||
| 92 | } |
||
| 93 |