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 ZohoDatabasePusher |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var Connection |
||
| 20 | */ |
||
| 21 | private $connection; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var LoggerInterface |
||
| 25 | */ |
||
| 26 | private $logger; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $prefix; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param Connection $connection |
||
| 35 | * @param string $prefix |
||
| 36 | * @param LoggerInterface $logger |
||
| 37 | */ |
||
| 38 | public function __construct(Connection $connection, $prefix = 'zoho_', LoggerInterface $logger = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param AbstractZohoDao $zohoDao |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | private function findMethodValues(AbstractZohoDao $zohoDao) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Insert or Update rows. |
||
| 71 | * |
||
| 72 | * @param AbstractZohoDao $zohoDao |
||
| 73 | */ |
||
| 74 | public function pushDataToZoho(AbstractZohoDao $zohoDao, $update = false) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Insert data to bean in order to insert zoho records. |
||
| 138 | * |
||
| 139 | * @param ZohoBeanInterface $zohoBean |
||
| 140 | * @param array $fieldsMatching |
||
| 141 | * @param array $row |
||
| 142 | */ |
||
| 143 | View Code Duplication | private function insertDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, array $row) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Insert data to bean in order to update zoho records. |
||
| 156 | * |
||
| 157 | * @param ZohoBeanInterface $zohoBean |
||
| 158 | * @param array $fieldsMatching |
||
| 159 | * @param type $columnName |
||
| 160 | * @param type $valueDb |
||
| 161 | */ |
||
| 162 | View Code Duplication | private function updateDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, $columnName, $valueDb) |
|
| 170 | |||
| 171 | /** |
||
| 172 | * Change the value to the good format. |
||
| 173 | * |
||
| 174 | * @param string $type |
||
| 175 | * @param mixed $value |
||
| 176 | * |
||
| 177 | * @return mixed |
||
| 178 | */ |
||
| 179 | private function formatValueToBeans($type, $value) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Run deleted rows to Zoho : local_delete. |
||
| 195 | * |
||
| 196 | * @param AbstractZohoDao $zohoDao |
||
| 197 | */ |
||
| 198 | public function pushDeletedRows(AbstractZohoDao $zohoDao) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Run inserted rows to Zoho : local_insert. |
||
| 218 | * |
||
| 219 | * @param AbstractZohoDao $zohoDao |
||
| 220 | */ |
||
| 221 | public function pushInsertedRows(AbstractZohoDao $zohoDao) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Run updated rows to Zoho : local_update. |
||
| 228 | * |
||
| 229 | * @param AbstractZohoDao $zohoDao |
||
| 230 | */ |
||
| 231 | public function pushUpdatedRows(AbstractZohoDao $zohoDao) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Push data from db to Zoho. |
||
| 238 | * |
||
| 239 | * @param AbstractZohoDao $zohoDao |
||
| 240 | */ |
||
| 241 | public function pushToZoho(AbstractZohoDao $zohoDao) |
||
| 250 | |||
| 251 | } |
||
| 252 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.