Skip to content

Commit

Permalink
More specific type for 'port' component of 'parse_url()'
Browse files Browse the repository at this point in the history
  • Loading branch information
thg2k committed Aug 15, 2022
1 parent 4b6d964 commit 9775464
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/Type/Php/ParseUrlFunctionDynamicReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\NullType;
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -122,17 +122,17 @@ private function cacheReturnTypes(): void
}

$string = new StringType();
$integer = new IntegerType();
$port = IntegerRangeType::fromInterval(0, 65535);
$false = new ConstantBooleanType(false);
$null = new NullType();

$stringOrFalseOrNull = TypeCombinator::union($string, $false, $null);
$integerOrFalseOrNull = TypeCombinator::union($integer, $false, $null);
$portOrFalseOrNull = TypeCombinator::union($port, $false, $null);

$this->componentTypesPairedConstants = [
PHP_URL_SCHEME => $stringOrFalseOrNull,
PHP_URL_HOST => $stringOrFalseOrNull,
PHP_URL_PORT => $integerOrFalseOrNull,
PHP_URL_PORT => $portOrFalseOrNull,
PHP_URL_USER => $stringOrFalseOrNull,
PHP_URL_PASS => $stringOrFalseOrNull,
PHP_URL_PATH => $stringOrFalseOrNull,
Expand All @@ -143,7 +143,7 @@ private function cacheReturnTypes(): void
$this->componentTypesPairedStrings = [
'scheme' => $string,
'host' => $string,
'port' => $integer,
'port' => $port,
'user' => $string,
'pass' => $string,
'path' => $string,
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5385,7 +5385,7 @@ public function dataFunctions(): array
'$parseUrlConstantUrlWithoutComponent2',
],
[
'array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false',
'array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false',
'$parseUrlConstantUrlUnknownComponent',
],
[
Expand All @@ -5405,11 +5405,11 @@ public function dataFunctions(): array
'$parseUrlStringUrlWithComponentInvalid',
],
[
'int|false|null',
'int<0, 65535>|false|null',
'$parseUrlStringUrlWithComponentPort',
],
[
'array{scheme?: string, host?: string, port?: int, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false',
'array{scheme?: string, host?: string, port?: int<0, 65535>, user?: string, pass?: string, path?: string, query?: string, fragment?: string}|false',
'$parseUrlStringUrlWithoutComponent',
],
[
Expand Down

0 comments on commit 9775464

Please sign in to comment.