Skip to content

Commit

Permalink
Reverse-engineer actual type from code (#10221)
Browse files Browse the repository at this point in the history
The code contains tests for is_array(), is object(), and an else clause.
The type is wrong, and the variable name misleading.
  • Loading branch information
greg0ire committed Nov 11, 2022
1 parent 7e45ad9 commit 465c02f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
20 changes: 10 additions & 10 deletions lib/Doctrine/ORM/Query/AST/Node.php
Expand Up @@ -49,19 +49,19 @@ public function __toString()
}

/**
* @param object $obj
* @param mixed $value
*
* @return string
*/
public function dump($obj)
public function dump($value)
{
static $ident = 0;

$str = '';

if ($obj instanceof Node) {
$str .= get_debug_type($obj) . '(' . PHP_EOL;
$props = get_object_vars($obj);
if ($value instanceof Node) {
$str .= get_debug_type($value) . '(' . PHP_EOL;
$props = get_object_vars($value);

foreach ($props as $name => $prop) {
$ident += 4;
Expand All @@ -71,23 +71,23 @@ public function dump($obj)
}

$str .= str_repeat(' ', $ident) . ')';
} elseif (is_array($obj)) {
} elseif (is_array($value)) {
$ident += 4;
$str .= 'array(';
$some = false;

foreach ($obj as $k => $v) {
foreach ($value as $k => $v) {
$str .= PHP_EOL . str_repeat(' ', $ident) . '"'
. $k . '" => ' . $this->dump($v) . ',';
$some = true;
}

$ident -= 4;
$str .= ($some ? PHP_EOL . str_repeat(' ', $ident) : '') . ')';
} elseif (is_object($obj)) {
$str .= 'instanceof(' . get_debug_type($obj) . ')';
} elseif (is_object($value)) {
$str .= 'instanceof(' . get_debug_type($value) . ')';
} else {
$str .= var_export($obj, true);
$str .= var_export($value, true);
}

return $str;
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Expand Up @@ -425,16 +425,6 @@ parameters:
count: 1
path: lib/Doctrine/ORM/Query/AST/JoinVariableDeclaration.php

-
message: "#^Call to function is_array\\(\\) with object will always evaluate to false\\.$#"
count: 1
path: lib/Doctrine/ORM/Query/AST/Node.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: lib/Doctrine/ORM/Query/AST/Node.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Query\\\\SqlWalker\\:\\:walkWhenClauseExpression\\(\\)\\.$#"
count: 1
Expand Down
8 changes: 0 additions & 8 deletions psalm-baseline.xml
Expand Up @@ -1830,14 +1830,6 @@
<code>$sqlWalker</code>
</ParamNameMismatch>
</file>
<file src="lib/Doctrine/ORM/Query/AST/Node.php">
<DocblockTypeContradiction occurrences="1">
<code>is_array($obj)</code>
</DocblockTypeContradiction>
<RedundantConditionGivenDocblockType occurrences="1">
<code>is_object($obj)</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="lib/Doctrine/ORM/Query/AST/NullComparisonExpression.php">
<ParamNameMismatch occurrences="1">
<code>$sqlWalker</code>
Expand Down

0 comments on commit 465c02f

Please sign in to comment.