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 |
||
| 10 | abstract class AbstractCronCommand extends AbstractMagentoCommand |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var \Magento\Framework\App\State |
||
| 14 | */ |
||
| 15 | protected $state; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var \Magento\Cron\Model\ConfigInterface |
||
| 19 | */ |
||
| 20 | protected $cronConfig; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var \Magento\Framework\App\Config\ScopeConfigInterface |
||
| 24 | */ |
||
| 25 | protected $scopeConfig; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var \Magento\Cron\Model\ResourceModel\Schedule\Collection |
||
| 29 | */ |
||
| 30 | protected $cronScheduleCollection; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \Magento\Framework\App\ProductMetadataInterface $productMetadata |
||
| 34 | */ |
||
| 35 | private $productMetadata; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface |
||
| 39 | */ |
||
| 40 | protected $timezone; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var \Magento\Framework\Stdlib\DateTime\DateTime |
||
| 44 | */ |
||
| 45 | private $dateTime; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param \Magento\Framework\App\State $state |
||
| 49 | * @param \Magento\Cron\Model\ConfigInterface $cronConfig |
||
| 50 | * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata |
||
| 51 | * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
||
| 52 | * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime |
||
| 53 | * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig |
||
| 54 | * @param \Magento\Cron\Model\ResourceModel\Schedule\Collection $cronScheduleCollection |
||
| 55 | */ |
||
| 56 | public function inject( |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | protected function getJobs() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param string $jobCode |
||
| 105 | * @return array |
||
| 106 | */ |
||
| 107 | protected function getJobConfig($jobCode) |
||
| 108 | { |
||
| 109 | foreach ($this->cronConfig->getJobs() as $jobGroup) { |
||
| 110 | foreach ($jobGroup as $job) { |
||
| 111 | if (isset($job['name']) && $job['name'] == $jobCode) { |
||
| 112 | return $job; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | return []; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param array $job |
||
| 122 | * @return array |
||
| 123 | */ |
||
| 124 | protected function getSchedule(array $job) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param InputInterface $input |
||
| 150 | * @param OutputInterface $output |
||
| 151 | * @param array $jobs |
||
| 152 | * @return string |
||
| 153 | * @throws \InvalidArgumentException |
||
| 154 | * @throws \Exception |
||
| 155 | */ |
||
| 156 | protected function askJobCode(InputInterface $input, OutputInterface $output, $jobs) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param InputInterface $input |
||
| 182 | * @param OutputInterface $output |
||
| 183 | * @return array |
||
| 184 | */ |
||
| 185 | protected function getJobForExecuteMethod(InputInterface $input, OutputInterface $output) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Get timestamp used for time related database fields in the cron tables |
||
| 218 | * |
||
| 219 | * Note: The timestamp used will change from Magento 2.1.7 to 2.2.0 and |
||
| 220 | * these changes are branched by Magento version in this method. |
||
| 221 | * |
||
| 222 | * @return int |
||
| 223 | */ |
||
| 224 | protected function getCronTimestamp() |
||
| 235 | } |
||
| 236 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.