Skip to content

Commit

Permalink
Merge pull request #7229 from orklah/cleanup5
Browse files Browse the repository at this point in the history
remove always true/false conditions
  • Loading branch information
orklah committed Dec 27, 2021
2 parents 33466d8 + 3ae8098 commit 3828db5
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 105 deletions.
10 changes: 2 additions & 8 deletions src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php
Expand Up @@ -41,7 +41,6 @@
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;
Expand Down Expand Up @@ -502,16 +501,11 @@ public static function checkIteratorType(

$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();
Expand Down
Expand Up @@ -188,7 +188,6 @@ public static function analyze(
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
Expand Down
Expand Up @@ -1214,11 +1214,7 @@ private static function analyzeDestructuringAssignment(
&& !$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(
Expand Down
Expand Up @@ -87,22 +87,6 @@ public static function analyze(
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());
Expand Down Expand Up @@ -146,25 +130,5 @@ public static function analyze(

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'
);
}
}
}
Expand Up @@ -677,7 +677,7 @@ private static function getAnalyzeNamedExpression(

$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(
Expand Down
Expand Up @@ -169,12 +169,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
$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,
[]
);
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php
Expand Up @@ -395,10 +395,6 @@ public static function isContainedBy(
}

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,
Expand Down
4 changes: 1 addition & 3 deletions src/Psalm/Internal/Type/Comparator/ScalarTypeComparator.php
Expand Up @@ -89,9 +89,7 @@ public static function isContainedBy(
}

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;
}
Expand Down
31 changes: 1 addition & 30 deletions src/Psalm/Internal/Type/TypeCombiner.php
Expand Up @@ -53,7 +53,6 @@
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;
Expand Down Expand Up @@ -1050,42 +1049,14 @@ private static function scrapeStringProperties(

$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;
}
} 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
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Type/Reconciler.php
Expand Up @@ -732,7 +732,6 @@ private static function getValueForKey(
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')
Expand Down
11 changes: 1 addition & 10 deletions tests/TestCase.php
Expand Up @@ -15,7 +15,6 @@
use Psalm\IssueBuffer;
use Psalm\Tests\Internal\Provider\FakeParserCacheProvider;
use Psalm\Type\Union;
use RuntimeException;
use Throwable;

use function array_filter;
Expand Down Expand Up @@ -151,15 +150,7 @@ public function analyzeFile($file_path, Context $context, bool $track_unused_sup
*/
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);
}

/**
Expand Down

0 comments on commit 3828db5

Please sign in to comment.