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) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Import all translation files from app resources |
||
| 61 | * |
||
| 62 | * @param ImportCommand $importCommand |
||
| 63 | * |
||
| 64 | * @return int total number of files imported |
||
| 65 | */ |
||
| 66 | private function importGlobalTranslationFiles(ImportCommand $importCommand) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Import all translation files from a specific bundle, bundle name will be lowercased so cases don't matter |
||
| 78 | * |
||
| 79 | * @param ImportCommand $importCommand |
||
| 80 | * |
||
| 81 | * @return int total number of files imported |
||
| 82 | */ |
||
| 83 | public function importBundleTranslationFiles(ImportCommand $importCommand) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Import all translation files from all registered bundles (in AppKernel) |
||
| 110 | * |
||
| 111 | * @param ImportCommand $importCommand |
||
| 112 | * |
||
| 113 | * @return int total number of files imported |
||
| 114 | */ |
||
| 115 | View Code Duplication | private function importAllBundlesTranslationFiles(ImportCommand $importCommand) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Import all translation files from your own registered bundles (in src/ directory) |
||
| 135 | * |
||
| 136 | * @param ImportCommand $importCommand |
||
| 137 | * |
||
| 138 | * @return int The total number of imported files |
||
| 139 | */ |
||
| 140 | private function importOwnBundlesTranslationFiles(ImportCommand $importCommand) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Import the translation files from the defined bundles. |
||
| 162 | * |
||
| 163 | * @param ImportCommand $importCommand |
||
| 164 | * |
||
| 165 | * @return int The total number of imported files |
||
| 166 | */ |
||
| 167 | View Code Duplication | private function importCustomBundlesTranslationFiles(ImportCommand $importCommand) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Import all translation files from a single bundle |
||
| 186 | * |
||
| 187 | * @param ImportCommand $importCommand |
||
| 188 | * |
||
| 189 | * @return int total number of files imported |
||
| 190 | */ |
||
| 191 | private function importSingleBundleTranslationFiles(ImportCommand $importCommand) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Import translation files from a specific Finder object |
||
| 206 | * The finder object shoud already have the files to look for defined; |
||
| 207 | * Forcing the import will override all existing translations in the stasher |
||
| 208 | * |
||
| 209 | * @param Finder $finder |
||
| 210 | * @param bool $force override identical translations in the stasher (domain/locale and keyword combination) |
||
| 211 | * |
||
| 212 | * @return int total number of files imported |
||
| 213 | */ |
||
| 214 | private function importTranslationFiles(Finder $finder, $force = false) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Validates that a bundle is registered in the AppKernel |
||
| 231 | * |
||
| 232 | * @param string $bundle |
||
| 233 | * |
||
| 234 | * @return bool bundle is valid or not |
||
| 235 | * |
||
| 236 | * @throws \Exception If the bundlename isn't valid |
||
| 237 | */ |
||
| 238 | public function validateBundleName($bundle) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Gives an array with all languages that needs to be imported (from the given ImportCommand) |
||
| 252 | * If non is given, all managed locales will be used (defined in config) |
||
| 253 | * |
||
| 254 | * @param ImportCommand $importCommand |
||
| 255 | * |
||
| 256 | * @return array all locales to import by the given ImportCommand |
||
| 257 | */ |
||
| 258 | public function determineLocalesToImport(ImportCommand $importCommand) |
||
| 266 | |||
| 267 | public function setTranslationFileExplorer($translationFileExplorer) |
||
| 271 | |||
| 272 | public function setImporter($importer) |
||
| 276 | |||
| 277 | private function importSf4TranslationFiles($importCommand) |
||
| 287 | } |
||
| 288 |
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.