Skip to content

Updated the generator phpdoc to help identifier magic methods#307

Merged
pimjansen merged 1 commit intoFakerPHP:mainfrom
pimjansen:feature/updated-refs-generator
Apr 8, 2021
Merged

Updated the generator phpdoc to help identifier magic methods#307
pimjansen merged 1 commit intoFakerPHP:mainfrom
pimjansen:feature/updated-refs-generator

Conversation

@pimjansen
Copy link
Copy Markdown

@pimjansen pimjansen commented Apr 7, 2021

What is the reason for this PR?

As mentioned in #303 there are some problems with static code analysis for our deprecation warnings in 1.14. With this PR i did some reflection and generated a new PHPDoc to match the actual code itself

  • A new feature
  • Fixed an issue (resolve #ID)

Author's checklist

Review checklist

  • All checks have passed
  • Changes are approved by maintainer

@pimjansen
Copy link
Copy Markdown
Author

For the ones that get worse, this is due the fact that no return type has been specified on the methods itself. Do we want to drag this into scope or not? If yes then we need to modify those blocks as well

@pimjansen
Copy link
Copy Markdown
Author

@localheinz can you assist in the weird phpstan error? Can't resolve it somehow. Also when running it locally im getting phpstan errors.

Note: Using configuration file /home/pim/Projects/Faker/phpstan.neon.dist.
 478/478 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 -- -------------------------------------------------------------------------------------------------------------------- 
     Error                                                                                                               
 -- -------------------------------------------------------------------------------------------------------------------- 
     Reached internal errors count limit of 50, exiting...                                                               
     Internal error: Internal error: preg_replace(): Argument #3 ($subject) must be of type array|string, null given in  
     file /home/pim/Projects/Faker/src/Faker/Provider/hr_HR/Address.php     

Could be the fact that its running php 8 locally though.

Copy link
Copy Markdown
Member

@bram-pkg bram-pkg left a comment

Choose a reason for hiding this comment

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

Ignored error pattern #^Return typehint of method Faker\\Provider\\me_ME\\Address\:\:localCoordinates\(\) has invalid type Faker\\Provider\\latitude\.$# in path /home/runner/work/Faker/Faker/src/Faker/Provider/me_ME/Address.php was not matched in reported errors.

Maybe that error should be fixed

* @example array('77.147489', '86.211205')
*
* @return array | latitude, longitude
* @return float[]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @return float[]
* @return array{0: float, 1: float}

Comment thread src/Faker/Provider/DateTime.php Outdated
Comment on lines +356 to +357
*
* @return void;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
*
* @return void;

@localheinz
Copy link
Copy Markdown
Member

@pimjansen

Can you verify whether you have Xdebug enabled? Disabling it should fix the error.

As @bramceulemans suggested, you should be able to regenerate the baseline afterwards!

@localheinz
Copy link
Copy Markdown
Member

@pimjansen

What do you think about running the script that updates the DocBlock in GitHub Actions?

This way we could ensure that

  • the script works
  • the script is run when changes were made

@pimjansen
Copy link
Copy Markdown
Author

@pimjansen

What do you think about running the script that updates the DocBlock in GitHub Actions?

This way we could ensure that

  • the script works

  • the script is run when changes were made

Could do but maybe its a bit too much magic and it reduces the actual understanding what everything does imo.

Concerning the issue, the error is a bit odd since the method actually is no phpdoc defined that gives the error. But let me run without xdebug

@pimjansen
Copy link
Copy Markdown
Author

@localheinz seems that PHPstan version is not running fine on PHP8. Lets modify that in the future. I will downgrade locally to 7.4 instead where it runs fine

@pimjansen pimjansen merged commit 91a6806 into FakerPHP:main Apr 8, 2021
@lefuturiste
Copy link
Copy Markdown

Do you known when this will be released ?

@pimjansen
Copy link
Copy Markdown
Author

Unknown yet. Since its not a bug we are not pushing an extra release for this

@Pixelshaped
Copy link
Copy Markdown

It's still pretty inconvenient. Please consider it, unless you're close to your next release. Also you should probably not close issues like #303 until this is merged into main: it gives the false impression the issue is fixed while it isn't. You can use closing keywords in your PR description like "Fix #303" for it to automatically happen upon merge.

@pimjansen pimjansen deleted the feature/updated-refs-generator branch May 6, 2021 15:10
@stof
Copy link
Copy Markdown

stof commented Jul 2, 2021

@pimjansen any chance to tag a release including that fix ? It's been more than 2 months since the fix was done now.
Without this fix, we must choose between running static analysis and migrating away from the deprecated properties, but we cannot have a nice state.

@pimjansen
Copy link
Copy Markdown
Author

@pimjansen any chance to tag a release including that fix ? It's been more than 2 months since the fix was done now.
Without this fix, we must choose between running static analysis and migrating away from the deprecated properties, but we cannot have a nice state.

#342

@stof
Copy link
Copy Markdown

stof commented Jul 8, 2021

There's one thing that got worse in this update: unique() and optional() have been updated to document their return type as UniqueGenerator and DefaultGenerator. But those 2 classes don't have the magic methods documented on them.
Previously, the magic methods were documented as returning Generator

@shalvah
Copy link
Copy Markdown

shalvah commented Jul 12, 2021

Hey, something else is broken here. Was using the shuffle() method to shuffle a string. Worked fine in v14, but v15 gives an error with PHPStan, because the return type was changed from array|string to array, which is incorrect. I'm guessing it was a mistake?

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.

7 participants