[PHP] Return type changed in PHP >= 8-0. Fluent setters now return static.#9431
[PHP] Return type changed in PHP >= 8-0. Fluent setters now return static.#9431DamImpr wants to merge 1 commit into
static.#9431Conversation
Initial test cases prevent the return type from being generated in the PHPDoc when it is a constructor. prevent the return type from being generated in the PHPDoc when it is a constructor. Removed the return type from the constructor in the list of methods to override commit missing file fix compare insensitive
static.static.
matthiasblaesing
left a comment
There was a problem hiding this comment.
In general makes sense to me. I left an inline comment, regarding an unintentional change?!
@tmysik could you please have a look?
| List<PhpElement> topLevelElements = new ArrayList<>(request.index.getTopLevelElements(prefix, aliasedNames, Trait.ALIAS)); | ||
| topLevelElements.sort(Comparator.comparing(PhpElement::getName, String.CASE_INSENSITIVE_ORDER)); | ||
| for (final PhpElement element : topLevelElements) { |
There was a problem hiding this comment.
Is this intentionally here? This does not seem to be relevant for the declared intention of the PR or am I wrong?
There was a problem hiding this comment.
Hi @matthiasblaesing
You’re right, it isn’t mentioned in the PR description.
It’s a change I made after development because two tests were failing when I ran tests on the php.editor.completion package, specifically testFunctionGuessingArrayReturnType_01 and testFunctionGuessingArrayReturnType_02.
In short, the return types did not have a deterministic order. For example, the method might return an array|string, which is valid in the language but differs from what the test method expected, namely string|array.
This change ensures a deterministic order, and the test suite no longer fails.
I’m not sure whether, given the project’s policies, this can be merged alongside the fix I’ve made. Please let me know if this is fine or if a separate PR is needed.
Thanks
There was a problem hiding this comment.
Ok, I don't see a problem in having the completion list deterministic and sorted is IMHO a good base.
|
@matthiasblaesing I will look into it tomorrow. |
From PHP version 8.0 onwards, the "static" return type has been adopted for fluent setters. In the "Generate Code" menu in NetBeans, no return type was assigned when fluent setters were created. This PR ensures that fluent setters, when used in a project configured with PHP version >= 8.0, correctly have the "static" return type.