1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Ignore falsable issues from core functions

This commit is contained in:
Matt Brown 2018-01-25 13:07:36 -05:00
parent d67f1e3c28
commit 1a2d13ae32
5 changed files with 38 additions and 7 deletions

View File

@ -2229,7 +2229,7 @@ return [
'filepro_fieldwidth' => ['int', 'field_number'=>'int'],
'filepro_retrieve' => ['string', 'row_number'=>'int', 'field_number'=>'int'],
'filepro_rowcount' => ['int'],
'file_put_contents' => ['int', 'file'=>'string', 'data'=>'', 'flags='=>'int', 'context='=>''],
'file_put_contents' => ['int|false', 'file'=>'string', 'data'=>'', 'flags='=>'int', 'context='=>''],
'filesize' => ['int|false', 'filename'=>'string'],
'FilesystemIterator::__construct' => ['void', 'path'=>'string', 'flags='=>'int'],
'FilesystemIterator::current' => ['string'],

View File

@ -251,7 +251,18 @@ class FunctionChecker extends FunctionLikeChecker
return Type::getMixed();
}
return Type::parseString($call_map[$call_map_key][0]);
$call_map_return_type = Type::parseString($call_map[$call_map_key][0]);
if (!in_array(
$call_map_key,
['mb_strpos', 'mb_strrpos', 'mb_stripos', 'mb_strripos', 'strpos', 'strrpos', 'stripos', 'strripos'],
true
) && $call_map_return_type->isFalsable()
) {
$call_map_return_type->ignore_falsable_issues = true;
}
return $call_map_return_type;
}
/**

View File

@ -851,7 +851,7 @@ class Config
*/
private static function getVendorDir($current_dir)
{
$composer_json_path = $current_dir . DIRECTORY_SEPARATOR . 'composer.json'; // this should ideally not be hardcoded
$composer_json_path = $current_dir . DIRECTORY_SEPARATOR . 'composer.json';
if (!file_exists($composer_json_path)) {
return 'vendor';
@ -862,7 +862,7 @@ class Config
}
if (isset($composer_json['config']['vendor-dir'])) {
return (string) $composer_json['config']['vendor-dir'];
return (string) $composer_json['config']['vendor-dir'];
}
return 'vendor';

View File

@ -29,7 +29,8 @@ function requireAutoloaders($current_dir, $has_explicit_root, $vendor_dir)
$has_autoloader = true;
}
$vendor_autoload_file = $autoload_root . DIRECTORY_SEPARATOR . $vendor_dir . DIRECTORY_SEPARATOR . 'autoload.php';
$vendor_autoload_file =
$autoload_root . DIRECTORY_SEPARATOR . $vendor_dir . DIRECTORY_SEPARATOR . 'autoload.php';
if (file_exists($vendor_autoload_file)) {
$autoload_files[] = realpath($vendor_autoload_file);
@ -65,7 +66,7 @@ function requireAutoloaders($current_dir, $has_explicit_root, $vendor_dir)
*/
function getVendorDir($current_dir)
{
$composer_json_path = $current_dir . DIRECTORY_SEPARATOR . 'composer.json'; // this should ideally not be hardcoded
$composer_json_path = $current_dir . DIRECTORY_SEPARATOR . 'composer.json';
if (!file_exists($composer_json_path)) {
return 'vendor';
@ -76,7 +77,7 @@ function getVendorDir($current_dir)
}
if (isset($composer_json['config']['vendor-dir'])) {
return (string) $composer_json['config']['vendor-dir'];
return (string) $composer_json['config']['vendor-dir'];
}
return 'vendor';

View File

@ -439,6 +439,25 @@ class FunctionCallTest extends TestCase
return current($arr);
}',
],
'ignoreFalsableFileGetContents' => [
'<?php
function foo(string $s): string {
return file_get_contents($s);
}
function bar(string $s): string {
$a = file_get_contents($s);
if ($a === false) {
return "hello";
}
return $a;
}
/**
* @return string|false
*/
function bat(string $s) {
return file_get_contents($s);
}',
],
];
}