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

Merge pull request #7229 from orklah/cleanup5

remove always true/false conditions
This commit is contained in:
orklah 2021-12-27 22:08:06 +01:00 committed by GitHub
commit 3828db52b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 7 additions and 105 deletions

View File

@ -41,7 +41,6 @@ use Psalm\Type\Atomic;
use Psalm\Type\Atomic\Scalar;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TDependentListKey;
use Psalm\Type\Atomic\TEmpty;
use Psalm\Type\Atomic\TFalse;
use Psalm\Type\Atomic\TGenericObject;
use Psalm\Type\Atomic\TIntRange;
@ -502,16 +501,11 @@ class ForeachAnalyzer
$always_non_empty_array = false;
if ($iterator_atomic_type instanceof Scalar ||
$iterator_atomic_type instanceof TVoid
) {
if ($iterator_atomic_type instanceof Scalar || $iterator_atomic_type instanceof TVoid) {
$invalid_iterator_types[] = $iterator_atomic_type->getKey();
$value_type = Type::getMixed();
} elseif ($iterator_atomic_type instanceof TObject ||
$iterator_atomic_type instanceof TMixed ||
$iterator_atomic_type instanceof TEmpty
) {
} elseif ($iterator_atomic_type instanceof TObject || $iterator_atomic_type instanceof TMixed) {
$has_valid_iterator = true;
$value_type = Type::getMixed();
$key_type = Type::getMixed();

View File

@ -188,7 +188,6 @@ class ArrayAnalyzer
if (!$atomic_key_type instanceof TString
&& !$atomic_key_type instanceof TInt
&& !$atomic_key_type instanceof TArrayKey
&& !$atomic_key_type instanceof TMixed
&& !$atomic_key_type instanceof TTemplateParam
&& !(
$atomic_key_type instanceof TObjectWithProperties

View File

@ -1214,11 +1214,7 @@ class AssignmentAnalyzer
&& !$assign_value_type->hasArrayAccessInterface($codebase)
) {
if ($assign_value_type->hasArray()) {
if (($assign_value_atomic_type instanceof TFalse
&& $assign_value_type->ignore_falsable_issues)
|| ($assign_value_atomic_type instanceof TNull
&& $assign_value_type->ignore_nullable_issues)
) {
if ($assign_value_atomic_type instanceof TFalse && $assign_value_type->ignore_falsable_issues) {
// do nothing
} elseif (IssueBuffer::accepts(
new PossiblyInvalidArrayAccess(

View File

@ -87,22 +87,6 @@ class NonComparisonOpAnalyzer
return;
}
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BitwiseXor) {
if ($stmt_left_type->hasBool() || $stmt_right_type->hasBool()) {
$statements_analyzer->node_data->setType($stmt, Type::getInt());
}
BinaryOpAnalyzer::addDataFlow(
$statements_analyzer,
$stmt,
$stmt->left,
$stmt->right,
'xor'
);
return;
}
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalXor) {
if ($stmt_left_type->hasBool() || $stmt_right_type->hasBool()) {
$statements_analyzer->node_data->setType($stmt, Type::getBool());
@ -146,25 +130,5 @@ class NonComparisonOpAnalyzer
return;
}
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BitwiseOr) {
ArithmeticOpAnalyzer::analyze(
$statements_analyzer,
$statements_analyzer->node_data,
$stmt->left,
$stmt->right,
$stmt,
$result_type,
$context
);
BinaryOpAnalyzer::addDataFlow(
$statements_analyzer,
$stmt,
$stmt->left,
$stmt->right,
'or'
);
}
}
}

View File

@ -677,7 +677,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
$function_call_info->function_exists = true;
$has_valid_function_call_type = true;
} elseif ($var_type_part instanceof TMixed || $var_type_part instanceof TTemplateParam) {
} elseif ($var_type_part instanceof TMixed) {
$has_valid_function_call_type = true;
IssueBuffer::maybeAdd(

View File

@ -169,12 +169,6 @@ class ArrayMapReturnTypeProvider implements FunctionReturnTypeProviderInterface
$function_call_arg->value->items[1]->value->value,
[]
);
} elseif ($variable_atomic_type instanceof TTemplateParamClass) {
$fake_method_call = new VirtualStaticCall(
$function_call_arg->value->items[0]->value,
$function_call_arg->value->items[1]->value->value,
[]
);
}
}

View File

@ -395,10 +395,6 @@ class AtomicTypeComparator
}
foreach ($input_type_part->as->getAtomicTypes() as $input_as_type_part) {
if ($input_as_type_part instanceof TNull && $container_type_part instanceof TNull) {
continue;
}
if (self::isContainedBy(
$codebase,
$input_as_type_part,

View File

@ -89,9 +89,7 @@ class ScalarTypeComparator
}
if ($container_type_part instanceof TNonspecificLiteralString
&& ($input_type_part instanceof TLiteralString
|| $input_type_part instanceof TNonspecificLiteralString
|| $input_type_part instanceof TNonEmptyNonspecificLiteralString)
&& ($input_type_part instanceof TLiteralString || $input_type_part instanceof TNonspecificLiteralString)
) {
return true;
}

View File

@ -53,7 +53,6 @@ use Psalm\Type\Atomic\TScalar;
use Psalm\Type\Atomic\TString;
use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Atomic\TTemplateParamClass;
use Psalm\Type\Atomic\TTraitString;
use Psalm\Type\Atomic\TTrue;
use Psalm\Type\Union;
use UnexpectedValueException;
@ -1050,28 +1049,7 @@ class TypeCombiner
$combination->strings = null;
} else {
$has_non_literal_class_string = false;
$shared_classlikes = $codebase ? self::getSharedTypes($combination, $codebase) : [];
foreach ($combination->strings as $string_type) {
if (!$string_type instanceof TLiteralClassString) {
$has_non_literal_class_string = true;
break;
}
}
if ($has_non_literal_class_string ||
!$type instanceof TClassString
) {
$combination->value_types[$type_key] = new TString();
} else {
if (isset($shared_classlikes[$type->as]) && $type->as_type) {
$combination->class_string_types[$type->as] = $type->as_type;
} else {
$combination->class_string_types['object'] = new TObject();
}
}
$combination->value_types[$type_key] = new TString();
}
} else {
$combination->value_types[$type_key] = $type;
@ -1079,13 +1057,6 @@ class TypeCombiner
} elseif (get_class($combination->value_types['string']) !== TString::class) {
if (get_class($type) === TString::class) {
$combination->value_types['string'] = $type;
} elseif ($combination->value_types['string'] instanceof TTraitString
&& $type instanceof TClassString
) {
$combination->value_types['trait-string'] = $combination->value_types['string'];
$combination->value_types['class-string'] = $type;
unset($combination->value_types['string']);
} elseif (get_class($combination->value_types['string']) !== get_class($type)) {
if (get_class($type) === TNonEmptyString::class
&& get_class($combination->value_types['string']) === TNumericString::class

View File

@ -732,7 +732,6 @@ class Reconciler
if ($existing_key_type_part instanceof TNull) {
$class_property_type = Type::getNull();
} elseif ($existing_key_type_part instanceof TMixed
|| $existing_key_type_part instanceof TTemplateParam
|| $existing_key_type_part instanceof TObject
|| ($existing_key_type_part instanceof TNamedObject
&& strtolower($existing_key_type_part->value) === 'stdclass')

View File

@ -15,7 +15,6 @@ use Psalm\Internal\Type\TypeTokenizer;
use Psalm\IssueBuffer;
use Psalm\Tests\Internal\Provider\FakeParserCacheProvider;
use Psalm\Type\Union;
use RuntimeException;
use Throwable;
use function array_filter;
@ -151,15 +150,7 @@ class TestCase extends BaseTestCase
*/
protected function getTestName($withDataSet = true): string
{
$name = parent::getName($withDataSet);
/**
* @psalm-suppress TypeDoesNotContainNull PHPUnit 8.2 made it non-nullable again
*/
if (null === $name) {
throw new RuntimeException('anonymous test - shouldn\'t happen');
}
return $name;
return $this->getName($withDataSet);
}
/**