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) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Insert data to bean in order to insert zoho records. |
||
| 134 | * |
||
| 135 | * @param ZohoBeanInterface $zohoBean |
||
| 136 | * @param array $fieldsMatching |
||
| 137 | * @param array $row |
||
| 138 | */ |
||
| 139 | View Code Duplication | private function insertDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, array $row) |
|
| 149 | |||
| 150 | /** |
||
| 151 | * Insert data to bean in order to update zoho records. |
||
| 152 | * |
||
| 153 | * @param ZohoBeanInterface $zohoBean |
||
| 154 | * @param array $fieldsMatching |
||
| 155 | * @param type $columnName |
||
| 156 | * @param type $valueDb |
||
| 157 | */ |
||
| 158 | View Code Duplication | private function updateDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, $columnName, $valueDb) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Change the value to the good format. |
||
| 169 | * |
||
| 170 | * @param string $type |
||
| 171 | * @param mixed $value |
||
| 172 | * |
||
| 173 | * @return mixed |
||
| 174 | */ |
||
| 175 | private function formatValueToBeans($type, $value) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Run deleted rows to Zoho : local_delete. |
||
| 191 | * |
||
| 192 | * @param AbstractZohoDao $zohoDao |
||
| 193 | */ |
||
| 194 | public function pushDeletedRows(AbstractZohoDao $zohoDao) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Run inserted rows to Zoho : local_insert. |
||
| 214 | * |
||
| 215 | * @param AbstractZohoDao $zohoDao |
||
| 216 | */ |
||
| 217 | public function pushInsertedRows(AbstractZohoDao $zohoDao) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Run updated rows to Zoho : local_update. |
||
| 224 | * |
||
| 225 | * @param AbstractZohoDao $zohoDao |
||
| 226 | */ |
||
| 227 | public function pushUpdatedRows(AbstractZohoDao $zohoDao) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Push data from db to Zoho. |
||
| 234 | * |
||
| 235 | * @param AbstractZohoDao $zohoDao |
||
| 236 | */ |
||
| 237 | public function pushToZoho(AbstractZohoDao $zohoDao) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @param LoggerInterface $logger |
||
| 249 | */ |
||
| 250 | public function setLogger(LoggerInterface $logger) |
||
| 254 | } |
||
| 255 |
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.