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

Nullable flag on constructor property promotion, closes #183 #184

Open
wants to merge 1 commit into
base: 4.12.x
Choose a base branch
from

Conversation

Grundik
Copy link

@Grundik Grundik commented May 16, 2023

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

See #183 for details.

Comment on lines 170 to 176
/**
* @return ?TypeGenerator
*/
public function getTypeObject()
{
return $this->type;
}
Copy link
Member

Choose a reason for hiding this comment

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

Exposing the type to the outside world seems like a regression here, as it will reduce the ability to change the codebase later on.

Comment on lines 90 to 92
if (
null !== $type
&& ($typeObject = $generator->getTypeObject())
&& $typeObject->getNullable()
) {
$type = '?' . $type;
}
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if the $type of ParameterGenerator could be exposed internally only: we could then get rid of the string type overall

Copy link
Author

Choose a reason for hiding this comment

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

Changed that to exposing only nullable flag.

Copy link
Member

Choose a reason for hiding this comment

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

@Grundik I don't have a clear mind on the approach here yet, but I'm trying to think of a design that removes public, and ideally avoids protected (although the inheritance design is already out of the bag)

Copy link
Author

Choose a reason for hiding this comment

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

The other way I see, is to make ParameterGenerator#generateTypeHint public, this would not require exposing getNullable().

But it looks like no big deal to expose that: there a lot of other flags exposed in a same way: passedByReference, vadiadic and such.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I'm much in "damage control" mode here, since the generator, builder and reflection-alike structure has been merged together in the past, making changes to internal structures lead to major versions :)

I'll sleep over it, but I'd rather not expose more than is strictly needed for ->generate() to work.

Copy link
Author

@Grundik Grundik May 16, 2023

Choose a reason for hiding this comment

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

Currenly there are no simple way to get this flag. E.g. parsing result of ParameterGenerator->generate() would be ugly, fragile, slow and overcomplicated.

Copy link
Member

Choose a reason for hiding this comment

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

Nono, I'm absolutely not suggesting that we go down the parsing way :)

Copy link
Author

Choose a reason for hiding this comment

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

Any additional thoughs?..

@Grundik
Copy link
Author

Grundik commented May 16, 2023

Just to be clear: this is not the fix for Ocramius/ProxyManager#784, there are at leas two different issues:

  • this one, with missing nullable flag (and seems like Promoted properties missing default value #182 also could kead to problems);
  • proxy-manager one: these reflections are used in inheritance context there, hence they dont need to redeclare promoted properties at all in that particular situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants