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

Support new in initializers #966

Merged
merged 1 commit into from
Aug 23, 2022
Merged

Support new in initializers #966

merged 1 commit into from
Aug 23, 2022

Conversation

malarzm
Copy link
Member

@malarzm malarzm commented Aug 7, 2022

@malarzm malarzm added this to the 3.4.0 milestone Aug 7, 2022
@malarzm malarzm changed the base branch from 3.3.x to 3.4.x August 7, 2022 17:59
@derrabus
Copy link
Member

derrabus commented Aug 7, 2022

The static analysis failure is my fault, I guess. 🙈 See #967.

@malarzm malarzm force-pushed the new-in-initializers branch from 8f43d78 to bcfaaa8 Compare August 7, 2022 18:06
@malarzm
Copy link
Member Author

malarzm commented Aug 7, 2022

@derrabus I knew I've seen that PR somewhere, couldn't recall where :D thanks for creating a fix so quickly 🍻

@derrabus
Copy link
Member

derrabus commented Aug 7, 2022

Please rebase, static analysis should be green now. 🤞🏻

@malarzm malarzm force-pushed the new-in-initializers branch from bcfaaa8 to 205401e Compare August 7, 2022 18:13
@derrabus
Copy link
Member

derrabus commented Aug 7, 2022

@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
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Member

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.

Choose a reason for hiding this comment

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

Interesting! @greg0ire are you referring to #826 here?

Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@greg0ire greg0ire Aug 16, 2022

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

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 :)

Copy link
Member

@greg0ire greg0ire Aug 21, 2022

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.

Copy link
Member Author

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

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same thing as above

@malarzm malarzm force-pushed the new-in-initializers branch from 205401e to eb0aaa5 Compare August 21, 2022 17:16
@malarzm malarzm requested a review from greg0ire August 21, 2022 17:20
@malarzm malarzm force-pushed the new-in-initializers branch from eb0aaa5 to 70a835e Compare August 22, 2022 21:37
@malarzm malarzm force-pushed the new-in-initializers branch from 70a835e to a45d437 Compare August 22, 2022 21:41
Copy link
Member

@greg0ire greg0ire left a 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!

@malarzm malarzm merged commit cbd8a6d into 3.4.x Aug 23, 2022
@malarzm malarzm deleted the new-in-initializers branch August 23, 2022 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile Error: Constant expression contains invalid operations
5 participants