Conditions | 11 |
Paths | 156 |
Total Lines | 61 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
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 | $this->connection->beginTransaction(); |
||
120 | $this->connection->update($tableName, ['id' => $zohoBean->getZohoId()], ['uid' => $uid]); |
||
121 | $this->connection->delete('local_insert', [ 'uid' => $uid ]); |
||
122 | $this->connection->commit(); |
||
123 | } |
||
124 | } else { |
||
125 | $this->connection->executeUpdate('delete from local_update where uid in ( :rowsDeleted)', |
||
126 | [ |
||
127 | 'rowsDeleted' => $rowsDeleted, |
||
128 | ], |
||
129 | [ |
||
130 | 'rowsDeleted' => Connection::PARAM_INT_ARRAY, |
||
131 | ] |
||
132 | ); |
||
133 | } |
||
134 | } |
||
135 | |||
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.