| Conditions | 12 |
| Paths | 208 |
| Total Lines | 73 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 3 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 74 | public function pushDataToZoho(AbstractZohoDao $zohoDao, $update = false) |
||
| 75 | { |
||
| 76 | $localTable = $update ? 'local_update' : 'local_insert'; |
||
| 77 | $fieldsMatching = $this->findMethodValues($zohoDao); |
||
| 78 | $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
||
| 79 | $rowsDeleted = []; |
||
| 80 | $statement = $this->connection->createQueryBuilder(); |
||
| 81 | $statement->select('zcrm.*'); |
||
| 82 | if ($update) { |
||
| 83 | $statement->addSelect('l.field_name as updated_fieldname'); |
||
| 84 | } |
||
| 85 | $statement->from($localTable, 'l') |
||
| 86 | ->join('l', $tableName, 'zcrm', 'zcrm.uid = l.uid') |
||
| 87 | ->where('l.table_name=:table_name') |
||
| 88 | ->setParameters([ |
||
| 89 | 'table_name' => $tableName, |
||
| 90 | ]); |
||
| 91 | $results = $statement->execute(); |
||
| 92 | /* @var $zohoBeans ZohoBeanInterface[] */ |
||
| 93 | $zohoBeans = array(); |
||
| 94 | while ($row = $results->fetch()) { |
||
| 95 | $beanClassName = $zohoDao->getBeanClassName(); |
||
| 96 | /* @var $zohoBean ZohoBeanInterface */ |
||
| 97 | if (isset($zohoBeans[$row['uid']])) { |
||
| 98 | $zohoBean = $zohoBeans[$row['uid']]; |
||
| 99 | } else { |
||
| 100 | $zohoBean = new $beanClassName(); |
||
| 101 | } |
||
| 102 | |||
| 103 | if (!$update) { |
||
| 104 | $this->insertDataZohoBean($zohoBean, $fieldsMatching, $row); |
||
| 105 | $zohoBeans[$row['uid']] = $zohoBean; |
||
| 106 | $rowsDeleted[] = $row['uid']; |
||
| 107 | } |
||
| 108 | if ($update && isset($row['updated_fieldname'])) { |
||
| 109 | $columnName = $row['updated_fieldname']; |
||
| 110 | $zohoBean->getZohoId() ?: $zohoBean->setZohoId($row['id']); |
||
| 111 | $this->updateDataZohoBean($zohoBean, $fieldsMatching, $columnName, $row[$columnName]); |
||
| 112 | $zohoBeans[$row['uid']] = $zohoBean; |
||
| 113 | $rowsDeleted[] = $row['uid']; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | $zohoDao->save($zohoBeans); |
||
| 117 | if (!$update) { |
||
| 118 | foreach ($zohoBeans as $uid => $zohoBean) { |
||
| 119 | $countResult = $this->connection->fetchColumn('select count(id) from '.$tableName.' where id = :id',['id'=>$zohoBean->getZohoId()]); |
||
| 120 | //If the sent data were duplicates Zoho can merged so we need to check if the Zoho ID already exist. |
||
| 121 | if($countResult === 0) { |
||
| 122 | // ID not exist we can update the new row with the Zoho ID |
||
| 123 | $this->connection->beginTransaction(); |
||
| 124 | $this->connection->update($tableName, ['id' => $zohoBean->getZohoId()], ['uid' => $uid]); |
||
| 125 | $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid ]); |
||
| 126 | $this->connection->commit(); |
||
| 127 | } else { |
||
| 128 | //ID already exist we need to delete the duplicate row. |
||
| 129 | $this->connection->beginTransaction(); |
||
| 130 | $this->connection->delete($tableName, ['uid' => $uid ]); |
||
| 131 | $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid ]); |
||
| 132 | $this->connection->commit(); |
||
| 133 | |||
| 134 | } |
||
| 135 | } |
||
| 136 | } else { |
||
| 137 | $this->connection->executeUpdate('delete from local_update where uid in ( :rowsDeleted)', |
||
| 138 | [ |
||
| 139 | 'rowsDeleted' => $rowsDeleted, |
||
| 140 | ], |
||
| 141 | [ |
||
| 142 | 'rowsDeleted' => Connection::PARAM_INT_ARRAY, |
||
| 143 | ] |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 264 |
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.