Skip to content

Commit

Permalink
Merge pull request #9073 from therealryanbonham/9066_fix_get_headers_…
Browse files Browse the repository at this point in the history
…signature

Update Call Maps and Signature for get_headers
  • Loading branch information
orklah committed Jan 9, 2023
2 parents e17ecc1 + bf62ef8 commit f415ad5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dictionaries/CallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3699,7 +3699,7 @@
'get_defined_functions' => ['array{internal: list<callable-string>, user: list<callable-string>}', 'exclude_disabled='=>'bool'],
'get_defined_vars' => ['array'],
'get_extension_funcs' => ['list<callable-string>|false', 'extension'=>'string'],
'get_headers' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'resource'],
'get_headers' => ['array|false', 'url'=>'string', 'associative='=>'bool', 'context='=>'?resource'],
'get_html_translation_table' => ['array', 'table='=>'int', 'flags='=>'int', 'encoding='=>'string'],
'get_include_path' => ['string'],
'get_included_files' => ['list<string>'],
Expand Down
2 changes: 1 addition & 1 deletion dictionaries/CallMap_71_delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
],
'get_headers' => [
'old' => ['array|false', 'url'=>'string', 'associative='=>'int'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'resource'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'?resource'],
],
'getopt' => [
'old' => ['array<string,string|false|list<string|false>>|false', 'short_options'=>'string', 'long_options='=>'array'],
Expand Down
4 changes: 4 additions & 0 deletions dictionaries/CallMap_80_delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@
'old' => ['list<string>|null', 'object_or_class'=>'mixed'],
'new' => ['list<string>', 'object_or_class'=>'object|class-string'],
],
'get_headers' => [
'old' => ['array|false', 'url'=>'string', 'associative='=>'int', 'context='=>'?resource'],
'new' => ['array|false', 'url'=>'string', 'associative='=>'bool', 'context='=>'?resource'],
],
'get_parent_class' => [
'old' => ['class-string|false', 'object_or_class='=>'mixed'],
'new' => ['class-string|false', 'object_or_class='=>'object|class-string'],
Expand Down
2 changes: 1 addition & 1 deletion stubs/CoreGenericFunctions.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ function bin2hex(string $string): string {}
*
* @param resource|null $context
*
* @return ($associative is 0 ? list<string> : array<string, string|list<string>>)|false
* @return ($associative is false|0 ? list<string> : array<string, string|list<string>>)|false
*
* @psalm-taint-sink ssrf $url
*/
Expand Down
11 changes: 11 additions & 0 deletions stubs/Php80.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,14 @@ class DatePeriod implements IteratorAggregate
/** @psalm-return (Start is string ? (Traversable<int, DateTime>&Iterator) : (Traversable<int, Start>&Iterator)) */
public function getIterator(): Iterator {}
}

/**
* @psalm-pure
*
* @param resource|null $context
*
* @return ($associative is false|0 ? list<string> : array<string, string|list<string>>)|false
*
* @psalm-taint-sink ssrf $url
*/
function get_headers(string $url, bool $associative = false, $context = null) : array|false {}
18 changes: 18 additions & 0 deletions tests/FunctionCallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,24 @@ function foo() {
}
',
],
'getHeadersAssociativeIn8x' => [
'code' => '<?php
$a = get_headers("https://psalm.dev", true);',
'assertions' => [
'$a' => 'array<string, list<string>|string>|false',
],
'ignored_issues' => [],
'php_version' => '8.0',
],
'getHeadersAssociativeIn7x' => [
'code' => '<?php
$a = get_headers("https://psalm.dev", 0);',
'assertions' => [
'$a' => 'false|list<string>',
],
'ignored_issues' => [],
'php_version' => '7.0',
],
];
}

Expand Down
1 change: 0 additions & 1 deletion tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ class InternalCallMapHandlerTest extends TestCase
'finfo::file',
'finfo::set_flags',
'generator::throw',
'get_headers',
'globiterator::__construct',
'globiterator::getfileinfo',
'globiterator::getpathinfo',
Expand Down

0 comments on commit f415ad5

Please sign in to comment.