Skip to content
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

[WIP] Fix #346 - magic methods hints need to be reflected in generated child classes #350

Closed
wants to merge 7 commits into from

Conversation

Ocramius
Copy link
Owner

This is just a patch that gets us where we want, but the introduced complexity is too much, therefore will need to find a better way to implement it, without having codegen talking to every reflection layer.

@Ocramius Ocramius added the bug label Nov 22, 2016
$this->setReturnsReference($originalMethod->returnsReference());
$this->setReturnType(((string) $originalMethod->getReturnType()) ?: null);
$this->addOrReplaceParameterNames($originalMethod, ...$parameters);
} else {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Don't like this else. Can probably just call the parent constructor with the given parameters, then replace

}
}

private function addOrReplaceParameterNames(
Copy link
Owner Author

Choose a reason for hiding this comment

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

This method is way too complex: need to split into multiple private methods explaining exactly what is going on at each step.

) : void {
$originalParameters = array_values(array_map(
function (\ReflectionParameter $parameter) use ($originalMethod) : ParameterGenerator {
return ParameterGenerator::fromReflection(new ParameterReflection(
Copy link
Owner Author

Choose a reason for hiding this comment

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

Loads of coupling due to Zend\Code's shitty reflection API :-(

$parentAccess

$symbols = [
'%init' => '$this->' . $initializerProperty->getName()
Copy link
Owner Author

Choose a reason for hiding this comment

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

I should hunt down all the sprintf() and replace them with this syntax: much easier to follow.

@@ -54,7 +54,7 @@ public function __construct(
) {
parent::__construct($originalClass, '__get', [new ParameterGenerator('name')]);

$hasParent = $originalClass->hasMethod('__get');
$hasParent = $originalClass->hasMethod('__get') ? $originalClass->getMethod('__get') : null;
Copy link
Owner Author

Choose a reason for hiding this comment

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

This decision path is duplicated everywhere, and can surely be simplified.

*
* @return string
*
* @throws \InvalidArgumentException
*/
public static function getPublicAccessSimulationCode(
?\ReflectionMethod $originalMethod,
Copy link
Owner Author

Choose a reason for hiding this comment

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

BC break.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Also note: since we are passing down reflection details, we may as well get rid of a lot of runtime boilerplate, to be replaced with string constants.

case static::OPERATION_UNSET:
return 'unset($targetObject->$' . $nameParameter . ');';
return 'unset($targetObject->$' . $nameParameter . ');'
Copy link
Owner Author

Choose a reason for hiding this comment

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

return unset($foo) is not a valid expression, so I simply add a fake return block afterwards.

@@ -119,6 +121,8 @@ public function getTestedClasses() : array
return [
[BaseClass::class],
[ClassWithMagicMethods::class],
[ClassWithHintedMagicMethods::class],
//[InterfaceWithHintedMagicMethods::class],
Copy link
Owner Author

Choose a reason for hiding this comment

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

This test doesn't verify interface proxying - need to move to appropriate functional tests instead.

@Ocramius Ocramius force-pushed the fix/#346-magic-methods-hints-reproducibility branch from 7dbb2ef to acbc96f Compare May 4, 2017 11:46
…cAccessSimulationCode()`, as the parameter count changed
@Majkl578
Copy link
Contributor

Majkl578 commented Sep 3, 2018

2 years, any progress?

Two more assets that make test suite crash: Majkl578@06d9f51

Note that with 7.2+ requirement you could simply ignore parameters, but you still need return types and void. :trollface:

@Ocramius
Copy link
Owner Author

Ocramius commented Sep 3, 2018

No progress, but I could restart it. can you PR the assets to master?

@Majkl578
Copy link
Contributor

Majkl578 commented Sep 3, 2018

#427

@Ocramius Ocramius closed this Dec 20, 2020
@Ocramius Ocramius deleted the branch master December 20, 2020 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants