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

Remove redundant code found by Psalm

This commit is contained in:
Matt Brown 2018-02-07 13:57:45 -05:00
parent 7bfd782d90
commit b4281748bc
6 changed files with 26 additions and 31 deletions

View File

@ -901,15 +901,15 @@ class AssertionFinder
*/
protected static function hasNullVariable(PhpParser\Node\Expr\BinaryOp $conditional)
{
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->right->name instanceof PhpParser\Node\Name &&
strtolower($conditional->right->name->parts[0]) === 'null') {
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->right->name->parts[0]) === 'null'
) {
return self::ASSIGNMENT_TO_RIGHT;
}
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->left->name instanceof PhpParser\Node\Name &&
strtolower($conditional->left->name->parts[0]) === 'null') {
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->left->name->parts[0]) === 'null'
) {
return self::ASSIGNMENT_TO_LEFT;
}
@ -923,15 +923,15 @@ class AssertionFinder
*/
protected static function hasFalseVariable(PhpParser\Node\Expr\BinaryOp $conditional)
{
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->right->name instanceof PhpParser\Node\Name &&
strtolower($conditional->right->name->parts[0]) === 'false') {
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->right->name->parts[0]) === 'false'
) {
return self::ASSIGNMENT_TO_RIGHT;
}
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->left->name instanceof PhpParser\Node\Name &&
strtolower($conditional->left->name->parts[0]) === 'false') {
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->left->name->parts[0]) === 'false'
) {
return self::ASSIGNMENT_TO_LEFT;
}
@ -945,15 +945,15 @@ class AssertionFinder
*/
protected static function hasTrueVariable(PhpParser\Node\Expr\BinaryOp $conditional)
{
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->right->name instanceof PhpParser\Node\Name &&
strtolower($conditional->right->name->parts[0]) === 'true') {
if ($conditional->right instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->right->name->parts[0]) === 'true'
) {
return self::ASSIGNMENT_TO_RIGHT;
}
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch &&
$conditional->left->name instanceof PhpParser\Node\Name &&
strtolower($conditional->left->name->parts[0]) === 'true') {
if ($conditional->left instanceof PhpParser\Node\Expr\ConstFetch
&& strtolower($conditional->left->name->parts[0]) === 'true'
) {
return self::ASSIGNMENT_TO_LEFT;
}

View File

@ -192,7 +192,6 @@ class PropertyAssignmentChecker
// Hack has a similar issue: https://github.com/facebook/hhvm/issues/5164
if ($lhs_type_part instanceof TObject ||
(
$lhs_type_part instanceof TNamedObject &&
in_array(
strtolower($lhs_type_part->value),
['stdclass', 'simplexmlelement', 'dateinterval', 'domdocument', 'domnode'],

View File

@ -282,11 +282,10 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
$class_template_params = null;
if ($stmt->var instanceof PhpParser\Node\Expr\Variable &&
($context->collect_initializations || $context->collect_mutations) &&
$stmt->var->name === 'this' &&
is_string($stmt->name) &&
$source instanceof FunctionLikeChecker
if ($stmt->var instanceof PhpParser\Node\Expr\Variable
&& ($context->collect_initializations || $context->collect_mutations)
&& $stmt->var->name === 'this'
&& $source instanceof FunctionLikeChecker
) {
self::collectSpecialInformation($source, $stmt->name, $context);
}

View File

@ -260,7 +260,7 @@ class StaticCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
) {
if (MethodChecker::checkStatic(
$method_id,
$stmt->class instanceof PhpParser\Node\Name && strtolower($stmt->class->parts[0]) === 'self',
strtolower($stmt->class->parts[0]) === 'self',
$project_checker,
new CodeLocation($source, $stmt),
$statements_checker->getSuppressedIssues()

View File

@ -310,7 +310,7 @@ class ArrayFetchChecker
$array_access_type = Type::getMixed();
}
}
} elseif ($type instanceof ObjectLike) {
} else {
if ($key_value !== null) {
if (isset($type->properties[$key_value]) || $replacement_type) {
$has_valid_offset = true;

View File

@ -193,11 +193,8 @@ class PropertyFetchChecker
// stdClass and SimpleXMLElement are special cases where we cannot infer the return types
// but we don't want to throw an error
// Hack has a similar issue: https://github.com/facebook/hhvm/issues/5164
if ($lhs_type_part instanceof TObject ||
(
$lhs_type_part instanceof TNamedObject &&
in_array(strtolower($lhs_type_part->value), ['stdclass', 'simplexmlelement'], true)
)
if ($lhs_type_part instanceof TObject
|| in_array(strtolower($lhs_type_part->value), ['stdclass', 'simplexmlelement'], true)
) {
$stmt->inferredType = Type::getMixed();
continue;