Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Oct 3, 2025

On latest PHPStan 2.1.30, using Interface::* seems mark as all must be returned, but not support partial of it, so use int over it.

Added comment note for how return int works.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 3fabc95 into main Oct 3, 2025
50 checks passed
@samsonasik samsonasik deleted the fix-phpstan-return-int branch October 3, 2025 21:18
Comment on lines +23 to 33
* @return Node|Node[]|null|int
*
* For int return, choose:
*
* ✔️ To decorate current node and its children to not be traversed on current rule, return one of:
* - NodeVisitor::DONT_TRAVERSE_CHILDREN
* - NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN
*
* ✔️ To remove node of Node\Stmt or Node\Param, return:
* - NodeVisitor::REMOVE_NODE
*/
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to keep original list, as now any int value can be returned by PHPStan, which is not true.
Could you revert this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, the rule classes itself then need update to add @return for specific constant then, eg:

    /**
     * @param StmtsAwareInterface $node
+    * @return null|Node|NodeVisitor::DONT_TRAVERSE_CHILDREN
     */
    public function refactor(Node $node): null|Node|int

I will revert this and update rule classes

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 created PR to use NodeVisitor::* on RectorInterface::refactor(), then update its rules @return to use its constant at PR:

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.

4 participants