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 |
||
14 | class UnlockCommand extends ContainerAwareCommand |
||
15 | { |
||
16 | /** |
||
17 | * @var LockHandlerInterface |
||
18 | */ |
||
19 | private $lockHandler; |
||
20 | |||
21 | /** |
||
22 | * @param LockHandlerInterface $lockHandler |
||
23 | * @param null|string $name |
||
24 | */ |
||
25 | public function __construct( |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | View Code Duplication | protected function configure() |
|
|
|||
37 | { |
||
38 | $this |
||
39 | ->setName('itkg_delay_event:unlock') |
||
40 | ->setDescription('Unlock command') |
||
41 | ->addOption( |
||
42 | 'channel', |
||
43 | 'c', |
||
44 | InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, |
||
45 | 'Specify the channels to unlock (default: [\'default\'])', |
||
46 | ['default'] |
||
47 | ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param InputInterface $input |
||
52 | * @param OutputInterface $output |
||
53 | * |
||
54 | * @return int|null|void |
||
55 | */ |
||
56 | protected function execute(InputInterface $input, OutputInterface $output) |
||
66 | } |
||
67 |
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.