Skip to content

Commit

Permalink
Restore the original if/elseif structure in autogenerate_models
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Mar 17, 2024
1 parent 8ddb3c8 commit 7174d72
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/WordPress/Blueprints/bin/autogenerate_models.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ function fixTypeHint( string $typeHint, array $replacements ): string {

$schema = $janeProperty->getObject();
if ( $schema instanceof JsonSchema ) {
// Don't set "null" as the default value since it's already a default
// value of all class properties.
if ( $schema->getDefault() !== null ) {
$property->setValue( $schema->getDefault() );
}
if ( $schema->getConst() ) {
$property->setValue( $schema->getConst() );
// Assume that a class with an interface uses a const property
Expand All @@ -214,6 +209,10 @@ function fixTypeHint( string $typeHint, array $replacements ): string {
// So, we have to manually set it back to null.
$class->getConstants()['DISCRIMINATOR']->setVisibility( null );
}
} elseif ( $schema->getDefault() !== null ) {
// Don't set "null" as the default value since it's already a default
// value of all class properties.
$property->setValue( $schema->getDefault() );
} elseif ( $schema->getType() === 'array' ) {
$property->setValue( [] );
}
Expand Down

0 comments on commit 7174d72

Please sign in to comment.