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

Use correct class names in the ClassGenerator implements and extend. #69

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Jun 25, 2016

This PR fixes #64. It will try to look for the classnames in the use statements and will validate if the classes live in the same namespace as the class that is being generated.
If this is the case, the short classname is being used instead of the full classname.
If this is not the case, the backslash is added to make sure that the classes can be loaded by PHP.

@veewee veewee force-pushed the feature/valid-extends-and-implements-classnames branch from 77d26f3 to 4a6f4ab Compare June 25, 2016 08:47
@weierophinney weierophinney added this to the 3.0.3 milestone Jun 27, 2016
@weierophinney weierophinney self-assigned this Jun 27, 2016
@weierophinney weierophinney merged commit 4a6f4ab into zendframework:master Jun 27, 2016
weierophinney added a commit that referenced this pull request Jun 27, 2016
…ts-classnames

Use correct class names in the ClassGenerator implements and extend.
weierophinney added a commit that referenced this pull request Jun 27, 2016
weierophinney added a commit that referenced this pull request Jun 27, 2016
weierophinney added a commit that referenced this pull request Jun 27, 2016
@weierophinney
Copy link
Member

Thanks, @veewee !

kamilZ added a commit to kamilZ/zend-code that referenced this pull request Jun 28, 2016
Error: symfony/symfony#9815
Tag: v3.0.3
PHP: 7.0.4 

This should solve the issue with PR zendframework#69  
@veewee check this out, please. I don't know if the ternary condition will be necessary. I put it anyway for compatibility with lower php version.
@stof
Copy link
Contributor

stof commented Jun 28, 2016

This is broken in case the class names used in setExtendedClass or setImplementedInterfaces contain the leading backslash (which was nececessary previously to make it work), as it will not generate 2 leading backslashes

@veewee
Copy link
Contributor Author

veewee commented Jun 28, 2016

That is indeed a case I did not know about and therefor did not cover. You might just want to use array_filter() on the $parts variable (https://github.com/zendframework/zend-code/pull/69/files#diff-0e7af4276dd38adadab5d0307db17a3dR1021).
This will remove the first backslash.

@stof
Copy link
Contributor

stof commented Jun 28, 2016

or just ltrim($class, '\\') before exploding

@veewee
Copy link
Contributor Author

veewee commented Jun 28, 2016

A patch has been created by @qRoC in #75.
Are there other use cases you can think of which causes generateShortOrCompleteClassname() to break existing code?

@stof
Copy link
Contributor

stof commented Jun 28, 2016

no, I don't think about other cases

basz added a commit to basz/zend-code that referenced this pull request Sep 28, 2016
* 'master' of https://github.com/zendframework/zend-code: (39 commits)
  Fix Travis code convention
  Fix Travis code convention
  Fix Travis code convention
  Fix Travis code convention
  1. Fix ClassScanner::getInterfaces() which don't work with Interface. 2. add TestCase  ClassScannerTest::testGetInterfacesFromInterface().
  Remove fast_finish flag
  Bumped to next dev version (3.0.5)
  Added CHANGELOG for zendframework#75
  Separated new tests to separate methods
  testCorrectExtendNamesFromGlobalNamespace
  add tests
  Added CHANGELOG for zendframework#59
  Update ClassGenerator.php
  fast fix
  Bumped to next dev version (3.0.4)
  Set date for 3.0.3
  Added CHANGELOG for zendframework#72
  Added CHANGELOG for zendframework#69
  Added CHANGELOG for zendframework#61
  Provide a fix for issue zendframework#70
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClassGenerator::fromReflection() breaks extends and implements
3 participants