Skip to content

Commit

Permalink
Don’t crash when conditionally defining classes with properties
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Mar 9, 2020
1 parent 04bcc32 commit 2c8688d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Psalm/Internal/Analyzer/ClassAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,9 +1541,7 @@ private function checkForMissingPropertyType(
);

if (!$declaring_property_class) {
throw new \UnexpectedValueException(
'Cannot get declaring class for ' . $property_id
);
return;
}

$fq_class_name = $declaring_property_class;
Expand Down
8 changes: 8 additions & 0 deletions tests/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,14 @@ public function get(): A {
echo A::SOME_CONST;
}'
],
'noCrashOnClassExists' => [
'<?php
if (!class_exists(ReflectionGenerator::class)) {
class ReflectionGenerator {
private $prop;
}
}',
]
];
}

Expand Down

0 comments on commit 2c8688d

Please sign in to comment.