| @@ -15,9 +15,8 @@ | ||
| 15 | 15 | * \YayCommerce\AdminShell\VersionedLoader::register('1.2.0', function() { |
| 16 | 16 | * \YayCommerce\AdminShell\AdminShell::boot(); |
| 17 | 17 | * }); |
| 18 | 18 | * }, 0); |
| 19 | - * @internal | |
| 20 | 19 | */ |
| 21 | 20 | class VersionedLoader |
| 22 | 21 | { |
| 23 | 22 | /** @var array<string, callable> version => boot callback */ |
| @@ -33,9 +32,9 @@ | ||
| 33 | 32 | * |
| 34 | 33 | * @param string $version Semver string, e.g. '1.2.0' |
| 35 | 34 | * @param callable $callback Boot callback — called only if this version wins. |
| 36 | 35 | */ |
| 37 | - public static function register(string $version, callable $callback) : void | |
| 36 | + public static function register(string $version, callable $callback): void | |
| 38 | 37 | { |
| 39 | 38 | // First-wins: do not overwrite an already-registered version. |
| 40 | 39 | if (isset(self::$candidates[$version])) { |
| 41 | 40 | return; |
| @@ -50,9 +49,9 @@ | ||
| 50 | 49 | /** |
| 51 | 50 | * Run after all plugins_loaded hooks. Pick highest version and invoke its callback. |
| 52 | 51 | * Idempotent — second call is a no-op. |
| 53 | 52 | */ |
| 54 | - public static function elect() : void | |
| 53 | + public static function elect(): void | |
| 55 | 54 | { |
| 56 | 55 | if (self::$elected || empty(self::$candidates)) { |
| 57 | 56 | return; |
| 58 | 57 | } |
| @@ -57,10 +56,10 @@ | ||
| 57 | 56 | return; |
| 58 | 57 | } |
| 59 | 58 | self::$elected = \true; |
| 60 | 59 | $winner = null; |
| 61 | - foreach (\array_keys(self::$candidates) as $version) { | |
| 62 | - if ($winner === null || \version_compare($version, $winner, '>')) { | |
| 60 | + foreach (array_keys(self::$candidates) as $version) { | |
| 61 | + if ($winner === null || version_compare($version, $winner, '>')) { | |
| 63 | 62 | $winner = $version; |
| 64 | 63 | } |
| 65 | 64 | } |
| 66 | 65 | if ($winner !== null && isset(self::$candidates[$winner])) { |
| @@ -69,16 +68,16 @@ | ||
| 69 | 68 | } |
| 70 | 69 | /** |
| 71 | 70 | * Return the winning version string, or null if election hasn't run. |
| 72 | 71 | */ |
| 73 | - public static function get_elected_version() : ?string | |
| 72 | + public static function get_elected_version(): ?string | |
| 74 | 73 | { |
| 75 | 74 | if (!self::$elected || empty(self::$candidates)) { |
| 76 | 75 | return null; |
| 77 | 76 | } |
| 78 | 77 | $winner = null; |
| 79 | - foreach (\array_keys(self::$candidates) as $version) { | |
| 80 | - if ($winner === null || \version_compare($version, $winner, '>')) { | |
| 78 | + foreach (array_keys(self::$candidates) as $version) { | |
| 79 | + if ($winner === null || version_compare($version, $winner, '>')) { | |
| 81 | 80 | $winner = $version; |
| 82 | 81 | } |
| 83 | 82 | } |
| 84 | 83 | return $winner; |
| @@ -85,9 +84,9 @@ | ||
| 85 | 84 | } |
| 86 | 85 | /** |
| 87 | 86 | * Reset state — only for unit tests. |
| 88 | 87 | */ |
| 89 | - public static function reset() : void | |
| 88 | + public static function reset(): void | |
| 90 | 89 | { |
| 91 | 90 | self::$candidates = []; |
| 92 | 91 | self::$elected = \false; |
| 93 | 92 | } |