Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| VersionNormalizer | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| normalize | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | /** |
| 4 | * Clansuite Server Query |
| 5 | * |
| 6 | * SPDX-FileCopyrightText: 2003-2025 Jens A. Koch |
| 7 | * SPDX-License-Identifier: MIT |
| 8 | * |
| 9 | * For the full copyright and license information, please view |
| 10 | * the LICENSE file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Clansuite\Capture\Extractor; |
| 14 | |
| 15 | use function preg_replace; |
| 16 | use function trim; |
| 17 | |
| 18 | /** |
| 19 | * Normalizes version strings by replacing special characters with underscores for consistent formatting. |
| 20 | */ |
| 21 | class VersionNormalizer |
| 22 | { |
| 23 | /** |
| 24 | * normalize method. |
| 25 | */ |
| 26 | public function normalize(string $version): string |
| 27 | { |
| 28 | // Replace dots and other special chars with underscores |
| 29 | $normalized = preg_replace('/[^a-zA-Z0-9]/', '_', $version); |
| 30 | |
| 31 | // Remove multiple consecutive underscores |
| 32 | $normalized = preg_replace('/_+/', '_', (string) $normalized); |
| 33 | |
| 34 | // Remove leading/trailing underscores |
| 35 | $normalized = trim((string) $normalized, '_'); |
| 36 | |
| 37 | return 'v' . $normalized; |
| 38 | } |
| 39 | } |