| Conditions | 10 |
| Paths | 28 |
| Total Lines | 59 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 77 | public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){ |
||
| 78 | |||
| 79 | $fieldsMatching = $this->findMethodValues($zohoDao); |
||
| 80 | $tableName = $this->getTableName($zohoDao); |
||
| 81 | $rowsDeleted = []; |
||
| 82 | $statement = $this->connection->createQueryBuilder(); |
||
| 83 | $statement->select('zcrm.*'); |
||
| 84 | if($update){ |
||
| 85 | $statement->addSelect('l.field_name as updated_fieldname'); |
||
| 86 | } |
||
| 87 | $statement->from($localTable, 'l') |
||
| 88 | ->join('l', $tableName, 'zcrm', 'zcrm.uid = l.uid') |
||
| 89 | ->where('l.table_name=:table_name') |
||
| 90 | ->setParameters([ |
||
| 91 | 'table_name' => $tableName |
||
| 92 | ]); |
||
| 93 | $results = $statement->execute(); |
||
| 94 | /* @var $zohoBeans ZohoBeanInterface[] */ |
||
| 95 | $zohoBeans = array(); |
||
| 96 | while ($row = $results->fetch()) { |
||
| 97 | $beanClassName = $zohoDao->getBeanClassName(); |
||
| 98 | /* @var $zohoBean ZohoBeanInterface */ |
||
| 99 | $zohoBean = new $beanClassName(); |
||
| 100 | if(!$update){ |
||
| 101 | foreach ($row as $columnName => $columnValue) { |
||
| 102 | if (in_array($columnName,['id','uid'])) { |
||
| 103 | continue; |
||
| 104 | }else{ |
||
| 105 | if($columnValue){ |
||
| 106 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | } |
||
| 111 | $zohoBeans[$row['uid']] = $zohoBean; |
||
| 112 | $rowsDeleted[] = $row['uid']; |
||
| 113 | } else{ |
||
| 114 | $columnName = $row['updated_fieldname']; |
||
| 115 | $zohoBean->setZohoId($row['id']); |
||
| 116 | if (in_array($columnName,['uid'])) { |
||
| 117 | continue; |
||
| 118 | }else{ |
||
| 119 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($row[$columnName]); |
||
| 120 | $zohoBeans[] = $zohoBean; |
||
| 121 | $rowsDeleted[] = $row['uid']; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | $zohoDao->save($zohoBeans); |
||
| 126 | if(!$update){ |
||
| 127 | foreach ($zohoBeans as $uid => $zohoBean) { |
||
| 128 | $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId(),'lastActivityTime'=> date("Y-m-d H:i:s") ], ['uid'=>$uid ]); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | $statementDelete = $this->connection->prepare('delete from '.$localTable.' where uid in ( :rowsDeleted)'); |
||
| 132 | $statementDelete->execute([ |
||
| 133 | 'rowsDeleted' => implode(',', $rowsDeleted) |
||
| 134 | ]); |
||
| 135 | } |
||
| 136 | |||
| 207 | } |
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.