Skip to content

Commit

Permalink
Retain specific int details in docblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Feb 19, 2025
1 parent 323f249 commit 9d1c4a5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions generator/tests/PhpStanFunctions/PhpStanTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,29 @@ public function testNotEmptyStringBecomingString(): void
$this->assertEquals('string', $param->getSignatureType(ErrorType::FALSY));
}

public function testPositiveIntBecomingInt(): void
{
$param = new PhpStanType('positive-int');
$this->assertEquals('int', $param->getDocBlockType());
$this->assertEquals('int', $param->getSignatureType());
}

public function testListBecomingArray(): void
{
$param = new PhpStanType('list<string>|false');
$this->assertEquals('array<string>', $param->getDocBlockType(ErrorType::FALSY));
$this->assertEquals('array', $param->getSignatureType(ErrorType::FALSY));
}

public function testNumbersAreRemoved(): void
public function testIntGeneralisation(): void
{
// PHP only supports "int" rather than specific values or ranges,
// but being specific in the docblock brings significant benefits
// when combined with tools like phpstan, see:
// https://github.com/thecodingmachine/phpstan-safe-rule/issues/52
$param = new PhpStanType('positive-int');
$this->assertEquals('positive-int', $param->getDocBlockType());
$this->assertEquals('int', $param->getSignatureType());

$param = new PhpStanType('0|positive-int');
$this->assertEquals('int', $param->getDocBlockType());
$this->assertEquals('0|positive-int', $param->getDocBlockType());
$this->assertEquals('int', $param->getSignatureType());

$param = new PhpStanType('0|1');
$this->assertEquals('0|1', $param->getDocBlockType());
$this->assertEquals('int', $param->getSignatureType());
}

Expand Down

0 comments on commit 9d1c4a5

Please sign in to comment.