| Conditions | 16 |
| Paths | 16 |
| Total Lines | 110 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 65 | public function handle() |
||
| 66 | { |
||
| 67 | $timer = new \DateTime(); |
||
| 68 | $this->setFormproperties(); |
||
| 69 | $this->setLanguage(); |
||
| 70 | $vocabId = $this->isElementSet() ? $this->import->schema_id : $this->import->vocabulary_id; |
||
| 71 | $changeset = $this->import->instructions; |
||
| 72 | $total_processed = 0; |
||
| 73 | $added = 0; |
||
| 74 | $updated = 0; |
||
| 75 | $deleted = 0; |
||
| 76 | //each item in the main array is a row. Each item in the statements array is a statement |
||
| 77 | foreach ($changeset['update'] as $reg_id => $row) { |
||
| 78 | $this->updatedStatements = []; |
||
| 79 | //start a transaction |
||
| 80 | DB::transaction(function () use ($reg_id, $row, &$updated) { |
||
| 81 | $statements = $this->getStatements($reg_id); |
||
| 82 | $dirty = false; |
||
| 83 | foreach ($row as $statement) { |
||
| 84 | $old = $statements->find($statement['statement_id']); |
||
| 85 | if ($old) { |
||
| 86 | if ($statement['new value']) { |
||
| 87 | $old->update([ |
||
| 88 | 'object' => $statement['new value'], |
||
| 89 | 'last_import_id' => $this->import->id, |
||
| 90 | 'is_generated' => false, |
||
| 91 | ]); |
||
| 92 | $this->addUpdateStatement($statement); |
||
| 93 | $dirty = true; |
||
| 94 | } else { |
||
| 95 | $old->delete(); |
||
| 96 | $this->addUpdateStatement($statement); |
||
| 97 | $dirty = true; |
||
| 98 | } |
||
| 99 | } else { |
||
| 100 | //make a new one |
||
| 101 | $existingStatement = $statements->filter(function ($item) use ($statement) { |
||
| 102 | /* @var Model $item */ |
||
| 103 | return $item->profile_property_id == $statement['property_id'] && |
||
| 104 | $item->object == $statement['new value'] && |
||
| 105 | $item->getOriginal('language') === $statement['language']; |
||
| 106 | }); |
||
| 107 | if ($existingStatement->count() === 0) { |
||
| 108 | $newStatement = $this->makeStatement($statement); |
||
| 109 | $this->resource->statements()->save($newStatement); |
||
|
|
|||
| 110 | $this->addUpdateStatement($statement); |
||
| 111 | $dirty = true; |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | if (count($this->updatedStatements)) { |
||
| 116 | try { |
||
| 117 | $this->resource->updateFromStatements($this->updatedStatements); |
||
| 118 | } catch (Exception $e) { |
||
| 119 | //log the error |
||
| 120 | $this->makeErrorLogEntry($row['*uri']['new value'], $e->getMessage()); |
||
| 121 | //cancel the transaction |
||
| 122 | return false; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | if ($dirty) { |
||
| 126 | $updated++; |
||
| 127 | } |
||
| 128 | }); |
||
| 129 | $total_processed++; |
||
| 130 | } |
||
| 131 | foreach ($changeset['add'] as $row) { |
||
| 132 | DB::transaction(function () use ($row, $vocabId, &$added) { |
||
| 133 | $allStatements = []; |
||
| 134 | foreach ($row as $statement) { |
||
| 135 | $this->addUpdateStatement($statement); |
||
| 136 | $allStatements[] = $this->makeStatement($statement); |
||
| 137 | } |
||
| 138 | try { |
||
| 139 | //this will make a resource with insufficient values... |
||
| 140 | $resource = $this->makeResource($vocabId); |
||
| 141 | //this will update the resource from the statements and save it... |
||
| 142 | $resource->updateFromStatements($this->updatedStatements); |
||
| 143 | //this will add the statements... |
||
| 144 | $resource->statements()->saveMany($allStatements); |
||
| 145 | $this->UpdatePrefLabelId($resource); |
||
| 146 | } catch (Exception $e) { |
||
| 147 | //log the error |
||
| 148 | $this->makeErrorLogEntry($row['*uri']['new value'], $e->getMessage()); |
||
| 149 | //cancel the transaction |
||
| 150 | return false; |
||
| 151 | } |
||
| 152 | |||
| 153 | $added++; |
||
| 154 | }); |
||
| 155 | $total_processed++; |
||
| 156 | } |
||
| 157 | foreach ($changeset['delete'] as $row) { |
||
| 158 | //TODO implement this... |
||
| 159 | //delete the resource |
||
| 160 | //cascade delete the statements, which should cascade delete the reciprocals |
||
| 161 | $total_processed++; |
||
| 162 | $deleted++; |
||
| 163 | } |
||
| 164 | $this->setResults('timer', $timer->diff(new \DateTime())->format('%h hours; %i minutes; %s seconds')); |
||
| 165 | $this->import->results = $this->results; |
||
| 166 | $this->import->batch->increment('handled_count'); |
||
| 167 | $this->import->total_processed_count = $total_processed; |
||
| 168 | $this->import->added_count = $added; |
||
| 169 | $this->import->updated_count = $updated; |
||
| 170 | $this->import->deleted_count = $deleted; |
||
| 171 | $this->import->imported_at = new \DateTime(); |
||
| 172 | $this->import->save(); |
||
| 173 | |||
| 174 | event(new ImportFinished($this->import)); |
||
| 175 | } |
||
| 288 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.