Skip to content

Commit 34e07d0

Browse files
committed
chore: fix PHP 8.5 deprecations.
1 parent 0ea2300 commit 34e07d0

15 files changed

+32
-18
lines changed

rector.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<?php
22

3+
use PhpParser\Node\Expr\Cast\Bool_;
4+
use PhpParser\Node\Expr\Cast\Double;
5+
use PhpParser\Node\Expr\Cast\Int_;
36
use Rector\Config\RectorConfig;
47
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
58
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
69
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
710
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
11+
use Rector\Renaming\Rector\Cast\RenameCastRector;
12+
use Rector\Renaming\ValueObject\RenameCast;
813

914
return RectorConfig::configure()
1015
->withPaths([
@@ -20,6 +25,15 @@
2025
])
2126
// All classes are public API by default, unless marked with @internal.
2227
->withConfiguredRule(RemoveAnnotationRector::class, ['api'])
28+
// Fix PHP 8.5 deprecations
29+
->withConfiguredRule(
30+
RenameCastRector::class,
31+
[
32+
new RenameCast(Int_::class, Int_::KIND_INTEGER, Int_::KIND_INT),
33+
new RenameCast(Bool_::class, Bool_::KIND_BOOLEAN, Bool_::KIND_BOOL),
34+
new RenameCast(Double::class, Double::KIND_DOUBLE, Double::KIND_FLOAT),
35+
],
36+
)
2337
// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
2438
->withSkip([
2539
RemoveExtraParametersRector::class,

src/GridFS/ReadableStream.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct(private CollectionWrapper $collectionWrapper, privat
8282
$this->length = $file->length;
8383

8484
if ($this->length > 0) {
85-
$this->numChunks = (integer) ceil($this->length / $this->chunkSize);
85+
$this->numChunks = (int) ceil($this->length / $this->chunkSize);
8686
$this->expectedLastChunkSize = $this->length - (($this->numChunks - 1) * $this->chunkSize);
8787
}
8888
}
@@ -184,7 +184,7 @@ public function seek(int $offset): void
184184
* changed, we'll also need to reset the buffer.
185185
*/
186186
$lastChunkOffset = $this->chunkOffset;
187-
$this->chunkOffset = (integer) floor($offset / $this->chunkSize);
187+
$this->chunkOffset = (int) floor($offset / $this->chunkSize);
188188
$this->bufferOffset = $offset % $this->chunkSize;
189189

190190
if ($lastChunkOffset === $this->chunkOffset) {

src/MapReduceResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function getTiming()
104104
public function __construct(callable $getIterator, stdClass $result)
105105
{
106106
$this->getIterator = $getIterator;
107-
$this->executionTimeMS = isset($result->timeMillis) ? (integer) $result->timeMillis : 0;
107+
$this->executionTimeMS = isset($result->timeMillis) ? (int) $result->timeMillis : 0;
108108
$this->counts = isset($result->counts) ? (array) $result->counts : [];
109109
$this->timing = isset($result->timing) ? (array) $result->timing : [];
110110
}

src/Model/CollectionInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __debugInfo()
6262
public function getCappedMax()
6363
{
6464
/* The MongoDB server might return this number as an integer or float */
65-
return isset($this->info['options']['max']) ? (integer) $this->info['options']['max'] : null;
65+
return isset($this->info['options']['max']) ? (int) $this->info['options']['max'] : null;
6666
}
6767

6868
/**
@@ -75,7 +75,7 @@ public function getCappedMax()
7575
public function getCappedSize()
7676
{
7777
/* The MongoDB server might return this number as an integer or float */
78-
return isset($this->info['options']['size']) ? (integer) $this->info['options']['size'] : null;
78+
return isset($this->info['options']['size']) ? (int) $this->info['options']['size'] : null;
7979
}
8080

8181
/**

src/Model/DatabaseInfo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getName()
6969
public function getSizeOnDisk()
7070
{
7171
/* The MongoDB server might return this number as an integer or float */
72-
return (integer) $this->info['sizeOnDisk'];
72+
return (int) $this->info['sizeOnDisk'];
7373
}
7474

7575
/**
@@ -79,7 +79,7 @@ public function getSizeOnDisk()
7979
*/
8080
public function isEmpty()
8181
{
82-
return (boolean) $this->info['empty'];
82+
return (bool) $this->info['empty'];
8383
}
8484

8585
/**

src/Model/IndexInfo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getNamespace()
111111
*/
112112
public function getVersion()
113113
{
114-
return (integer) $this->info['v'];
114+
return (int) $this->info['v'];
115115
}
116116

117117
/**

src/Operation/Count.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function execute(Server $server)
147147
throw new UnexpectedValueException('count command did not return a numeric "n" value');
148148
}
149149

150-
return (integer) $result->n;
150+
return (int) $result->n;
151151
}
152152

153153
/**

src/Operation/CountDocuments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function execute(Server $server)
128128
throw new UnexpectedValueException('count command did not return a numeric "n" value');
129129
}
130130

131-
return (integer) $result->n;
131+
return (int) $result->n;
132132
}
133133

134134
private function createAggregate(): Aggregate

src/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ function is_write_concern_acknowledged(WriteConcern $writeConcern): bool
430430
function server_supports_feature(Server $server, int $feature): bool
431431
{
432432
$info = $server->getInfo();
433-
$maxWireVersion = isset($info['maxWireVersion']) ? (integer) $info['maxWireVersion'] : 0;
434-
$minWireVersion = isset($info['minWireVersion']) ? (integer) $info['minWireVersion'] : 0;
433+
$maxWireVersion = isset($info['maxWireVersion']) ? (int) $info['maxWireVersion'] : 0;
434+
$minWireVersion = isset($info['minWireVersion']) ? (int) $info['minWireVersion'] : 0;
435435

436436
return $minWireVersion <= $feature && $maxWireVersion >= $feature;
437437
}

tests/Collection/CollectionFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
852852
for ($i = 1; $i <= $n; $i++) {
853853
$bulkWrite->insert([
854854
'_id' => $i,
855-
'x' => (integer) ($i . $i),
855+
'x' => (int) $i . $i,
856856
]);
857857
}
858858

0 commit comments

Comments
 (0)