| Conditions | 3 | 
| Paths | 4 | 
| Total Lines | 20 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php | ||
| 16 | public function getNextFreeIndex(IndexService $index, \DateTime $time = null): string | ||
| 17 |     { | ||
| 18 |         if ($time === null) { | ||
| 19 | $time = new \DateTime(); | ||
| 20 | } | ||
| 21 | |||
| 22 |         $date = $time->format('Y.m.d'); | ||
| 23 | $alias = $index->getIndexName(); | ||
| 24 | $indexName = $alias . '-' . $date; | ||
| 25 | $i = 0; | ||
| 26 | |||
| 27 | $client = $index->getClient(); | ||
| 28 | |||
| 29 |         while ($client->indices()->exists(['index' => $indexName])) { | ||
| 30 | $i++; | ||
| 31 |             $indexName = "{$indexName}-{$i}"; | ||
| 32 | } | ||
| 33 | |||
| 34 | return $indexName; | ||
| 35 | } | ||
| 36 | } | ||
| 37 |