-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
Support new in initializers #966
Conversation
The static analysis failure is my fault, I guess. 🙈 See #967. |
8f43d78
to
bcfaaa8
Compare
@derrabus I knew I've seen that PR somewhere, couldn't recall where :D thanks for creating a fix so quickly 🍻 |
Please rebase, static analysis should be green now. 🤞🏻 |
bcfaaa8
to
205401e
Compare
@nicolas-grekas Can you have a look, please? |
@@ -1116,6 +1116,33 @@ private function getParameterType(ReflectionParameter $parameter) | |||
return $this->formatType($parameter->getType(), $declaringFunction, $parameter); | |||
} | |||
|
|||
/** | |||
* @return string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a native type declaration here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason, I was mimicking other methods in the generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's deal with those globally later? We will be able to add them to private methods only though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctrine/common
is probably going to die soon, so that's really not a big deal, we can deal with it later or not at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referring to a discussion on a private Slack.
continue; | ||
} | ||
|
||
$part = preg_replace('/(?(DEFINE)(?<V>[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+))(?<!\\\\)(?&V)(?:\\\\(?&V))*+::/', '\\\\$0', $part); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this line? When I comment it out, the test below does not fail 🤔 … I'm using PHP 8.1.8 Likewise, if I put rubbish in the regex line 1133, no test fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have absolutely no clue, I took what @nicolas-grekas provided for ProxyManager for granted 🙈 Tried to go for original FriendsOfPHP PR but nobody challenged that there either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's just return what's on line 1132? It seems to be the important part of this patch. When somebody reports the bug the bottom part fixes, let's make sure to add a test that documents it, as well as comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regexp is supposed to add the \
prefix to internal classes when they declare a default value that references a class constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like it would also affect top-level classes that are not internal, but user defined, wouldn't it? In both cases, I'm unsure if doctrine/common
should support it, as AFAIK it's only ever used to proxify entities and documents, that should never be in the top-level namespace, or inherit from a class defined in it. Unlike proxy-manager I suppose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be quite weird but I not completely impossible I suppose. @malarzm , I think we should either add a test case based on ArrayObject::asort()
(which refers to a constant), or drop the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added part with using global const, it does fail without those regexes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really? When I try again what I did in #966 (comment) on eb0aaa5, the test still passes 🤔
Also, dumping $part
shows no prepended backslash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really?
Dang, sorry. I made an early return in getDefaultValue
that was supposed to break the test... it did, but for totally other reason :s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, I'm giving up. I'm almost starting my vacations and I think it'll be better to have main cases covered. If somebody reports a bug that could be fixed by regexes I've just removed then it can be done in a bugfix manner.
} | ||
|
||
$value = rtrim(substr(explode('$' . $parameter->getName() . ' = ', (string) $parameter, 2)[1], 0, -2)); | ||
$parts = preg_split('{(\'(?:[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')}', $value, -1, PREG_SPLIT_DELIM_CAPTURE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to use the x
delimiter and add comments inside that regex. If that makes it become multiline, then maybe also use nowdoc? That way there won't be a need for escaping the single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as above
205401e
to
eb0aaa5
Compare
eb0aaa5
to
70a835e
Compare
70a835e
to
a45d437
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have a nice vacation!
Port of Ocramius/ProxyManager#755
Fixes #961