Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.45% |
21 / 22 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ManifestValidator | |
95.24% |
20 / 21 |
|
0.00% |
0 / 1 |
8 | |
0.00% |
0 / 1 |
| validate | |
95.24% |
20 / 21 |
|
0.00% |
0 / 1 |
8 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Core\Updater\Validator; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Updater\Dto\UpdateManifestDto; |
| 12 | |
| 13 | /** |
| 14 | * Validates update manifest specifications against current runtime environment and system version. |
| 15 | * |
| 16 | * @package App\Core\Updater\Validator |
| 17 | */ |
| 18 | final class ManifestValidator |
| 19 | { |
| 20 | /** |
| 21 | * Validates manifest requirements against current environment. |
| 22 | * |
| 23 | * @param UpdateManifestDto $manifest Parsed manifest DTO. |
| 24 | * @param string|null $currentSystemVersion Currently installed platform version (if known). |
| 25 | * @return list<string> List of validation error messages. Empty list indicates full compliance. |
| 26 | */ |
| 27 | public function validate(UpdateManifestDto $manifest, ?string $currentSystemVersion = null): array |
| 28 | { |
| 29 | $errors = []; |
| 30 | |
| 31 | if (trim($manifest->version) === '') { |
| 32 | $errors[] = 'Target release version cannot be empty.'; |
| 33 | } |
| 34 | |
| 35 | if (version_compare(PHP_VERSION, $manifest->phpMin, '<')) { |
| 36 | $errors[] = sprintf( |
| 37 | 'PHP version %s does not meet the minimum required version %s.', |
| 38 | PHP_VERSION, |
| 39 | $manifest->phpMin |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | foreach ($manifest->requiredExtensions as $ext) { |
| 44 | if (!extension_loaded($ext)) { |
| 45 | $errors[] = sprintf('Required PHP extension "%s" is not installed or enabled.', $ext); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | if ( |
| 50 | $manifest->fromVersion !== null |
| 51 | && $currentSystemVersion !== null |
| 52 | && version_compare($currentSystemVersion, $manifest->fromVersion, '<') |
| 53 | ) { |
| 54 | $errors[] = sprintf( |
| 55 | 'Installed system version %s is lower than required upgrade baseline %s.', |
| 56 | $currentSystemVersion, |
| 57 | $manifest->fromVersion |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | return $errors; |
| 62 | } |
| 63 | } |