| Conditions | 10 |
| Paths | 13 |
| Total Lines | 54 |
| Code Lines | 36 |
| 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 |
||
| 69 | public function handle(): int |
||
| 70 | { |
||
| 71 | $access = $this->haveAccess(); |
||
| 72 | if (false === $access) { |
||
| 73 | $this->error('Could not connect to your local Firefly III instance.'); |
||
| 74 | |||
| 75 | return 1; |
||
| 76 | } |
||
| 77 | |||
| 78 | $this->info(sprintf('Welcome to the Firefly III bunq importer, v%s', config('bunq.version'))); |
||
| 79 | app('log')->debug(sprintf('Now in %s', __METHOD__)); |
||
| 80 | $config = $this->argument('config'); |
||
| 81 | |||
| 82 | if (!file_exists($config) || (file_exists($config) && !is_file($config))) { |
||
| 83 | $message = sprintf('The importer can\'t import: configuration file "%s" does not exist or could not be read.', $config); |
||
| 84 | $this->error($message); |
||
| 85 | app('log')->error($message); |
||
| 86 | |||
| 87 | return 1; |
||
| 88 | } |
||
| 89 | $jsonResult = $this->verifyJSON($config); |
||
| 90 | if (false === $jsonResult) { |
||
| 91 | $message = 'The importer can\'t import: could not decode the JSON in the config file.'; |
||
| 92 | $this->error($message); |
||
| 93 | |||
| 94 | return 1; |
||
| 95 | } |
||
| 96 | $configuration = json_decode(file_get_contents($config), true, 512, JSON_THROW_ON_ERROR); |
||
| 97 | |||
| 98 | $this->line('The import routine is about to start.'); |
||
| 99 | $this->line('This is invisible and may take quite some time.'); |
||
| 100 | $this->line('Once finished, you will see a list of errors, warnings and messages (if applicable).'); |
||
| 101 | $this->line('--------'); |
||
| 102 | $this->line('Running...'); |
||
| 103 | $result = $this->startDownload($configuration); |
||
| 104 | if (0 === $result) { |
||
| 105 | $this->line('Download from bunq complete.'); |
||
| 106 | } |
||
| 107 | if (0 !== $result) { |
||
| 108 | $this->warn('Download from bunq resulted in errors.'); |
||
| 109 | |||
| 110 | return $result; |
||
| 111 | } |
||
| 112 | $secondResult = $this->startSync($configuration); |
||
| 113 | if (0 === $secondResult) { |
||
| 114 | $this->line('Sync to Firefly III complete.'); |
||
| 115 | } |
||
| 116 | if (0 !== $secondResult) { |
||
| 117 | $this->warn('Sync to Firefly III resulted in errors.'); |
||
| 118 | |||
| 119 | return $secondResult; |
||
| 120 | } |
||
| 121 | |||
| 122 | return 0; |
||
| 123 | } |
||
| 125 |