Skip to content

Commit

Permalink
Parameter & Property: isNullable() returns true when default value is…
Browse files Browse the repository at this point in the history
… null (possible BC break)
  • Loading branch information
dg committed Jun 18, 2024
1 parent c125c35 commit bb548ce
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/PhpGenerator/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function setNullable(bool $state = true): static

public function isNullable(): bool
{
return $this->nullable;
return $this->nullable || ($this->hasDefaultValue && $this->defaultValue === null);
}


Expand Down
2 changes: 1 addition & 1 deletion src/PhpGenerator/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function setNullable(bool $state = true): static

public function isNullable(): bool
{
return $this->nullable;
return $this->nullable || ($this->initialized && $this->value === null);
}


Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/expected/ClassType.expect
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class Example extends ParentClass implements IExample, IOne
public $order = RecursiveIteratorIterator::SELF_FIRST;
public readonly array $typed1;
public ?array $typed2 = null;
public array $typed3 = null;
public ?array $typed3 = null;
public static $sections = ['first' => true];


Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/expected/Extractor.bodies.expect
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class Class7
}


function resolving($a = a\FOO, self $b = null, $c = self::FOO)
function resolving($a = a\FOO, ?self $b = null, $c = self::FOO)
{
// constants
echo FOO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class Class7
}


function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
function resolving($a = \Abc\a\FOO, ?self $b = null, $c = self::FOO)
{
// constants
echo FOO;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class Class7
}


function resolving($a = \Abc\a\FOO, self $b = null, $c = self::FOO)
function resolving($a = \Abc\a\FOO, ?self $b = null, $c = self::FOO)
{
// constants
echo FOO;
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpGenerator/expected/Extractor.classes.expect
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Class2 extends Class1 implements Interface2
}


private function func4(array $a = [], Class2 $b = null, $c = Unknown::ABC)
private function func4(array $a = [], ?Class2 $b = null, $c = Unknown::ABC)
{
}

Expand All @@ -94,7 +94,7 @@ class Class4

class Class5
{
public function func1(\A $a, ?\B $b, ?\C $c = null, \D $d = null, ?int $i = 1, ?array $arr = [])
public function func1(\A $a, ?\B $b, ?\C $c = null, ?\D $d = null, ?int $i = 1, ?array $arr = [])
{
}

Expand Down

0 comments on commit bb548ce

Please sign in to comment.