Skip to content

Commit f9081ff

Browse files
committed
Setup rector config
1 parent 7f0b902 commit f9081ff

10 files changed

+42
-12
lines changed

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ possible it can be added to the baseline using `set-baseline`:
151151
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
152152
```
153153

154+
## Automatic code refactoring
155+
156+
The library uses [rector](https://getrector.com/) to refactor the code for new features.
157+
To run automatic refactoring, use the `rector` command:
158+
159+
```
160+
$ vendor/bin/rector
161+
```
162+
163+
New rules can be added to the `rector.php` configuration file.
164+
154165
## Documentation
155166

156167
Documentation for the library lives in the `docs/` directory and is built with

composer.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
"symfony/polyfill-php80": "^1.27"
1919
},
2020
"require-dev": {
21-
"squizlabs/php_codesniffer": "^3.7",
2221
"doctrine/coding-standard": "^11.1",
22+
"rector/rector": "^0.16.0",
23+
"squizlabs/php_codesniffer": "^3.7",
2324
"symfony/phpunit-bridge": "^5.2",
2425
"vimeo/psalm": "^4.28"
2526
},
@@ -39,6 +40,7 @@
3940
"config": {
4041
"allow-plugins": {
4142
"dealerdirect/phpcodesniffer-composer-installer": true
42-
}
43+
},
44+
"sort-packages": true
4345
}
4446
}

examples/aggregate.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use function MongoDB\BSON\fromPHP;
1212
use function MongoDB\BSON\toRelaxedExtendedJSON;
1313
use function printf;
14-
use function rand;
14+
use function random_int;
1515

1616
require __DIR__ . '/../vendor/autoload.php';
1717

@@ -28,7 +28,7 @@ function toJSON(object $document): string
2828
$documents = [];
2929

3030
for ($i = 0; $i < 100; $i++) {
31-
$documents[] = ['randomValue' => rand(0, 1000)];
31+
$documents[] = ['randomValue' => random_int(0, 1000)];
3232
}
3333

3434
$collection->insertMany($documents);

rector.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Rector\Config\RectorConfig;
4+
use Rector\Set\ValueObject\LevelSetList;
5+
6+
return static function (RectorConfig $rectorConfig): void {
7+
$rectorConfig->paths([
8+
__DIR__ . '/examples',
9+
__DIR__ . '/src',
10+
__DIR__ . '/tests',
11+
__DIR__ . '/tools',
12+
]);
13+
14+
// define sets of rules
15+
$rectorConfig->sets([LevelSetList::UP_TO_PHP_72]);
16+
};

tests/FunctionsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function provideTypeMapValues()
210210
'Array field path converted to array' => [
211211
[
212212
'root' => 'object',
213-
'array' => 'MongoDB\Model\BSONArray',
213+
'array' => BSONArray::class,
214214
'fieldPaths' => [
215215
'field' => 'array',
216216
'field.$' => 'object',
@@ -219,22 +219,22 @@ public function provideTypeMapValues()
219219
],
220220
[
221221
'root' => 'object',
222-
'array' => 'MongoDB\Model\BSONArray',
222+
'array' => BSONArray::class,
223223
'fieldPaths' => ['nested' => 'array'],
224224
],
225225
'field.$',
226226
],
227227
'Array field path without root key' => [
228228
[
229229
'root' => 'object',
230-
'array' => 'MongoDB\Model\BSONArray',
230+
'array' => BSONArray::class,
231231
'fieldPaths' => [
232232
'field' => 'array',
233233
'field.$.nested' => 'array',
234234
],
235235
],
236236
[
237-
'array' => 'MongoDB\Model\BSONArray',
237+
'array' => BSONArray::class,
238238
'fieldPaths' => ['nested' => 'array'],
239239
],
240240
'field.$',

tests/GridFS/BucketFunctionalTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ public function testOpenDownloadStreamByNameShouldRequireFilenameAndRevisionToEx
549549
$this->bucket->uploadFromStream('filename', $this->createStream('bar'));
550550

551551
$this->expectException(FileNotFoundException::class);
552-
$this->bucket->openDownloadStream($filename, ['revision' => $revision]);
552+
$this->bucket->openDownloadStream($filename);
553553
}
554554

555555
public function testOpenUploadStream(): void

tests/GridFS/UnusableStream.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function register($protocol = 'unusable'): void
2020
stream_wrapper_unregister($protocol);
2121
}
2222

23-
stream_wrapper_register($protocol, static::class, STREAM_IS_URL);
23+
stream_wrapper_register($protocol, self::class, STREAM_IS_URL);
2424
}
2525

2626
public function stream_close(): void

tests/Operation/WatchFunctionalTest.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -1107,8 +1107,7 @@ public function testResumeTokenNotFoundDoesNotAdvanceKey(): void
11071107
try {
11081108
$changeStream->next();
11091109
$this->fail('Exception for missing resume token was not thrown');
1110-
} catch (ResumeTokenException $e) {
1111-
} catch (ServerException $e) {
1110+
} catch (ResumeTokenException | ServerException $e) {
11121111
}
11131112

11141113
$this->assertFalse($changeStream->valid());

tests/SpecTests/ClientSideEncryptionSpecTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,7 @@ private function createTestCollection(?stdClass $encryptedFields = null, ?stdCla
20172017

20182018
private function encryptCorpusValue(string $fieldName, stdClass $data, ClientEncryption $clientEncryption)
20192019
{
2020+
$encrypted = null;
20202021
$encryptionOptions = [
20212022
'algorithm' => $data->algo === 'rand' ? ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_RANDOM : ClientEncryption::AEAD_AES_256_CBC_HMAC_SHA_512_DETERMINISTIC,
20222023
];

tests/UnifiedSpecTests/Operation.php

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public function assert(bool $rethrowExceptions = false): void
172172

173173
private function execute()
174174
{
175+
$result = null;
175176
$this->context->setActiveClient(null);
176177

177178
if ($this->isTestRunnerOperation) {

0 commit comments

Comments
 (0)