New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove always true/false conditions #7229
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TMixed is handled above |
||
&& !$atomic_key_type instanceof TTemplateParam | ||
&& !( | ||
$atomic_key_type instanceof TObjectWithProperties | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TNull is handled above |
||
&& $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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,22 +87,6 @@ public static function analyze( | |
return; | ||
} | ||
|
||
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BitwiseXor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BitwiseXor is handled above |
||
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 @@ public static function analyze( | |
|
||
return; | ||
} | ||
|
||
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BitwiseOr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BitwiseOr is handled above |
||
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' | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -671,7 +671,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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TTemplateParam can't get here, there's a continue above: https://github.com/vimeo/psalm/pull/7229/files#diff-2b5a0d000f3703de9fd772b1a15dc0290371dcd5e742a2f6d583e44796199bd7L635 |
||
} elseif ($var_type_part instanceof TMixed) { | ||
$has_valid_function_call_type = true; | ||
|
||
IssueBuffer::maybeAdd( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,12 +169,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev | |
$function_call_arg->value->items[1]->value->value, | ||
[] | ||
); | ||
} elseif ($variable_atomic_type instanceof TTemplateParamClass) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TTemplateParamClass is handled above with the same content in the conditional |
||
$fake_method_call = new VirtualStaticCall( | ||
$function_call_arg->value->items[0]->value, | ||
$function_call_arg->value->items[1]->value->value, | ||
[] | ||
); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TNull was already returned here: https://github.com/vimeo/psalm/pull/7229/files#diff-e17ecd10daef9f0bed66b49fc187403cae341f5a3994fdf1f776f044103a3e66L128 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's for the container type part, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, so it goes |
||
continue; | ||
} | ||
|
||
if (self::isContainedBy( | ||
$codebase, | ||
$input_as_type_part, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TNonEmptyNonspecificLiteralString is a child of TNonspecificLiteralString just above |
||
&& ($input_type_part instanceof TLiteralString || $input_type_part instanceof TNonspecificLiteralString) | ||
) { | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $type instanceof TClassString was handled in another branch |
||
) { | ||
$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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
) { | ||
$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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continued just above |
||
|| $existing_key_type_part instanceof TObject | ||
|| ($existing_key_type_part instanceof TNamedObject | ||
&& strtolower($existing_key_type_part->value) === 'stdclass') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-nullable since 8.2 and Psalm 4 requires PHPunit 9 |
||
throw new RuntimeException('anonymous test - shouldn\'t happen'); | ||
} | ||
|
||
return $name; | ||
return $this->getName($withDataSet); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TEmpty is already covered by Scalar on the previous if