| Conditions | 17 |
| Paths | 96 |
| Total Lines | 53 |
| Lines | 9 |
| Ratio | 16.98 % |
| Changes | 0 | ||
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 |
||
| 57 | public function onRow(Row $row) |
||
| 58 | { |
||
| 59 | $rowIndex = $row->getIndex(); |
||
|
|
|||
| 60 | $row = $row->toArray(); |
||
| 61 | |||
| 62 | $newData = array(); |
||
| 63 | $updatedData = array(); |
||
| 64 | |||
| 65 | $hasNotNULL = false; |
||
| 66 | //check not NULL columns |
||
| 67 | foreach ($this->notNullColumnNames as $notNullColumn) { |
||
| 68 | //if there is not the column in the row |
||
| 69 | if (!isset($row[$notNullColumn])) { |
||
| 70 | $hasNotNULL = true; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!empty($row[$this->key])) { |
||
| 75 | $exists = $this->model->where($this->key, '=', $row[$this->key])->count(); |
||
| 76 | if (!$exists && !$hasNotNULL) { |
||
| 77 | $values = array(); |
||
| 78 | View Code Duplication | foreach ($this->columns as $col) { |
|
| 79 | if ($col != $this->key && array_key_exists($col, $row)) { |
||
| 80 | $values[$col] = $row[$col]; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | $newData[] = $values; |
||
| 84 | } else if ($this->status == 2 && $exists) { |
||
| 85 | $values = array(); |
||
| 86 | View Code Duplication | foreach ($this->columns as $col) { |
|
| 87 | if (array_key_exists($col, $row)) |
||
| 88 | $values[$col] = $row[$col]; |
||
| 89 | } |
||
| 90 | $updatedData[] = $values; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | // insert data into table |
||
| 95 | if (!empty($newData)) { |
||
| 96 | $this->model->insert($newData); |
||
| 97 | } |
||
| 98 | |||
| 99 | // update available data |
||
| 100 | if (!empty($updatedData)) { |
||
| 101 | foreach ($updatedData as $data) { |
||
| 102 | $keyValue = (int)$data[$this->key]; |
||
| 103 | unset($data[$this->key]); |
||
| 104 | try{ |
||
| 105 | $this->model->where($this->key, $keyValue)->update($data); |
||
| 106 | }catch (\Exception $e){} |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.