| Conditions | 3 |
| Paths | 3 |
| Total Lines | 26 |
| Code Lines | 15 |
| Lines | 26 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | protected function processValue($value) |
||
| 25 | { |
||
| 26 | $data = file_get_contents($value['target_id']); |
||
| 27 | if (false === $data) { |
||
| 28 | throw new \Exception("Error reading file"); |
||
| 29 | } |
||
| 30 | |||
| 31 | /* @var \Drupal\file\FileInterface $file */ |
||
| 32 | $file = file_save_data( |
||
| 33 | $data, |
||
| 34 | 'public://' . uniqid() . '.jpg' |
||
| 35 | ); |
||
| 36 | |||
| 37 | if (false === $file) { |
||
| 38 | throw new \Exception("Error saving file"); |
||
| 39 | } |
||
| 40 | |||
| 41 | $file->save(); |
||
| 42 | |||
| 43 | $return = array( |
||
| 44 | 'target_id' => $file->id(), |
||
| 45 | 'alt' => 'Behat test image', |
||
| 46 | 'title' => 'Behat test image', |
||
| 47 | ); |
||
| 48 | return $return; |
||
| 49 | } |
||
| 50 | } |
||
| 51 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.