| Conditions | 5 |
| Paths | 3 |
| Total Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 | try { |
||
| 48 | $this->client->indices()->create([ |
||
| 49 | 'index' => $indexName, |
||
| 50 | ]); |
||
| 51 | } catch (Throwable $exception) { |
||
| 52 | $this->output->writeln( |
||
| 53 | sprintf( |
||
| 54 | '<error>Error creating index %s, exception message: %s.</error>', |
||
| 55 | $indexName, |
||
| 56 | $exception->getMessage() |
||
| 57 | ) |
||
| 58 | ); |
||
| 59 | |||
| 60 | return self::FAILURE; |
||
| 61 | } |
||
| 62 | |||
| 63 | $this->output->writeln( |
||
| 64 | sprintf( |
||
| 65 | '<info>Index %s created.</info>', |
||
| 66 | $indexName |
||
| 67 | ) |
||
| 68 | ); |
||
| 69 | |||
| 70 | return self::SUCCESS; |
||
| 71 | } |
||
| 72 | } |
||
| 73 |