Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /