Skip to content

Commit 22febaa

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.0.x
2 parents 57c6588 + 98e2b6e commit 22febaa

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

resources/functionMap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,8 +6403,8 @@
64036403
'mcrypt_module_open' => ['resource|false', 'cipher'=>'string', 'cipher_directory'=>'string', 'mode'=>'string', 'mode_directory'=>'string'],
64046404
'mcrypt_module_self_test' => ['bool', 'algorithm'=>'string', 'lib_dir='=>'string'],
64056405
'mcrypt_ofb' => ['string', 'cipher'=>'string', 'key'=>'string', 'data'=>'string', 'mode'=>'int', 'iv='=>'string'],
6406-
'md5' => ['non-falsy-string', 'str'=>'string', 'raw_output='=>'bool'],
6407-
'md5_file' => ['non-falsy-string|false', 'filename'=>'string', 'raw_output='=>'bool'],
6406+
'md5' => ['non-falsy-string&lowercase-string', 'str'=>'string', 'raw_output='=>'bool'],
6407+
'md5_file' => ['(non-falsy-string&lowercase-string)|false', 'filename'=>'string', 'raw_output='=>'bool'],
64086408
'mdecrypt_generic' => ['string', 'td'=>'resource', 'data'=>'string'],
64096409
'Memcache::add' => ['bool', 'key'=>'string', 'var'=>'mixed', 'flag='=>'int', 'expire='=>'int'],
64106410
'Memcache::addServer' => ['bool', 'host'=>'string', 'port='=>'int', 'persistent='=>'bool', 'weight='=>'int', 'timeout='=>'int', 'retry_interval='=>'int', 'status='=>'bool', 'failure_callback='=>'callable', 'timeoutms='=>'int'],
@@ -10446,8 +10446,8 @@
1044610446
'setRightFill' => ['void', 'red'=>'int', 'green'=>'int', 'blue'=>'int', 'a='=>'int'],
1044710447
'setthreadtitle' => ['bool', 'title'=>'string'],
1044810448
'settype' => ['bool', '&rw_var'=>'mixed', 'type'=>'string'],
10449-
'sha1' => ['non-falsy-string', 'str'=>'string', 'raw_output='=>'bool'],
10450-
'sha1_file' => ['non-falsy-string|false', 'filename'=>'string', 'raw_output='=>'bool'],
10449+
'sha1' => ['non-falsy-string&lowercase-string', 'str'=>'string', 'raw_output='=>'bool'],
10450+
'sha1_file' => ['(non-falsy-string&lowercase-string)|false', 'filename'=>'string', 'raw_output='=>'bool'],
1045110451
'sha256' => ['string', 'str'=>'string', 'raw_output='=>'bool'],
1045210452
'sha256_file' => ['string', 'filename'=>'string', 'raw_output='=>'bool'],
1045310453
'shapefileObj::__construct' => ['void', 'filename'=>'string', 'type'=>'int'],

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,4 +911,23 @@ public function testBug7173(): void
911911
$this->analyse([__DIR__ . '/data/bug-7173.php'], []);
912912
}
913913

914+
public function testHashing(): void
915+
{
916+
$this->analyse([__DIR__ . '/data/hashing.php'], [
917+
[
918+
"Strict comparison using === between lowercase-string&non-falsy-string and 'ABC' will always evaluate to false.",
919+
9,
920+
],
921+
[
922+
"Strict comparison using === between (lowercase-string&non-falsy-string)|false and 'ABC' will always evaluate to false.",
923+
12,
924+
],
925+
[
926+
"Strict comparison using === between (lowercase-string&non-falsy-string)|(non-falsy-string&numeric-string) and 'A' will always evaluate to false.",
927+
31,
928+
'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.',
929+
],
930+
]);
931+
}
932+
914933
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Hashing;
4+
5+
use function md5;
6+
use function md5_file;
7+
8+
function doFoo(string $s):void {
9+
if (md5($s) === 'ABC') {
10+
11+
}
12+
if (md5_file($s) === 'ABC') {
13+
14+
}
15+
}
16+
17+
/**
18+
* @param (non-falsy-string&numeric-string)|(non-falsy-string&lowercase-string) $s
19+
* @return void
20+
*/
21+
function doFooBar($s) {
22+
if ($s === '598d4c200461b81522a3328565c25f7c') {
23+
24+
}
25+
if ($s === 'a') {
26+
27+
}
28+
if ($s === '123') {
29+
30+
}
31+
if ($s === 'A') {
32+
33+
}
34+
}

0 commit comments

Comments
 (0)