8000 [PropertyInfo] Extract property type from property declaration by tsantos84 · Pull Request #31798 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyInfo] Extract property type from property declaration #31798

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

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[PropertyInfo] Prevent exception in case the property doesn't exist
  • Loading branch information
tsantos84 committed Jun 7, 2019
commit 2a273c11bf03dca98d09557dd741710d057df834
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ private function extractFromDeclaredType(string $class, string $property)

try {
$reflectionClass = new \ReflectionClass($class);
$reflectionProperty = $reflectionClass->getProperty($property);
} catch (\ReflectionException $e) {
return null;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent test fails you can add following code here:

if (!$reflectionClass->hasProperty($property)) {
    return null;
}

Copy link
@mshavliuk mshavliuk Jun 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can expand try-catch block for the whole function content (to prevent errors, which can happen while calling hasType, getProperty, getType etc. which can throw ReflectionException).
I think the best option - add either hasProperty or expand try-catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've used the same try/catch block where I create the reflection class to get the property, and if it doesn't exist, it'll return null

$reflectionProperty = $reflectionClass->getProperty($property);

if (!$reflectionProperty->hasType()) {
return null;
Expand Down
0