Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit e49f0ed

Browse files
committed
Set null type implicitly for nullable paramater definition
1 parent bf92724 commit e49f0ed

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Specs/Builder/ParameterSpecBuilder.php

+5
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ protected function buildOptionalParameterSpec(array $matches, ?string $default):
143143
}
144144
}
145145

146+
if ($this->hasNullable($matches)) {
147+
// nullable means that null is a valid value and thus we should explicitly enable null extractor here
148+
$matches['type'] = 'null|' . $matches['type'];
149+
}
150+
146151
return new OptionalParameterSpec($matches['name'], $this->extractor->build($matches['type']), $default);
147152
}
148153

tests/Specs/Builder/ParameterSpecBuilderTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function testBuildingNullableParameterWithDefaultValueShouldThrowExceptio
199199

200200
public function testBuildingNullableParameter()
201201
{
202-
$this->extractorDefinitionShouldBuildOn('type');
202+
$this->extractorDefinitionShouldBuildOn('null|type');
203203

204204
$spec = $this->builder->build('param? : type');
205205

@@ -255,7 +255,7 @@ public function testBuildingParameterWithBoolFalseTypeGuessing()
255255
public function testBuildingParameterWithNullableTypeGuessing()
256256
{
257257
$this->argumentDefinitionShouldBuildOn('null');
258-
$this->extractorDefinitionShouldBuildOn('any');
258+
$this->extractorDefinitionShouldBuildOn('null|any');
259259

260260
$spec = $this->builder->build('param?');
261261

0 commit comments

Comments
 (0)