[ "name" => trim($name), "type" => trim($type), "docs" => trim($docs), "default" => $default, ], ]; }, $f ?? []); $f = array_merge(...$f); return $f; }, $fields); $classes = array_combine($names, $fields); ksort($classes); // print_r($classes); // Files that have already been processed. // Uncomment to display the results again. $added = [ // "BisCompanyRegisteredOffice", // "BisCompanyRegisteredEntry", // "BisCompanyName", // "BisCompanyLiquidation", // "BisCompanyLanguage", // "BisCompanyForm", // "BisCompanyDetails", // "BisCompanyContactDetail", // "BisCompanyBusinessLine", // "BisCompanyBusinessIdChange", // "BisAddress", ]; // Output the classes as preformatted for easier copypasta. // This is not the prettiest way to generate the codes, but it works. foreach ($classes as $className => $vars) { if (in_array($className, $added)) { continue; } echo " /** * $className */ class $className extends DataTransferObject { "; if (array_key_exists("source", $vars)) { echo " use HasSource;\n"; } foreach ($vars as $varKey => $varData) { if ($varKey === "source") { continue; } $caster = ""; if (str_contains($varData["type"], "[")) { $classType = str_replace(["[", "]", "?"], "", $varData["type"]); $caster = "\n #[CastWith(Casters\ArrayCaster::class, itemType: {$classType}::class)]"; } $type = $varData["type"]; $typeHelper = ""; if (str_contains($type, "[")) { $type = str_contains($type, "?") ? "?array" : "array"; $typeHelper = "\n * @var {$varData["type"]} \${$varData["name"]}"; } $default = $varData["default"] !== null ? " = " . $varData["default"] . ";" : ";"; echo " /** * {$varData["docs"]}{$typeHelper} */{$caster} public {$type} \${$varData["name"]}{$default} "; } echo "\n}"; }