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 |
||
| 16 | class mediaembed extends \phpbb\cron\task\base |
||
| 17 | { |
||
| 18 | /** @var \phpbb\config\config $config Config object */ |
||
| 19 | protected $config; |
||
| 20 | |||
| 21 | /** @var \phpbb\cache\driver\driver_interface */ |
||
| 22 | protected $cache; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor |
||
| 26 | * |
||
| 27 | * @param \phpbb\config\config $config Config object |
||
| 28 | * @param \phpbb\cache\driver\driver_interface $cache Cache jbject |
||
| 29 | * @access public |
||
| 30 | */ |
||
| 31 | public function __construct(\phpbb\config\config $config, \phpbb\cache\driver\driver_interface $cache) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritDoc} |
||
| 39 | */ |
||
| 40 | public function run() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritDoc} |
||
| 54 | */ |
||
| 55 | public function is_runnable() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritDoc} |
||
| 62 | */ |
||
| 63 | public function should_run() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Purge all MediaEmbed cache files |
||
| 70 | */ |
||
| 71 | protected function mediaembed_purge_cache() |
||
| 98 | } |
||
| 99 |
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.