mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Remove more dead code
This commit is contained in:
parent
ec65f31aaa
commit
0fbf8b5619
@ -325,7 +325,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
|
||||
foreach (ClassChecker::getInterfacesForClass(
|
||||
$this->fq_class_name
|
||||
) as $interface_id => $interface_name) {
|
||||
) as $_ => $interface_name) {
|
||||
$interface_storage = self::$storage[strtolower($interface_name)];
|
||||
|
||||
$storage->public_class_constants += $interface_storage->public_class_constants;
|
||||
@ -787,7 +787,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
$class_storage = self::$storage[strtolower($this->fq_class_name)];
|
||||
|
||||
if (!isset($class_storage->methods[$method_name])) {
|
||||
$storage = FunctionLikeChecker::register($stmt, $this);
|
||||
FunctionLikeChecker::register($stmt, $this);
|
||||
}
|
||||
|
||||
if (!$stmt->isAbstract() && $class_context->self) {
|
||||
@ -1661,8 +1661,6 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
||||
return null;
|
||||
}
|
||||
|
||||
$file_checker = $source->getFileChecker();
|
||||
|
||||
if (ClassChecker::classExtends($appearing_property_class, $calling_context)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
|
||||
$this->interface_checkers_to_visit[$fq_class_name] = $class_checker;
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Trait_) {
|
||||
$trait_checker = new TraitChecker($stmt, $this, $stmt->name);
|
||||
new TraitChecker($stmt, $this, $stmt->name);
|
||||
}
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Namespace_) {
|
||||
$namespace_name = $stmt->name ? implode('\\', $stmt->name->parts) : '';
|
||||
|
@ -346,11 +346,12 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
}
|
||||
|
||||
if ($context->count_references) {
|
||||
foreach ($context->vars_in_scope as $var_name => $_) {
|
||||
foreach ($context->vars_possibly_in_scope as $var_name => $_) {
|
||||
if (strpos($var_name, '->') === false &&
|
||||
$var_name !== '$this' &&
|
||||
strpos($var_name, '::$') === false &&
|
||||
strpos($var_name, '[') === false
|
||||
strpos($var_name, '[') === false &&
|
||||
$var_name !== '$_'
|
||||
) {
|
||||
if (!isset($context->referenced_vars[$var_name])) {
|
||||
echo 'Variable ' . $var_name . ' is not referenced in ' . $cased_method_id . PHP_EOL;
|
||||
|
@ -499,8 +499,6 @@ class MethodChecker extends FunctionLikeChecker
|
||||
return null;
|
||||
}
|
||||
|
||||
$file_checker = $source->getFileChecker();
|
||||
|
||||
if (ClassChecker::classExtends($appearing_method_class, $calling_context)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -490,8 +490,6 @@ class ProjectChecker
|
||||
|
||||
$this->config->hide_external_errors = $this->config->isInProjectDirs($file_name);
|
||||
|
||||
$file_name_parts = explode('.', $file_name);
|
||||
|
||||
$filetype_handlers = $this->config->getFiletypeHandlers();
|
||||
|
||||
FileChecker::loadReferenceCache();
|
||||
|
@ -643,6 +643,13 @@ class IfChecker
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($outer_context->count_references) {
|
||||
$outer_context->referenced_vars = array_merge(
|
||||
$outer_context->referenced_vars,
|
||||
$else_context->referenced_vars
|
||||
);
|
||||
}
|
||||
|
||||
if (count($else->stmts)) {
|
||||
// has a return/throw at end
|
||||
$has_ending_statements = ScopeChecker::doesAlwaysReturnOrThrow($else->stmts);
|
||||
|
@ -75,6 +75,13 @@ class TryChecker
|
||||
|
||||
$statements_checker->analyze($catch->stmts, $catch_context, $loop_context);
|
||||
|
||||
if ($context->count_references) {
|
||||
$context->referenced_vars = array_merge(
|
||||
$catch_context->referenced_vars,
|
||||
$context->referenced_vars
|
||||
);
|
||||
}
|
||||
|
||||
if (!ScopeChecker::doesAlwaysReturnOrThrow($catch->stmts)) {
|
||||
foreach ($catch_context->vars_in_scope as $catch_var => $type) {
|
||||
if ($catch->var !== $catch_var &&
|
||||
|
@ -89,8 +89,6 @@ class CallChecker
|
||||
$context->check_consts = false;
|
||||
} elseif ($method->parts === ['extract']) {
|
||||
$context->check_variables = false;
|
||||
} elseif ($method->parts === ['assert']) {
|
||||
$contains_assertion = true;
|
||||
} elseif ($method->parts === ['var_dump'] || $method->parts === ['shell_exec']) {
|
||||
if (IssueBuffer::accepts(
|
||||
new ForbiddenCode(
|
||||
|
@ -750,6 +750,11 @@ class ExpressionChecker
|
||||
|
||||
$context->updateChecks($op_context);
|
||||
|
||||
$context->referenced_vars = array_merge(
|
||||
$op_context->referenced_vars,
|
||||
$context->referenced_vars
|
||||
);
|
||||
|
||||
$context->vars_possibly_in_scope = array_merge(
|
||||
$op_context->vars_possibly_in_scope,
|
||||
$context->vars_possibly_in_scope
|
||||
@ -801,6 +806,11 @@ class ExpressionChecker
|
||||
|
||||
$context->updateChecks($op_context);
|
||||
|
||||
$context->referenced_vars = array_merge(
|
||||
$op_context->referenced_vars,
|
||||
$context->referenced_vars
|
||||
);
|
||||
|
||||
$context->vars_possibly_in_scope = array_merge(
|
||||
$op_context->vars_possibly_in_scope,
|
||||
$context->vars_possibly_in_scope
|
||||
@ -1282,7 +1292,7 @@ class ExpressionChecker
|
||||
|
||||
$new_return_type_parts = [];
|
||||
|
||||
foreach ($return_type->types as $key => $return_type_part) {
|
||||
foreach ($return_type->types as $return_type_part) {
|
||||
$new_return_type_parts[] = self::fleshOutAtomicType($return_type_part, $args, $calling_class, $method_id);
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ class Clause
|
||||
{
|
||||
ksort($this->possibilities);
|
||||
|
||||
foreach ($this->possibilities as $var => &$possible_types) {
|
||||
foreach ($this->possibilities as &$possible_types) {
|
||||
sort($possible_types);
|
||||
}
|
||||
|
||||
|
@ -441,7 +441,7 @@ class Config
|
||||
*/
|
||||
public function initializePlugins(ProjectChecker $project_checker)
|
||||
{
|
||||
foreach ($this->filetype_handlers as $extension_name => &$path) {
|
||||
foreach ($this->filetype_handlers as &$path) {
|
||||
$plugin_file_checker = new FileChecker($path, $project_checker);
|
||||
$plugin_file_checker->visit();
|
||||
|
||||
|
@ -113,7 +113,7 @@ class Context
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->vars_in_scope as $key => &$type) {
|
||||
foreach ($this->vars_in_scope as &$type) {
|
||||
if ($type) {
|
||||
$type = clone $type;
|
||||
}
|
||||
@ -241,7 +241,7 @@ class Context
|
||||
if ($type->hasArray() || $type->isMixed()) {
|
||||
$vars_to_remove = [];
|
||||
|
||||
foreach ($this->vars_in_scope as $var_id => $context_type) {
|
||||
foreach ($this->vars_in_scope as $var_id => $_) {
|
||||
if (preg_match('/^' . preg_quote($remove_var_id, DIRECTORY_SEPARATOR) . '[\[\-]/', $var_id)) {
|
||||
$vars_to_remove[] = $var_id;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ class ObjectLike extends \Psalm\Type\Atomic
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->properties as $key => &$property) {
|
||||
foreach ($this->properties as &$property) {
|
||||
$property = clone $property;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user