Skip to content

Commit

Permalink
Allow scalars by default null
Browse files Browse the repository at this point in the history
  • Loading branch information
kafkiansky committed Aug 16, 2024
1 parent c09a782 commit 1850063
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Internal/Code/PhpType.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function toPhpDoc(string $paramName): string
*/
public static function scalar(string $nativeType, ?string $phpDocType = null, null|bool|string|int $default = null): self
{
return new self($nativeType, $phpDocType, default: $default);
return new self($nativeType, $phpDocType, nullable: null === $default, default: $default);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions Internal/Code/Type/ScalarTypeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ final class ScalarTypeVisitor extends DefaultTypeVisitor
public function scalar(ProtoType $type, Scalar $scalar): PhpType
{
return match ($scalar) {
Scalar::bool => PhpType::scalar('bool', default: false),
Scalar::string => PhpType::scalar('string', default: ''),
Scalar::bytes => PhpType::scalar('string', 'bytes', ''),
Scalar::double => PhpType::scalar('float', 'double', 0),
Scalar::float => PhpType::scalar('float', default: 0),
default => PhpType::scalar('int', $scalar->value, 0),
Scalar::bool => PhpType::scalar('bool'),
Scalar::string => PhpType::scalar('string'),
Scalar::bytes => PhpType::scalar('string', 'bytes'),
Scalar::double => PhpType::scalar('float', 'double'),
Scalar::float => PhpType::scalar('float'),
default => PhpType::scalar('int', $scalar->value),
};
}
}

0 comments on commit 1850063

Please sign in to comment.