Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Fix code reflection - getBody/getContents method #5245

Closed
wants to merge 15 commits into from
Closed

Fix code reflection - getBody/getContents method #5245

wants to merge 15 commits into from

Conversation

blanchonvincent
Copy link
Contributor

Zend\Code\Reflection getBody function is often broken with some code format

  • implement getBody in FunctionReflection
  • fix getBody in MethodReflection
  • fix getContents in FunctionReflection
  • fix getContents in MethodReflection

* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Code
Copy link
Contributor

Choose a reason for hiding this comment

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

remove @Package

@blanchonvincent
Copy link
Contributor Author

@Ocramius can you confirm that on this function :

function1()
{
    return 'foo';
}

getBody is :

return 'foo';

getContent is :

function1()
{
    return 'foo';
}

?

@Ocramius
Copy link
Member

@blanchonvincent never used that API - are there no other tests for it?

@blanchonvincent
Copy link
Contributor Author

@Ocramius The prototype is

public function getContents($includeDocBlock = true)

So, if the contents is :

{
   return ....;
}

what is the contents with docblock ? I think there is a bug, and the contents must be :

function foo()
{
   return ....;
}

and with docblock :

/**
 * bla bla bla
 */
function foo()
{
   return ....;
}

@Ocramius
Copy link
Member

@blanchonvincent yep, I agree on that. I'd just first check what the consumers of that method are before applying any change.

@blanchonvincent
Copy link
Contributor Author

@Ocramius, Ok, let me know

@Ocramius
Copy link
Member

@blanchonvincent no, I was suggesting you to grep for its usage :)

@blanchonvincent
Copy link
Contributor Author

@Ocramius, Look never used, and $useDockBlock param doesn't work, and lot of time, the function return an empty result ... so I fix that.

@blanchonvincent
Copy link
Contributor Author

PR is finished -- better code coverage & lot of fixs

@mwillbanks
Copy link
Contributor

@Ocramius since you did original review; could you please review a last time?


$content = false;
if ($this->isClosure()) {
preg_match('#function\s*\([^\)]*\)\s*(use\s*\([^\)]+\))?\s*\{(.*\;)?\s*\}#s', $functionLine, $matches);
Copy link
Member

Choose a reason for hiding this comment

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

Woah, this witchcraft needs a comment :-)

Copy link
Member

Choose a reason for hiding this comment

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

Does this handle also closures containing closures?

Copy link
Member

Choose a reason for hiding this comment

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

@Ocramius I don't see any reason why it wouldn't -- the body regex is looking for any number of terminated statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ocramius, yep, look at the tests


$body = false;
if ($this->isClosure()) {
preg_match('#function\s*\([^\)]*\)\s*(use\s*\([^\)]+\))?\s*\{(.*\;)\s*\}#s', $functionLine, $matches);
Copy link
Member

Choose a reason for hiding this comment

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

Same remarks as above

Copy link
Member

Choose a reason for hiding this comment

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

Also: these regexes look constant. Can you move them to either a class constant or a private property?

Copy link
Member

Choose a reason for hiding this comment

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

They're not -- there are subtle differences in what each is matching.

@Maks3w
Copy link
Member

Maks3w commented Oct 29, 2013

@blanchonvincent Please rebase the PR for fix merge conflicts

weierophinney added a commit that referenced this pull request Oct 30, 2013
…ator-functiongenerator

Fix code reflection - getBody/getContents method

Conflicts:
	library/Zend/Code/Reflection/FunctionReflection.php
	library/Zend/Code/Reflection/MethodReflection.php
	tests/ZendTest/Code/Reflection/FunctionReflectionTest.php
	tests/ZendTest/Code/Reflection/MethodReflectionTest.php
weierophinney added a commit that referenced this pull request Oct 30, 2013
- trailing whitespace, braces
- Added functions.php to the exclude list for php-cs-fixer, as the tests are
  testing specific formatting issues.
weierophinney added a commit that referenced this pull request Oct 30, 2013
@ghost ghost assigned weierophinney Oct 30, 2013
@weierophinney
Copy link
Member

Merged to develop for release with 2.3.0, as it represents new functionality. I took care of the merge conflicts.

stefanotorresi pushed a commit to stefanotorresi/zf2 that referenced this pull request Oct 31, 2013
@stefanotorresi stefanotorresi mentioned this pull request Oct 31, 2013
weierophinney added a commit that referenced this pull request Nov 1, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants