From b6316dbe3e24760351cfa25c8224dd98117f8e89 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 3 Jul 2019 10:57:43 +0200 Subject: [PATCH 1/2] Test that a PhpParameter is created without explicit setNullable definition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …when generateNullableTypes is enabled --- tests/generator/ParameterGeneratorTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/generator/ParameterGeneratorTest.php b/tests/generator/ParameterGeneratorTest.php index ab7bb0d..3b69c84 100644 --- a/tests/generator/ParameterGeneratorTest.php +++ b/tests/generator/ParameterGeneratorTest.php @@ -103,6 +103,13 @@ public function testPhp73Nullable() { $this->assertEquals('?float $foo', $generator->generate($param)); } + public function testPhp73NullableDefaultsToFalseWhenUnset() { + $generator = new ModelGenerator(['generateScalarTypeHints' => true, 'generateNullableTypes' => true]); + + $param = PhpParameter::create('foo')->setType('float'); + $this->assertEquals('float $foo', $generator->generate($param)); + } + public function testValues() { $generator = new ModelGenerator(); From b0ad7115cd44a7fd68c1f256016d465f2be5eaf5 Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 6 Jun 2019 16:58:36 +0200 Subject: [PATCH 2/2] Use nullable return type for TypePart::getTypeNullable() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to prevent a fatal error when setNullable has not been called explicitly, when generateNullableTypes is enabled. Error was: PHP Fatal error: Uncaught TypeError: Return value of gossi\codegen\model\PhpParameter::getNullable() must be of the type bool, null returned in […]/vendor/gossi/php-code-generator/src/model/parts/TypePart.php:75 --- src/model/parts/TypePart.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/model/parts/TypePart.php b/src/model/parts/TypePart.php index 881221a..84159c9 100644 --- a/src/model/parts/TypePart.php +++ b/src/model/parts/TypePart.php @@ -71,7 +71,7 @@ public function getTypeDescription(): ?string { * * @return bool */ - public function getNullable(): bool { + public function getNullable(): ?bool { return $this->typeNullable; }