Skip to content
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

support @param number #294

Closed
mathroc opened this issue Jul 19, 2016 · 2 comments
Closed

support @param number #294

mathroc opened this issue Jul 19, 2016 · 2 comments
Labels
enhancement This improves the quality of Phan's analysis of a codebase

Comments

@mathroc
Copy link
Contributor

mathroc commented Jul 19, 2016

PhanTypeMismatchArgument Argument 1 (value) is float|int but \NumberFormatter::format() takes \Symfony\Component\Intl\NumberFormatter\number defined at /scripts/vendor/symfony/intl/NumberFormatter/NumberFormatter.php:371

/** @param number */ is some times used to describe int|float, eg:
https://github.com/symfony/intl/blob/master/NumberFormatter/NumberFormatter.php#L360
it's also used in the documentation : http://php.net/manual/en/numberformatter.format.php and I think I read discussion in php internals about adding it to PHP so it might be a good idea to support it as an alias to int|float

@morria morria added the enhancement This improves the quality of Phan's analysis of a codebase label Jul 19, 2016
@TysonAndre
Copy link
Member

TysonAndre commented Nov 18, 2016

https://github.com/TysonAndre/phan/pull/4/files is one way of doing this (handle immediately after parsing doc comment)
(Not in etsy/phan, but could be redone as a PR against etsy/phan if this is useful to have. Emitting a issue if a key of 'experimental_invalid_phpdoc_types' exists as a class/builtin would be a TODO)
number isn't a reserved name in php yet.

(It's mostly meant for old invalid phpdoc, so it doesn't bother to expand number|null or number[] (to int[]|float[]). It would replace those vars, params, and return types which are exactly "number" with int|float.

'experimental_invalid_phpdoc_types' => ['number' => 'int|float'],

TysonAndre added a commit to TysonAndre/phan that referenced this issue Sep 18, 2017
E.g. if a codebase frequently uses `@param number $x`, then the
maintainers may wish to add the following line to .phan/config.php

`'phpdoc_type_mapping' => ['number' => 'int|float'],`

Add test case to the rewriting_test folder.
TysonAndre added a commit to TysonAndre/phan that referenced this issue Sep 18, 2017
E.g. if a codebase frequently uses `@param number $x`, then the
maintainers may wish to add the following line to .phan/config.php

`'phpdoc_type_mapping' => ['number' => 'int|float'],`

Add test case to the rewriting_test folder.
TysonAndre added a commit to TysonAndre/phan that referenced this issue Sep 18, 2017
E.g. if a codebase frequently uses `@param number $x`, then the
maintainers may wish to add the following line to .phan/config.php

`'phpdoc_type_mapping' => ['number' => 'int|float'],`

Add test case to the rewriting_test folder.
TysonAndre added a commit that referenced this issue Sep 18, 2017
Workaround for #294 : Add 'phpdoc_type_mapping' setting
@TysonAndre
Copy link
Member

See PR #1112, the phpdoc_type_mapping setting will be in the next Phan release. This may be expanded to individual parts of phpdoc types (including the inside of nullable types), but currently acts on the string as a whole.

In order to avoid unintuitive issues similar to #781 , I'd rather be conservative about adding types that aren't in phpdoc2 or other standards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This improves the quality of Phan's analysis of a codebase
Projects
None yet
Development

No branches or pull requests

3 participants