Skip to content
Permalink
Browse files

Tighten up Psalm’s inference

  • Loading branch information
muglug committed Nov 25, 2019
1 parent c60cafb commit 1f07ea7ee73c65b81ef5b780a95e835e06de6ac8
@@ -94,6 +94,10 @@ public static function afterFunctionCallAnalysis(
$function_id
);
if (!$function_storage->cased_name) {
return;
}
$function_name_parts = explode('\\', $function_storage->cased_name);
if (end($function_name_parts) !== end($expr->name->parts)) {
@@ -49,18 +49,13 @@
</plugins>

<issueHandlers>
<MisplacedRequiredParam errorLevel="suppress"/>
<PossiblyNullOperand errorLevel="suppress"/>
<MissingConstructor>

<DeprecatedMethod>
<errorLevel type="suppress">
<file name="src/Psalm/Internal/Scanner/FunctionDocblockComment.php"/>
<file name="src/Psalm/Storage/FunctionLikeStorage.php"/>
<file name="src/Psalm/Storage/MethodStorage.php"/>
<file name="src/Psalm/Storage/PropertyStorage.php"/>
<file name="src/Psalm/Internal/Scope/CaseScope.php"/>
<directory name="tests" />
</errorLevel>
</MissingConstructor>
<DeprecatedProperty errorLevel="suppress"/>
</DeprecatedMethod>

<DeprecatedMethod>
<errorLevel type="suppress">
@@ -751,6 +751,7 @@ private function checkParamReferences(
}
if (!($storage instanceof MethodStorage)
|| !$storage->cased_name
|| $storage->visibility === ClassLikeAnalyzer::VISIBILITY_PRIVATE
) {
if ($this->function instanceof Closure) {
@@ -804,6 +805,7 @@ private function checkParamReferences(
if ($storage instanceof MethodStorage
&& $class_storage
&& $storage->cased_name
&& $storage->visibility !== ClassLikeAnalyzer::VISIBILITY_PRIVATE
) {
$method_id_lc = strtolower($this->getMethodId());
@@ -816,7 +818,6 @@ private function checkParamReferences(
$method_id_lc
);
/** @var ClassMethod $this->function */
$method_name_lc = strtolower($storage->cased_name);
if (!isset($class_storage->overridden_method_ids[$method_name_lc])) {
@@ -520,7 +520,7 @@ public static function compareMethods(
$prevent_method_signature_mismatch = true
) {
$implementer_method_id = $implementer_classlike_storage->name . '::'
. strtolower($guide_method_storage->cased_name);
. strtolower($guide_method_storage->cased_name ?: '');
$implementer_declaring_method_id = $codebase->methods->getDeclaringMethodId($implementer_method_id);
@@ -694,7 +694,7 @@ public static function compareMethods(
$template_types = [];
foreach ($map as $key => $type) {
if (is_string($key)) {
if (is_string($key) && $implementer_method_storage->defining_fqcln) {
$template_types[$key][$implementer_method_storage->defining_fqcln] = [
$type,
];
@@ -259,9 +259,7 @@ private static function handleCase(
}
$case_context->parent_context = $context;
$case_scope = $case_context->case_scope = new CaseScope();
$case_scope->parent_context = $case_context;
$case_scope = $case_context->case_scope = new CaseScope($case_context);
$case_equality_expr = null;
@@ -527,7 +527,7 @@ public function isVariadic($method_id)
list($fq_class_name, $method_name) = explode('::', $method_id);
return $this->classlike_storage_provider->get($fq_class_name)->methods[$method_name]->variadic;
return $this->classlike_storage_provider->get($fq_class_name)->methods[$method_name ?: '']->variadic;
}
/**
@@ -638,8 +638,13 @@ private function scanFile(
if ($this->codebase->register_autoload_files) {
foreach ($file_storage->functions as $function_storage) {
if (!$this->codebase->functions->hasStubbedFunction($function_storage->cased_name)) {
$this->codebase->functions->addGlobalFunction($function_storage->cased_name, $function_storage);
if ($function_storage->cased_name
&& !$this->codebase->functions->hasStubbedFunction($function_storage->cased_name)
) {
$this->codebase->functions->addGlobalFunction(
$function_storage->cased_name,
$function_storage
);
}
}
@@ -25,6 +25,11 @@ class CaseScope
*/
public $break_vars;
public function __construct(Context $parent_context)
{
$this->parent_context = $parent_context;
}
public function __destruct()
{
/** @psalm-suppress PossiblyNullPropertyAssignmentValue */
@@ -57,7 +57,7 @@ class FunctionLikeStorage
public $signature_return_type_location;
/**
* @var string
* @var ?string
*/
public $cased_name;
@@ -67,12 +67,12 @@ class FunctionLikeStorage
public $suppressed_issues = [];
/**
* @var bool
* @var ?bool
*/
public $deprecated;
/**
* @var bool
* @var ?bool
*/
public $internal;
@@ -84,15 +84,15 @@ class FunctionLikeStorage
/**
* @var bool
*/
public $variadic;
public $variadic = false;
/**
* @var bool
*/
public $returns_by_ref = false;
/**
* @var int
* @var ?int
*/
public $required_param_count;
@@ -6,22 +6,22 @@ class MethodStorage extends FunctionLikeStorage
/**
* @var bool
*/
public $is_static;
public $is_static = false;
/**
* @var int
*/
public $visibility;
public $visibility = 0;
/**
* @var bool
*/
public $final;
public $final = false;
/**
* @var bool
*/
public $abstract;
public $abstract = false;
/**
* @var bool
@@ -44,7 +44,7 @@ class MethodStorage extends FunctionLikeStorage
public $inherited_return_type = false;
/**
* @var string
* @var ?string
*/
public $defining_fqcln;
@@ -10,14 +10,14 @@ class PropertyStorage
use CustomMetadataTrait;
/**
* @var bool
* @var ?bool
*/
public $is_static;
/**
* @var int
*/
public $visibility;
public $visibility = 0;
/**
* @var CodeLocation|null

0 comments on commit 1f07ea7

Please sign in to comment.
You can’t perform that action at this time.