cancel
Showing results for 
Search instead for 
Did you mean: 

Reflection return type does not handle use statements

0 Kudos

Reflection return type does not handle use statements

Feature request from mc388, posted on GitHub Mar 14, 2016

Steps to reproduce

  1. Install Magento v2.0.2
  2. Create a new API method
  3. Change method phpdoc from @return \Magento\Sales\Api\Data\OrderInterface Order interface to @return OrderInterface Order interface and add a use statement for Magento\Sales\Api\Data\OrderInterface
  4. Call the new API method

Expected result

  1. API should return an OrderInterface object

Actual result

  1. Class OrderInterface does not exists

I think the issue is in Magento\Framework\Reflection\TypeProcessor->getGetterReturnType. You just read the @return flag but ignore the use statement.

3 Comments
Not applicable

Comment from Vinai, posted on GitHub Mar 14, 2016

That is a limitation of the PHP interpreter, PHPUnit for example has the same "issue" when parsing @covers and @uses annotations. The class imports are resolved by the PHP interpreter using a kind of pre-processing of the source code, but the comments are just treated as plain text, not code. however, any code that tries to apply namespaces to non-fully qualified class names in annotations would not only have to resolve class name imports, but also would have to keep track of the current namspace in the PHP file, which I would imagine would be not that trivial, since PHP allowes multiple namespaces per file. I also got bitten by not using fully qualified class names in PHPDoc comments, but after some digging I changed the way I thought about them.

Not applicable

Comment from piotrekkaminski, posted on GitHub Jun 14, 2016

@antonkril can you look into it?

Not applicable

Comment from antonkril, posted on GitHub Jul 15, 2016

Yes, it's a limitation of parser. It can be scheduled as improvement.