build/generate-known-translation-apis: fixed incorrect positional parameter order

closes #4639
This commit is contained in:
Dylan K. Taylor 2021-12-11 21:28:52 +00:00
parent ede07c4314
commit e06eefeab0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 8 additions and 2 deletions

View File

@ -41,6 +41,7 @@ use function preg_match_all;
use function str_replace;
use function strtoupper;
use const INI_SCANNER_RAW;
use const SORT_NUMERIC;
use const SORT_STRING;
use const STDERR;
@ -142,15 +143,20 @@ HEADER;
$translationContainerClass = (new \ReflectionClass(Translatable::class))->getShortName();
foreach(Utils::stringifyKeys($languageDefinitions) as $key => $value){
$parameters = [];
$allParametersPositional = true;
if(preg_match_all($parameterRegex, $value, $matches) > 0){
foreach($matches[1] as $parameterName){
if(is_numeric($parameterName)){
$parameters[$parameterName] = "param$parameterName";
}else{
$parameters[$parameterName] = $parameterName;
$allParametersPositional = false;
}
}
}
if($allParametersPositional){
ksort($parameters, SORT_NUMERIC);
}
echo "\tpublic static function " .
functionify($key) .
"(" . implode(", ", array_map(fn(string $paramName) => "$translationContainerClass|string \$$paramName", $parameters)) . ") : $translationContainerClass{\n";

View File

@ -244,10 +244,10 @@ final class KnownTranslationFactory{
return new Translatable(KnownTranslationKeys::COMMANDS_ENCHANT_USAGE, []);
}
public static function commands_gamemode_success_other(Translatable|string $param1, Translatable|string $param0) : Translatable{
public static function commands_gamemode_success_other(Translatable|string $param0, Translatable|string $param1) : Translatable{
return new Translatable(KnownTranslationKeys::COMMANDS_GAMEMODE_SUCCESS_OTHER, [
1 => $param1,
0 => $param0,
1 => $param1,
]);
}