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 |
||
| 20 | class ImageImportCommand extends ShopwareCommand |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var Helper |
||
| 24 | */ |
||
| 25 | private $helper; |
||
| 26 | |||
| 27 | public function __construct(Helper $helper) { |
||
| 31 | |||
| 32 | protected function configure() |
||
| 33 | { |
||
| 34 | $this |
||
| 35 | ->setName('connect:image:import') |
||
| 36 | ->setDescription('Import images from connect') |
||
| 37 | ->addArgument( |
||
| 38 | 'limit', |
||
| 39 | InputArgument::OPTIONAL, |
||
| 40 | 'Amount of Images to import at once', |
||
| 41 | 10 |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param InputInterface $input |
||
| 47 | * @param OutputInterface $output |
||
| 48 | */ |
||
| 49 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return ImageImport |
||
| 61 | */ |
||
| 62 | View Code Duplication | private function getImageImport() |
|
| 74 | } |
||
| 75 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.