Skip to content

Conversation

troizet
Copy link
Collaborator

@troizet troizet commented Mar 16, 2025

If a function or method does not have a return statement, the @return void tag is generated when generating a phpDoc.

before:

before.mp4

after:

after.mp4

^Add meaningful description above

Click to collapse/expand PR instructions

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

Please make sure (eg. git log) that all commits have a valid name and email address for you in the Author field.

If you're a first time contributor, see the Contributing guidelines for more information.

If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.

PR approval and merge checklist:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

@troizet troizet added the PHP [ci] enable extra PHP tests (php/php.editor) label Mar 16, 2025
@troizet troizet requested review from junichi11 and tmysik March 16, 2025 06:52
@troizet troizet changed the title PHP: If a function or method does not have a return operator, the @return void tag is generated when generating a phpDoc PHP: If a function or method does not have a return statement, the @return void tag is generated when generating a phpDoc Mar 16, 2025
if (i.hasReturn) {
generateDocEntry(doc, toAdd, "@return", indent, null, i.getReturnType()); // NOI18N
} else {
generateDocEntry(doc, toAdd, "@return", indent, null, Type.VOID); // NOI18N
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: maybe simpler?

Suggested change
generateDocEntry(doc, toAdd, "@return", indent, null, Type.VOID); // NOI18N
generateDocEntry(doc, toAdd, "@return", indent, null, i.hasReturn ? i.getReturnType() : Type.VOID); // NOI18N

Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

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

Looks good to me, but please wait for @junichi11. Thank you for your work.

@apache apache locked and limited conversation to collaborators Mar 16, 2025
@apache apache unlocked this conversation Mar 16, 2025
@junichi11
Copy link
Member

The existing tests are executed for different purposes, so we should add tests for this fix.
e.g.

function noReturn() {
}

function hasReturn() {
    return "test";
}

function emptyReturn() {
    return;
}

function multipleEmptyReturns() {
    if (true) {
        return;
    }
    return;
}
// ... etc.

class  TestClass {
    public function noReturn() {
    }

    // ... etc.
}

interface TestInterface {
    public function test(); // in this case, should not add?
    // ... etc.
}

abstract class AbstractClass {
    public abstract function test(int $param);
    // ... etc.
}

Please also write examples to the description(Before & After). Thanks!

@junichi11 junichi11 added this to the NB26 milestone Mar 17, 2025
@troizet troizet marked this pull request as draft March 29, 2025 04:37
@neilcsmith-net neilcsmith-net modified the milestones: NB26, NB27 Apr 16, 2025
@ebarboni ebarboni modified the milestones: NB27, NB28 Jul 23, 2025
@troizet troizet removed this from the NB28 milestone Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants