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 |
||
71 | public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){ |
||
72 | |||
73 | $fieldsMatching = $this->findMethodValues($zohoDao); |
||
74 | $tableName = $this->getTableName($zohoDao); |
||
75 | $rowsDeleted = []; |
||
76 | $statement = $this->connection->createQueryBuilder(); |
||
77 | $statement->select('zcrm.*'); |
||
78 | if($update){ |
||
79 | $statement->addSelect('l.field_name as updated_fieldname'); |
||
80 | } |
||
81 | $statement->from($localTable, 'l') |
||
82 | ->join('l', $tableName, 'zcrm', 'zcrm.uid = l.uid') |
||
83 | ->where('l.table_name=:table_name') |
||
84 | ->setParameters([ |
||
85 | 'table_name' => $tableName |
||
86 | ]); |
||
87 | $results = $statement->execute(); |
||
88 | /* @var $zohoBeans ZohoBeanInterface[] */ |
||
89 | $zohoBeans = array(); |
||
90 | while ($row = $results->fetch()) { |
||
91 | $beanClassName = $zohoDao->getBeanClassName(); |
||
92 | /* @var $zohoBean ZohoBeanInterface */ |
||
93 | $zohoBean = new $beanClassName(); |
||
94 | if(!$update){ |
||
95 | foreach ($row as $columnName => $columnValue) { |
||
96 | if (in_array($columnName,['id','uid'])) { |
||
97 | continue; |
||
98 | }else{ |
||
99 | if($columnValue){ |
||
100 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | } |
||
105 | $zohoBeans[$row['uid']] = $zohoBean; |
||
106 | $rowsDeleted[] = $row['uid']; |
||
107 | } else{ |
||
108 | $columnName = $row['updated_fieldname']; |
||
109 | $zohoBean->setZohoId($row['id']); |
||
110 | if (in_array($columnName,['uid'])) { |
||
111 | continue; |
||
112 | }else{ |
||
113 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($row[$columnName]); |
||
114 | $zohoBeans[] = $zohoBean; |
||
115 | $rowsDeleted[] = $row['uid']; |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | $zohoDao->save($zohoBeans); |
||
120 | if(!$update){ |
||
121 | foreach ($zohoBeans as $uid => $zohoBean) { |
||
122 | $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId(),'lastActivityTime'=> date("Y-m-d H:i:s") ], ['uid'=>$uid ]); |
||
123 | } |
||
124 | } |
||
125 | $statementDelete = $this->connection->prepare('delete from '.$localTable.' where uid in ( :rowsDeleted)'); |
||
126 | $statementDelete->execute([ |
||
127 | 'rowsDeleted' => implode(',', $rowsDeleted) |
||
128 | ]); |
||
129 | } |
||
130 | |||
201 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.