Skip to content

#2861: Support throw of static methods#2890

Merged
TomasVotruba merged 1 commit intorectorphp:masterfrom
Aerendir:AnnotateThrowables-support-static-methods
Feb 20, 2020
Merged

#2861: Support throw of static methods#2890
TomasVotruba merged 1 commit intorectorphp:masterfrom
Aerendir:AnnotateThrowables-support-static-methods

Conversation

@Aerendir
Copy link
Copy Markdown
Contributor

@Aerendir Aerendir commented Feb 19, 2020

#2889 (general discussion: #2861).

What this should support

function throwThroughStaticMethod()
{
    throw ExcetionFactory::createException();
}

Explanation

See the test case here: https://github.com/rectorphp/rector/blob/71ad810c8c777def532af6ff22be6d4d900b3bdd/rules/coding-style/tests/Rector/Throw_/AnnotateThrowablesRector/Fixture/factory_static_method_with_return_dockblock.php.inc

The problem is to read the Docblock of the invoked method.

One approach, as suggested in #2861 (#2861 (comment)) is to use the reflection.

Currently it is possible to obtain the Docblock using reflection, but the docblock is obtained as a simple string and it cannot be parsed.

Obtaining a simple string is useless, as it makes impossible to know which classes are actually returned.

    /**
     * This is the DocComment of createExceptionEccolo().
     *
     * @param int $code
     *
     * @return TheException|TheExceptionTheSecond|TheExceptionTheThird|\RuntimeException
     */

Is TheException something like Namespace1\TheException or is it Namespace2\TheExeception?

Without being able to access a parsed version of the Docblock, it is impossible to know what is returned by the invoked static method.

@TomasVotruba , WDYT?

@Aerendir Aerendir changed the title Try to read the Dockblosk of the thrown static method. #2861: Support throw of static methods Feb 19, 2020
Comment thread rules/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php
@Aerendir
Copy link
Copy Markdown
Contributor Author

@TomasVotruba , ready to be merged! 💪

@TomasVotruba TomasVotruba merged commit ec50ab5 into rectorphp:master Feb 20, 2020
@TomasVotruba
Copy link
Copy Markdown
Member

Great job!

@Aerendir Aerendir deleted the AnnotateThrowables-support-static-methods branch February 21, 2020 09:09
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.

2 participants