| Conditions | 7 |
| Paths | 2 |
| Total Lines | 32 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | public static function getNextAvailableVariableName($variable, array $usedVariables) |
||
| 16 | { |
||
| 17 | $variable = self::toVariableName($variable); |
||
| 18 | while (true) { |
||
| 19 | // check that the name is not reserved |
||
| 20 | if (!in_array($variable, $usedVariables, true)) { |
||
| 21 | break; |
||
| 22 | } |
||
| 23 | |||
| 24 | $numbers = ''; |
||
| 25 | while (true) { |
||
| 26 | $lastCharacter = substr($variable, strlen($variable) - 1); |
||
| 27 | if ($lastCharacter >= '0' && $lastCharacter <= '9') { |
||
| 28 | $numbers = $lastCharacter.$numbers; |
||
| 29 | $variable = substr($variable, 0, strlen($variable) - 1); |
||
| 30 | } else { |
||
| 31 | break; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($numbers === '') { |
||
| 36 | $numbers = 0; |
||
| 37 | } else { |
||
| 38 | $numbers = (int) $numbers; |
||
| 39 | } |
||
| 40 | ++$numbers; |
||
| 41 | |||
| 42 | $variable = $variable.$numbers; |
||
| 43 | } |
||
| 44 | |||
| 45 | return $variable; |
||
| 46 | } |
||
| 47 | |||
| 69 |