-
Notifications
You must be signed in to change notification settings - Fork 265
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
Changes from all commits
5b9420b
0c29d03
d4905d7
2688276
219b648
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
use function MongoDB\BSON\fromPHP; | ||
use function MongoDB\BSON\toRelaxedExtendedJSON; | ||
use function printf; | ||
use function rand; | ||
use function random_int; | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
@@ -28,7 +28,7 @@ function toJSON(object $document): string | |
$documents = []; | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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 😉 |
||
} | ||
|
||
$collection->insertMany($documents); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
use Rector\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector; | ||
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; | ||
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->paths([ | ||
|
@@ -11,13 +14,20 @@ | |
__DIR__ . '/tools', | ||
]); | ||
|
||
/** | ||
* All classes are public API by default, unless marked with @internal. | ||
*/ | ||
$rectorConfig->ruleWithConfiguration(RemoveAnnotationRector::class, ['api']); | ||
// Modernize code | ||
$rectorConfig->sets([LevelSetList::UP_TO_PHP_72]); | ||
|
||
$rectorConfig->skip([ | ||
// Falsely detect unassigned variables in code paths stopped by PHPUnit\Framework\Assert::markTestSkipped() | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Would |
||
RemoveExtraParametersRector::class => [ | ||
__DIR__ . '/src/Operation/', | ||
], | ||
]); | ||
|
||
// define sets of rules | ||
// $rectorConfig->sets([ | ||
// LevelSetList::UP_TO_PHP_72 | ||
// ]); | ||
// All classes are public API by default, unless marked with @internal. | ||
$rectorConfig->ruleWithConfiguration(RemoveAnnotationRector::class, ['api']); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ public static function register($protocol = 'unusable'): void | |
stream_wrapper_unregister($protocol); | ||
} | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public function stream_close(): void | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1107,8 +1107,7 @@ public function testResumeTokenNotFoundDoesNotAdvanceKey(): void | |
try { | ||
$changeStream->next(); | ||
$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 commentThe 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 |
||
} | ||
|
||
$this->assertFalse($changeStream->valid()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,6 +368,7 @@ private function doToString() | |
return 'matches ' . $this->exporter()->export($this->value); | ||
} | ||
|
||
/** @psalm-return never-return */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helps to detect code paths and avoid false-positive undefined variable access. |
||
private static function failAt(string $message, string $keyPath): void | ||
{ | ||
$prefix = empty($keyPath) ? '' : sprintf('Field path "%s": ', $keyPath); | ||
|
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.