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