Skip to content

Commit

Permalink
Do this in one write.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Aug 20, 2024
1 parent 5a6c9ee commit b51e180
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tests/mu-plugins/mu-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ function save_external_schema( string $url, string $name, array $path = [] ) : v
}
}

function set_schema_field( string $filename, string $key, mixed $value ) : void {
/**
* @param array<string, mixed> $values
*/
function set_schema_fields( string $filename, array $values ) : void {
$target = dirname( ABSPATH, 2 ) . "/" . $filename;
$file = file_get_contents( $target );

Expand All @@ -191,7 +194,9 @@ function set_schema_field( string $filename, string $key, mixed $value ) : void
throw new \Exception( "Failed to parse {$filename} schema." );
}

$data[ $key ] = $value;
foreach ( $values as $key => $value ) {
$data[ $key ] = $value;
}

$json = json_encode( $data, JSON_PRETTY_PRINT ^ JSON_UNESCAPED_SLASHES );

Expand Down
9 changes: 7 additions & 2 deletions tests/output/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
$constants = $reflection->getConstants();
$file = 'schemas/rest-api/properties/http-status-code.json';

set_schema_field( $file, 'tsEnumNames', array_keys( $constants ) );
set_schema_field( $file, 'enum', array_values( $constants ) );
set_schema_fields(
$file,
[
'tsEnumNames' => array_keys( $constants ),
'enum' => array_values( $constants ),
]
);

0 comments on commit b51e180

Please sign in to comment.