Skip to content

Commit

Permalink
Merge pull request #525 from ciaranmcnulty/false-types
Browse files Browse the repository at this point in the history
Support the false pseudotype, which cannot be nullable or standalone
  • Loading branch information
ciaranmcnulty authored Mar 17, 2021
2 parents 3f22964 + 2b882e1 commit 26ec19b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
25 changes: 25 additions & 0 deletions spec/Prophecy/Doubler/Generator/Node/ArgumentTypeNodeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,29 @@ function it_does_not_allow_union_mixed()
$this->shouldThrow(DoubleException::class)->duringInstantiation();
}
}

function it_does_not_prefix_false()
{
$this->beConstructedWith('false', 'array');

$this->getTypes()->shouldReturn(['false', 'array']);
}

function it_does_not_allow_standalone_false()
{
$this->beConstructedWith('false');

if (PHP_VERSION_ID >=80000) {
$this->shouldThrow(DoubleException::class)->duringInstantiation();
}
}

function it_does_not_allow_nullable_false()
{
$this->beConstructedWith('null', 'false');

if (PHP_VERSION_ID >=80000) {
$this->shouldThrow(DoubleException::class)->duringInstantiation();
}
}
}
25 changes: 25 additions & 0 deletions spec/Prophecy/Doubler/Generator/Node/ReturnTypeNodeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,29 @@ function it_knows_when_it_is_void()

$this->shouldBeVoid();
}

function it_does_not_prefix_false()
{
$this->beConstructedWith('false', 'array');

$this->getTypes()->shouldReturn(['false', 'array']);
}

function it_does_not_allow_standalone_false()
{
$this->beConstructedWith('false');

if (PHP_VERSION_ID >=80000) {
$this->shouldThrow(DoubleException::class)->duringInstantiation();
}
}

function it_does_not_allow_nullable_false()
{
$this->beConstructedWith('null', 'false');

if (PHP_VERSION_ID >=80000) {
$this->shouldThrow(DoubleException::class)->duringInstantiation();
}
}
}
11 changes: 10 additions & 1 deletion src/Prophecy/Doubler/Generator/Node/TypeNodeAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function getRealType(string $type): string
case 'array':
case 'callable':
case 'bool':
case 'false':
case 'float':
case 'int':
case 'string':
Expand All @@ -77,7 +78,15 @@ protected function getRealType(string $type): string
protected function guardIsValidType()
{
if ($this->types == ['null' => 'null']) {
throw new DoubleException('Argument type cannot be standalone null');
throw new DoubleException('Type cannot be standalone null');
}

if ($this->types == ['false' => 'false']) {
throw new DoubleException('Type cannot be standalone false');
}

if ($this->types == ['false' => 'false', 'null' => 'null']) {
throw new DoubleException('Type cannot be nullable false');
}

if (\PHP_VERSION_ID >= 80000 && isset($this->types['mixed']) && count($this->types) !== 1) {
Expand Down

0 comments on commit 26ec19b

Please sign in to comment.