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 |
||
18 | class CleanDeletedMediaCommand extends ContainerAwareCommand |
||
19 | { |
||
20 | /** |
||
21 | * @var EntityManager |
||
22 | */ |
||
23 | private $em; |
||
24 | |||
25 | /** |
||
26 | * @var MediaManager |
||
27 | */ |
||
28 | private $mediaManager; |
||
29 | |||
30 | /** |
||
31 | * @param EntityManagerInterface|null $em |
||
32 | * @param MediaManager|null $mediaManager |
||
33 | */ |
||
34 | View Code Duplication | public function __construct(/* EntityManagerInterface */ $em = null, /* MediaManager */ $mediaManager = null) |
|
|
|||
35 | { |
||
36 | parent::__construct(); |
||
37 | |||
38 | if (!$em instanceof EntityManagerInterface) { |
||
39 | @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED); |
||
40 | |||
41 | $this->setName(null === $em ? 'kuma:media:clean-deleted-media' : $em); |
||
42 | |||
43 | return; |
||
44 | } |
||
45 | |||
46 | $this->em = $em; |
||
47 | $this->mediaManager = $mediaManager; |
||
48 | } |
||
49 | |||
50 | protected function configure() |
||
67 | |||
68 | protected function execute(InputInterface $input, OutputInterface $output) |
||
101 | } |
||
102 |
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.