| Conditions | 13 |
| Paths | 52 |
| Total Lines | 60 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 76 | public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){ |
||
| 77 | |||
| 78 | $fieldsMatching = $this->findMethodValues($zohoDao); |
||
| 79 | $tableName = ZohoDatabaseHelper::getTableName($zohoDao,$this->prefix); |
||
| 80 | $rowsDeleted = []; |
||
| 81 | $statement = $this->connection->createQueryBuilder(); |
||
| 82 | $statement->select('zcrm.*'); |
||
| 83 | if($update){ |
||
| 84 | $statement->addSelect('l.field_name as updated_fieldname'); |
||
| 85 | } |
||
| 86 | $statement->from($localTable, 'l') |
||
| 87 | ->join('l', $tableName, 'zcrm', 'zcrm.uid = l.uid') |
||
| 88 | ->where('l.table_name=:table_name') |
||
| 89 | ->setParameters([ |
||
| 90 | 'table_name' => $tableName |
||
| 91 | ]); |
||
| 92 | $results = $statement->execute(); |
||
| 93 | /* @var $zohoBeans ZohoBeanInterface[] */ |
||
| 94 | $zohoBeans = array(); |
||
| 95 | while ($row = $results->fetch()) { |
||
| 96 | $beanClassName = $zohoDao->getBeanClassName(); |
||
| 97 | /* @var $zohoBean ZohoBeanInterface */ |
||
| 98 | if(isset($zohoBeans[$row['uid']])){ |
||
| 99 | $zohoBean = $zohoBeans[$row['uid']]; |
||
| 100 | }else{ |
||
| 101 | $zohoBean = new $beanClassName(); |
||
| 102 | } |
||
| 103 | if(!$update){ |
||
| 104 | foreach ($row as $columnName => $columnValue) { |
||
| 105 | if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) { |
||
| 106 | $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $columnValue, null, $row['uid']); |
||
| 107 | if($columnValue){ |
||
| 108 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | $zohoBeans[$row['uid']] = $zohoBean; |
||
| 113 | $rowsDeleted[] = $row['uid']; |
||
| 114 | } else{ |
||
| 115 | $columnName = $row['updated_fieldname']; |
||
| 116 | $zohoBean->setZohoId($row['id']); |
||
| 117 | if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) { |
||
| 118 | $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $row[$columnName], $row['id']); |
||
| 119 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
||
| 120 | $zohoBeans[$row['uid']] = $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 | |||
| 225 | } |
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.