Skip to content

[PropertyInfo] Extract the logic converting a php doc to a Type #19484

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

Merged
merged 1 commit into from
Sep 14, 2016

Conversation

GuilhemN
Copy link
Contributor

Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This PR creates a new trait PhpDocTypeHelperTrait extracting some logic of the PhpDocExtractor.
I would like to detect the return type of some methods but this is not easily doable as I have to transform the doc types to a Type instance.

Is this ok for you ?

@dunglas
Copy link
Member

dunglas commented Aug 1, 2016

I got the use case and it is legitimate, but what do you think about creating a new utility class instead of a trait? It would be easier to test and a cleaner design IMO.

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Aug 1, 2016

@dunglas looks good to me as well :)
Is it better like that ?

@dunglas
Copy link
Member

dunglas commented Aug 6, 2016

Last nitpicking (I hope): why using static methods here? A typical class would be cleaner IMO (even if it has no state).

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Aug 7, 2016

@dunglas I made it static because it is very unlikely to change and to be extended but a typical class is fine for me as well :)

*
* @return Type|null
*/
private static function createType($docType, $nullable)
Copy link
Contributor Author

@GuilhemN GuilhemN Aug 25, 2016

Choose a reason for hiding this comment

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

Should we let static the private methods?

@stof
Copy link
Member

stof commented Aug 25, 2016

@Ener-Getick a static API creates hard coupling, and is harder to evolve in the future because of that. So I would prefer using a normal class here

@GuilhemN
Copy link
Contributor Author

GuilhemN commented Aug 25, 2016

@stof that's already the case except for the private methods which are static, i don't even remember why.
I'll make them normal for consistency.

/**
* Creates a {@see Type} from a PHPDoc tag.
*
* @param Var_|Return_|Param $tag
Copy link
Member

Choose a reason for hiding this comment

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

Rather than such mixed argument, used only to get its type, I would take the phpDocumentor\Reflection\Type directly as argument

@fabpot
Copy link
Member

fabpot commented Sep 14, 2016

Thank you @Ener-Getick.

@fabpot fabpot merged commit d6e93d8 into symfony:master Sep 14, 2016
fabpot added a commit that referenced this pull request Sep 14, 2016
…to a Type (Ener-Getick)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[PropertyInfo] Extract the logic converting a php doc to a Type

| Q             | A
| ------------- | ---
| Branch?       | "master"
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This PR creates a new trait `PhpDocTypeHelperTrait` extracting some logic of the `PhpDocExtractor`.
I would like to detect the return type of some methods but this is not easily doable as I have to transform the doc types to a ``Type`` instance.

Is this ok for you ?

Commits
-------

d6e93d8 [PropertyInfo] Extract the logic converting a php doc to a Type in PhpDocTypeHelperTrait
@GuilhemN GuilhemN deleted the PHPINFOTYPES branch September 15, 2016 15:27
@fabpot fabpot mentioned this pull request Oct 27, 2016
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.

5 participants