| Conditions | 6 |
| Paths | 4 |
| Total Lines | 53 |
| 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 |
||
| 32 | public function handle(): int |
||
| 33 | { |
||
| 34 | $indexName = $this->argument('index-name'); |
||
| 35 | |||
| 36 | if ($indexName === null || |
||
| 37 | !is_string($indexName) || |
||
| 38 | mb_strlen($indexName) === 0 |
||
| 39 | ) { |
||
| 40 | $this->output->writeln( |
||
| 41 | '<error>Argument index-name must be a non empty string.</error>' |
||
| 42 | ); |
||
| 43 | |||
| 44 | return self::FAILURE; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!$this->client->indices()->exists([ |
||
| 48 | 'index' => $indexName, |
||
| 49 | ])) { |
||
| 50 | $this->output->writeln( |
||
| 51 | sprintf( |
||
| 52 | '<error>Index %s doesn\'t exists and cannot be deleted.</error>', |
||
| 53 | $indexName |
||
| 54 | ) |
||
| 55 | ); |
||
| 56 | |||
| 57 | return self::FAILURE; |
||
| 58 | } |
||
| 59 | |||
| 60 | try { |
||
| 61 | $this->client->indices()->delete([ |
||
| 62 | 'index' => $this->argument('index-name'), |
||
| 63 | ]); |
||
| 64 | } catch (Throwable $exception) { |
||
| 65 | $this->output->writeln( |
||
| 66 | sprintf( |
||
| 67 | '<error>Error deleting index %s, exception message: %s.</error>', |
||
| 68 | $indexName, |
||
| 69 | $exception->getMessage() |
||
| 70 | ) |
||
| 71 | ); |
||
| 72 | |||
| 73 | return self::FAILURE; |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->output->writeln( |
||
| 77 | sprintf( |
||
| 78 | '<info>Index %s deleted.</info>', |
||
| 79 | $indexName |
||
| 80 | ) |
||
| 81 | ); |
||
| 82 | |||
| 83 | return self::SUCCESS; |
||
| 84 | } |
||
| 85 | } |
||
| 86 |