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

Merge pull request #7233 from orklah/cleanup8

more code grooming
This commit is contained in:
orklah 2021-12-28 20:48:23 +01:00 committed by GitHub
commit f9b3600a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 21 additions and 59 deletions

View File

@ -1805,11 +1805,11 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
$context->self,
$template_params
);
$this_object_type->was_static = !$storage->final;
} else {
$this_object_type = new TNamedObject($context->self);
$this_object_type->was_static = !$storage->final;
}
$this_object_type->was_static = !$storage->final;
$context->vars_in_scope['$this'] = new Union([$this_object_type]);

View File

@ -2652,23 +2652,17 @@ class AssertionFinder
)
);
if ($not_identical) {
try {
$assertion = $var_type->getAssertionString();
} catch (UnexpectedValueException $e) {
$assertion = null;
}
try {
$assertion = $var_type->getAssertionString();
} catch (UnexpectedValueException $e) {
$assertion = null;
}
if ($not_identical) {
if ($assertion) {
$if_types[$var_name] = [['!=' . $assertion]];
}
} else {
try {
$assertion = $var_type->getAssertionString();
} catch (UnexpectedValueException $e) {
$assertion = null;
}
if ($assertion) {
$if_types[$var_name] = [['!~' . $assertion]];
}

View File

@ -66,8 +66,6 @@ class MethodCallAnalyzer extends CallAnalyzer
return false;
}
$context->inside_call = $was_inside_call;
if (!$stmt->name instanceof PhpParser\Node\Identifier) {
$context->inside_call = true;

View File

@ -672,8 +672,6 @@ class AtomicPropertyFetchAnalyzer
$statements_analyzer->node_data->setType($stmt, Type::getMixed());
}
$property_id = $lhs_type_part->value . '::$' . $prop_name;
/*
* If we have an explicit list of all allowed magic properties on the class, and we're
* not in that list, fall through

View File

@ -1252,7 +1252,6 @@ class ClassLikes
$destination_parts = explode('\\', $new_fq_class_name);
$destination_class_name = array_pop($destination_parts);
$file_manipulations = [];
$file_manipulations[] = new FileManipulation(
(int) $class_name_node->getAttribute('startFilePos'),

View File

@ -153,7 +153,6 @@ class BuildInfoCollector
if (isset($this->env['APPVEYOR']) && $this->env['APPVEYOR'] && isset($this->env['APPVEYOR_BUILD_NUMBER'])) {
$this->readEnv['CI_BUILD_NUMBER'] = $this->env['APPVEYOR_BUILD_NUMBER'];
$this->readEnv['CI_JOB_ID'] = $this->env['APPVEYOR_JOB_NUMBER'];
$this->readEnv['CI_BRANCH'] = $this->env['APPVEYOR_REPO_BRANCH'];
$this->readEnv['CI_PR_NUMBER'] = $this->env['APPVEYOR_PULL_REQUEST_NUMBER'] ?? '';
$this->env['CI_NAME'] = 'AppVeyor';

View File

@ -811,8 +811,7 @@ class FunctionLikeNodeScanner
): FunctionLikeParameter {
$param_type = null;
$is_nullable = $param->default !== null &&
$param->default instanceof PhpParser\Node\Expr\ConstFetch &&
$is_nullable = $param->default instanceof PhpParser\Node\Expr\ConstFetch &&
strtolower($param->default->name->parts[0]) === 'null';
$param_typehint = $param->type;

View File

@ -424,13 +424,6 @@ class ArrayMapReturnTypeProvider implements FunctionReturnTypeProviderInterface
$context->vars_in_scope["\$__fake_{$fake_var_discriminator}_offset_var__"] = Type::getMixed();
$context->vars_in_scope["\$__fake_{$fake_var_discriminator}_method_call_var__"] =
$lhs_instance_type ?: new Union([new TNamedObject($callable_fq_class_name)]);
$fake_method_return_type = self::executeFakeCall(
$statements_source,
$fake_method_call,
$context,
$assertions
);
} else {
$fake_method_call = new VirtualStaticCall(
new VirtualFullyQualified(
@ -446,15 +439,15 @@ class ArrayMapReturnTypeProvider implements FunctionReturnTypeProviderInterface
);
$context->vars_in_scope["\$__fake_{$fake_var_discriminator}_offset_var__"] = Type::getMixed();
$fake_method_return_type = self::executeFakeCall(
$statements_source,
$fake_method_call,
$context,
$assertions
);
}
$fake_method_return_type = self::executeFakeCall(
$statements_source,
$fake_method_call,
$context,
$assertions
);
$function_id_return_type = $fake_method_return_type ?? Type::getMixed();
} else {
$fake_function_call = new VirtualFuncCall(

View File

@ -55,8 +55,6 @@ class FilterVarReturnTypeProvider implements FunctionReturnTypeProviderInterface
) {
$filter_type_type = $second_arg_type->getSingleIntLiteral();
$filter_type = null;
switch ($filter_type_type->value) {
case FILTER_VALIDATE_INT:
$filter_type = Type::getInt();

View File

@ -61,7 +61,7 @@ class RandReturnTypeProvider implements FunctionReturnTypeProviderInterface
} elseif ($second_atomic_type instanceof TIntRange) {
$max_value = $second_atomic_type->max_bound;
} elseif ($second_atomic_type instanceof TPositiveInt) {
$max_value = null;
// no max value, we keep null
}
}

View File

@ -101,8 +101,10 @@ class DocblockParser
unset($lines[$k]);
} else {
// Strip the leading *, if present.
$lines[$k] = str_replace("\t", ' ', $line);
$lines[$k] = preg_replace('/^ *\*/', '', $line);
$text = $lines[$k];
$text = str_replace("\t", ' ', $text);
$text = preg_replace('/^ *\*/', '', $text);
$lines[$k] = $text;
}
$line_offset += $original_line_length + 1;

View File

@ -227,7 +227,6 @@ class ParseTreeCreator
if ($this->current_leaf !== $current_parent) {
$new_parent_leaf->children = [$this->current_leaf];
$this->current_leaf->parent = $new_parent_leaf;
array_pop($current_parent->children);
}
@ -419,8 +418,6 @@ class ParseTreeCreator
if ($current_parent !== $this->current_leaf) {
$new_leaf->children = [$this->current_leaf];
$this->current_leaf->parent = $new_leaf;
array_pop($current_parent->children);
}
$current_parent->children[] = $new_leaf;
@ -505,8 +502,6 @@ class ParseTreeCreator
$new_parent_leaf = new KeyedArrayPropertyTree($this->current_leaf->value, $current_parent);
$new_parent_leaf->possibly_undefined = $prev_token !== null && $prev_token[0] === '?';
$this->current_leaf->parent = $new_parent_leaf;
array_pop($current_parent->children);
$current_parent->children[] = $new_parent_leaf;
@ -574,8 +569,6 @@ class ParseTreeCreator
$this->current_leaf->parent
);
$this->current_leaf->parent = $new_leaf;
array_pop($current_parent->children);
$current_parent->children[] = $new_leaf;
$this->current_leaf = $new_leaf;
@ -640,11 +633,9 @@ class ParseTreeCreator
$new_parent_leaf = new UnionTree($this->current_leaf);
$new_parent_leaf->children = [$this->current_leaf];
$new_parent_leaf->parent = $current_parent;
$this->current_leaf->parent = $new_parent_leaf;
} else {
$new_parent_leaf = new UnionTree($current_parent);
$new_parent_leaf->children = [$this->current_leaf];
$this->current_leaf->parent = $new_parent_leaf;
}
if ($current_parent) {
@ -679,7 +670,6 @@ class ParseTreeCreator
$new_parent_leaf = new IntersectionTree($current_parent);
$new_parent_leaf->children = [$this->current_leaf];
$this->current_leaf->parent = $new_parent_leaf;
if ($current_parent) {
array_pop($current_parent->children);

View File

@ -1008,8 +1008,6 @@ class TypeCombiner
} else {
$combination->value_types['string'] = $type;
}
$combination->strings = null;
} elseif ($type instanceof TLowercaseString) {
$has_non_lowercase_string = false;
@ -1025,8 +1023,6 @@ class TypeCombiner
} else {
$combination->value_types['string'] = $type;
}
$combination->strings = null;
} elseif ($type instanceof TNonEmptyString) {
$has_empty_string = false;
@ -1042,12 +1038,8 @@ class TypeCombiner
} else {
$combination->value_types['string'] = $type;
}
$combination->strings = null;
} elseif ($type instanceof TNonspecificLiteralString) {
$combination->value_types['string'] = $type;
$combination->strings = null;
} else {
$combination->value_types[$type_key] = new TString();
}