-
Couldn't load subscription status.
- Fork 266
PHPLIB-1141: Setup rector #1088
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
Conversation
8789703 to
8d5f04c
Compare
7905ad1 to
7da6c97
Compare
|
|
||
| for ($i = 0; $i < 100; $i++) { | ||
| $documents[] = ['randomValue' => rand(0, 1000)]; | ||
| $documents[] = ['randomValue' => random_int(0, 1000)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit overzealous, as we don't actually need a cryptographically secure number here. But it's also just an example file so I don't feel strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the new "best practice". Using it proves that the doc have been updated 😉
| } | ||
|
|
||
| stream_wrapper_register($protocol, static::class, STREAM_IS_URL); | ||
| stream_wrapper_register($protocol, self::class, STREAM_IS_URL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static is useless for a final class. self can be resolved at compile time.
| return 'matches ' . $this->exporter()->export($this->value); | ||
| } | ||
|
|
||
| /** @psalm-return never-return */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helps to detect code paths and avoid false-positive undefined variable access.
Are those two examples due to the tooling not realizing that |
|
|
||
| for ($i = 0; $i < 100; $i++) { | ||
| $documents[] = ['randomValue' => rand(0, 1000)]; | ||
| $documents[] = ['randomValue' => random_int(0, 1000)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a bit overzealous, as we don't actually need a cryptographically secure number here. But it's also just an example file so I don't feel strongly about it.
| AddDefaultValueForUndefinedVariableRector::class => [ | ||
| __DIR__ . '/tests/', | ||
| ], | ||
| // @see https://github.com/phpstan/phpstan-src/pull/2429 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would See: make more sense here since we're not in an actual doc block?
| $this->fail('Exception for missing resume token was not thrown'); | ||
| } catch (ResumeTokenException $e) { | ||
| } catch (ServerException $e) { | ||
| } catch (ResumeTokenException | ServerException $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that this was available since 7.1 (long before general union types in 8.0): https://wiki.php.net/rfc/multiple-catch
| run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=$(nproc)" | ||
|
|
||
| - name: "Run Rector" | ||
| run: "vendor/bin/rector --ansi --dry-run" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted that --dry-run returns a non-zero exit code if changes are detected, which makes it suitable for CI.
PHPUnit 9.6 had the annotation People seems to have the opposite behavior: phpstan/phpstan-phpunit#52 |
Fix PHPLIB-1141
The library uses rector to refactor the code for new features.
To run automatic refactoring, use the
rectorcommand:Job merged with psalm: https://github.com/mongodb/mongo-php-library/actions/runs/5134018025/jobs/9237409213?pr=1088
The rules need to be adjusted due to false positive like this: