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 |
||
| 15 | class ImportCommandHandler extends AbstractCommandHandler |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * TranslationFileExplorer |
||
| 19 | * |
||
| 20 | * @var TranslationFileExplorer |
||
| 21 | */ |
||
| 22 | private $translationFileExplorer; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Importer |
||
| 26 | * |
||
| 27 | * @var Importer |
||
| 28 | */ |
||
| 29 | private $importer; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Execute an import command |
||
| 33 | * |
||
| 34 | * @param ImportCommand $importCommand |
||
| 35 | * |
||
| 36 | * @return int total number of files imported |
||
|
|
|||
| 37 | */ |
||
| 38 | public function executeImportCommand(ImportCommand $importCommand) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Import all translation files from app resources |
||
| 49 | * |
||
| 50 | * @param ImportCommand $importCommand |
||
| 51 | * |
||
| 52 | * @return int total number of files imported |
||
| 53 | */ |
||
| 54 | private function importGlobalTranslationFiles(ImportCommand $importCommand) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Import all translation files from a specific bundle, bundle name will be lowercased so cases don't matter |
||
| 66 | * |
||
| 67 | * @param ImportCommand $importCommand |
||
| 68 | * |
||
| 69 | * @return int total number of files imported |
||
| 70 | */ |
||
| 71 | public function importBundleTranslationFiles(ImportCommand $importCommand) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Import all translation files from all registered bundles (in AppKernel) |
||
| 96 | * |
||
| 97 | * @param ImportCommand $importCommand |
||
| 98 | * |
||
| 99 | * @return int total number of files imported |
||
| 100 | */ |
||
| 101 | View Code Duplication | private function importAllBundlesTranslationFiles(ImportCommand $importCommand) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Import all translation files from your own registered bundles (in src/ directory) |
||
| 121 | * |
||
| 122 | * @param ImportCommand $importCommand |
||
| 123 | * |
||
| 124 | * @return int The total number of imported files |
||
| 125 | */ |
||
| 126 | private function importOwnBundlesTranslationFiles(ImportCommand $importCommand) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Import the translation files from the defined bundles. |
||
| 148 | * |
||
| 149 | * @param ImportCommand $importCommand |
||
| 150 | * |
||
| 151 | * @return int The total number of imported files |
||
| 152 | */ |
||
| 153 | View Code Duplication | private function importCustomBundlesTranslationFiles(ImportCommand $importCommand) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * Import all translation files from a single bundle |
||
| 172 | * |
||
| 173 | * @param ImportCommand $importCommand |
||
| 174 | * |
||
| 175 | * @return int total number of files imported |
||
| 176 | */ |
||
| 177 | private function importSingleBundleTranslationFiles(ImportCommand $importCommand) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Import translation files from a specific Finder object |
||
| 192 | * The finder object shoud already have the files to look for defined; |
||
| 193 | * Forcing the import will override all existing translations in the stasher |
||
| 194 | * |
||
| 195 | * @param Finder $finder |
||
| 196 | * @param bool $force override identical translations in the stasher (domain/locale and keyword combination) |
||
| 197 | * |
||
| 198 | * @return int total number of files imported |
||
| 199 | */ |
||
| 200 | private function importTranslationFiles(Finder $finder, $force = flase) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Validates that a bundle is registered in the AppKernel |
||
| 217 | * |
||
| 218 | * @param string $bundle |
||
| 219 | * |
||
| 220 | * @return bool bundle is valid or not |
||
| 221 | * |
||
| 222 | * @throws \Exception If the bundlename isn't valid |
||
| 223 | */ |
||
| 224 | public function validateBundleName($bundle) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Gives an array with all languages that needs to be imported (from the given ImportCommand) |
||
| 238 | * If non is given, all managed locales will be used (defined in config) |
||
| 239 | * |
||
| 240 | * @param ImportCommand $importCommand |
||
| 241 | * |
||
| 242 | * @return array all locales to import by the given ImportCommand |
||
| 243 | */ |
||
| 244 | public function determineLocalesToImport(ImportCommand $importCommand) |
||
| 252 | |||
| 253 | public function setTranslationFileExplorer($translationFileExplorer) |
||
| 257 | |||
| 258 | public function setImporter($importer) |
||
| 262 | |||
| 263 | private function importSf4TranslationFiles($importCommand) |
||
| 273 | } |
||
| 274 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.