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

Incorrect PHPDoc typings due @mixin \Money\Money changing types #120

Closed
ThaDaVos opened this issue May 6, 2022 · 1 comment · Fixed by #121
Closed

Incorrect PHPDoc typings due @mixin \Money\Money changing types #120

ThaDaVos opened this issue May 6, 2022 · 1 comment · Fixed by #121

Comments

@ThaDaVos
Copy link

ThaDaVos commented May 6, 2022

I noticed (don't know when this was done), but due the combination of @mixin \Money\Money at

/**
* @mixin \Money\Money
*/
and the convertResult at
return static::convertResult($result);
in the __call the typing of the methods is wrong.

For example:

use Money\Currency;
use Cknow\Money\Money;

$revenueA = new Money(123, new Currency('EUR'));
$revenueB = new Money(123, new Currency('EUR'));

$revenueTotal = $revenueA->add($revenueB);

$type = get_class($revenueTotal);

echo "The type of the calculation result is: $type";

This will return "The type of the calculation result is: Cknow\Money\Money" - while a good editor which supports @mixin will show that it should be a Money\Money - which in turn may lead to confused developers and wrongly using Money::convert to get the correct type for function arguments, resulting in runtime typing errors while one does not expect them.

For example:
image

@ThaDaVos
Copy link
Author

ThaDaVos commented May 6, 2022

Maybe a good solution would be to add the PHPDoc manually to the Money class - or discuss with Money\Money that it should return self|static instead of Money and extend their class directly instead of, sorry to say this, abusing the magic methods

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 a pull request may close this issue.

1 participant