Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"require-dev": {
"doctrine/coding-standard": "^12.0",
"phpunit/phpunit": "^10.5.35",
"rector/rector": "^1.2",
"rector/rector": "^2.1.4",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "6.5.*"
},
Expand Down
49 changes: 27 additions & 22 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,47 @@
<?php

use PhpParser\Node\Expr\Cast\Bool_;
use PhpParser\Node\Expr\Cast\Double;
use PhpParser\Node\Expr\Cast\Int_;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Renaming\Rector\Cast\RenameCastRector;
use Rector\Renaming\ValueObject\RenameCast;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/examples',
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/tools',
]);

// Modernize code
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
PHPUnitSetList::PHPUNIT_100,
]);

$rectorConfig->rule(ChangeSwitchToMatchRector::class);
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);

])
->withPhpSets(php74: true)
->withComposerBased(phpunit: true)
->withRules([
ChangeSwitchToMatchRector::class,
])
// All classes are public API by default, unless marked with @internal.
->withConfiguredRule(RemoveAnnotationRector::class, ['api'])
// Fix PHP 8.5 deprecations
->withConfiguredRule(
RenameCastRector::class,
[
new RenameCast(Int_::class, Int_::KIND_INTEGER, Int_::KIND_INT),
new RenameCast(Bool_::class, Bool_::KIND_BOOLEAN, Bool_::KIND_BOOL),
new RenameCast(Double::class, Double::KIND_DOUBLE, Double::KIND_FLOAT),
],
)
// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
$rectorConfig->skip([
->withSkip([
RemoveExtraParametersRector::class,
// Do not use ternaries extensively
IfIssetToCoalescingRector::class,
ChangeSwitchToMatchRector::class => [
__DIR__ . '/tests/SpecTests/Operation.php',
],
]);
])
// phpcs:enable

// All classes are public API by default, unless marked with @internal.
$rectorConfig->ruleWithConfiguration(RemoveAnnotationRector::class, ['api']);
};
->withImportNames(importNames: false, removeUnusedImports: true);
1 change: 0 additions & 1 deletion src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use MongoDB\GridFS\Exception\StreamException;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
use MongoDB\Operation\Find;

use function array_intersect_key;
use function array_key_exists;
Expand Down
4 changes: 2 additions & 2 deletions src/GridFS/ReadableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function __construct(private CollectionWrapper $collectionWrapper, privat
$this->length = $file->length;

if ($this->length > 0) {
$this->numChunks = (integer) ceil($this->length / $this->chunkSize);
$this->numChunks = (int) ceil($this->length / $this->chunkSize);
$this->expectedLastChunkSize = $this->length - (($this->numChunks - 1) * $this->chunkSize);
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public function seek(int $offset): void
* changed, we'll also need to reset the buffer.
*/
$lastChunkOffset = $this->chunkOffset;
$this->chunkOffset = (integer) floor($offset / $this->chunkSize);
$this->chunkOffset = (int) floor($offset / $this->chunkSize);
$this->bufferOffset = $offset % $this->chunkSize;

if ($lastChunkOffset === $this->chunkOffset) {
Expand Down
4 changes: 2 additions & 2 deletions src/Model/CollectionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __debugInfo(): array
public function getCappedMax(): ?int
{
/* The MongoDB server might return this number as an integer or float */
return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
return isset($this->info['options']['max']) ? (int) $this->info['options']['max'] : null;
}

/**
Expand All @@ -69,7 +69,7 @@ public function getCappedMax(): ?int
public function getCappedSize(): ?int
{
/* The MongoDB server might return this number as an integer or float */
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
return isset($this->info['options']['size']) ? (int) $this->info['options']['size'] : null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Model/DatabaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public function getName(): string
public function getSizeOnDisk(): int
{
/* The MongoDB server might return this number as an integer or float */
return (integer) $this->info['sizeOnDisk'];
return (int) $this->info['sizeOnDisk'];
}

/**
* Return whether the database is empty.
*/
public function isEmpty(): bool
{
return (boolean) $this->info['empty'];
return (bool) $this->info['empty'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Model/IndexInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getName(): string
*/
public function getVersion(): int
{
return (integer) $this->info['v'];
return (int) $this->info['v'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Count.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function execute(Server $server): int
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}

return (integer) $result->n;
return (int) $result->n;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/CountDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function execute(Server $server): int
throw new UnexpectedValueException('count command did not return a numeric "n" value');
}

return (integer) $result->n;
return (int) $result->n;
}

private function createAggregate(): Aggregate
Expand Down
4 changes: 2 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ function is_write_concern_acknowledged(WriteConcern $writeConcern): bool
function server_supports_feature(Server $server, int $feature): bool
{
$info = $server->getInfo();
$maxWireVersion = isset($info['maxWireVersion']) ? (integer) $info['maxWireVersion'] : 0;
$minWireVersion = isset($info['minWireVersion']) ? (integer) $info['minWireVersion'] : 0;
$maxWireVersion = isset($info['maxWireVersion']) ? (int) $info['maxWireVersion'] : 0;
$minWireVersion = isset($info['minWireVersion']) ? (int) $info['minWireVersion'] : 0;

return $minWireVersion <= $feature && $maxWireVersion >= $feature;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
'x' => (int) ($i . $i),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/BulkWriteFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private function createFixtures(int $n): void
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
'x' => (int) ($i . $i),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/DeleteFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function createFixtures(int $n): void
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
'x' => (int) ($i . $i),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/ExplainFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ private function createFixtures(int $n): void
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
'x' => (int) ($i . $i),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/UpdateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private function createFixtures(int $n): void
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
'_id' => $i,
'x' => (integer) ($i . $i),
'x' => (int) ($i . $i),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private static function cast(string $type, int $value): mixed
{
return match ($type) {
'DecimalNoPrecision', 'DecimalPrecision' => new Decimal128((string) $value),
'DoubleNoPrecision', 'DoublePrecision' => (double) $value,
'DoubleNoPrecision', 'DoublePrecision' => (float) $value,
'Date' => new UTCDateTime($value),
'Int' => $value,
'Long' => new Int64($value),
Expand Down
2 changes: 1 addition & 1 deletion tools/connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

function getHosts(string $uri): array
{
if (strpos($uri, '://') === false) {
if (! str_contains($uri, '://')) {
return [$uri];
}

Expand Down
4 changes: 2 additions & 2 deletions tools/detect-extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ function grepIniFile(string $filename, string $extension): int
$lines = [];

foreach (new SplFileObject($filename) as $i => $line) {
if (strpos($line, 'extension') === false) {
if (! str_contains($line, 'extension')) {
continue;
}

if (strpos($line, $extension) === false) {
if (! str_contains($line, $extension)) {
continue;
}

Expand Down