| Conditions | 12 |
| Paths | 10 |
| Total Lines | 51 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 41 | private function startImport(string $csv, array $configuration): int |
||
| 42 | { |
||
| 43 | Log::debug(sprintf('Now in %s', __METHOD__)); |
||
| 44 | $configObject = Configuration::fromFile($configuration); |
||
| 45 | $manager = new ImportRoutineManager; |
||
| 46 | |||
| 47 | try { |
||
| 48 | $manager->setConfiguration($configObject); |
||
| 49 | } catch (ImportException $e) { |
||
| 50 | $this->error($e->getMessage()); |
||
|
|
|||
| 51 | |||
| 52 | return 1; |
||
| 53 | } |
||
| 54 | $manager->setReader(FileReader::getReaderFromContent($csv)); |
||
| 55 | try { |
||
| 56 | $manager->start(); |
||
| 57 | } catch (ImportException $e) { |
||
| 58 | $this->error($e->getMessage()); |
||
| 59 | |||
| 60 | return 1; |
||
| 61 | } |
||
| 62 | |||
| 63 | $messages = $manager->getAllMessages(); |
||
| 64 | $warnings = $manager->getAllWarnings(); |
||
| 65 | $errors = $manager->getAllErrors(); |
||
| 66 | |||
| 67 | if (count($errors) > 0) { |
||
| 68 | foreach ($errors as $index => $error) { |
||
| 69 | foreach ($error as $line) { |
||
| 70 | $this->error(sprintf('ERROR in line #%d: %s', $index + 1, $line)); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if (count($warnings) > 0) { |
||
| 76 | foreach ($warnings as $index => $warning) { |
||
| 77 | foreach ($warning as $line) { |
||
| 78 | $this->warn(sprintf('Warning from line #%d: %s', $index + 1, $line)); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (count($messages) > 0) { |
||
| 84 | foreach ($messages as $index => $message) { |
||
| 85 | foreach ($message as $line) { |
||
| 86 | $this->info(sprintf('Message from line #%d: %s', $index + 1, strip_tags($line))); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return 0; |
||
| 92 | } |
||
| 93 | } |