Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 062a19c

Browse files
Fix PHP 8.5 deprecations of (integer), (long) and (boolean) casts (#1758)
* build(deps-dev): updated rector/rector to ^2.1.4 * chore: fix PHP 8.5 deprecations.
1 parent 0e80d17 commit 062a19c

19 files changed

+49
-45
lines changed

‎composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require-dev": {
1919
"doctrine/coding-standard": "^12.0",
2020
"phpunit/phpunit": "^10.5.35",
21-
"rector/rector": "^1.2",
21+
"rector/rector": "^2.1.4",
2222
"squizlabs/php_codesniffer": "^3.7",
2323
"vimeo/psalm": "6.5.*"
2424
},

‎rector.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
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;
8-
use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector;
9-
use Rector\PHPUnit\Set\PHPUnitSetList;
10-
use Rector\Set\ValueObject\LevelSetList;
11+
use Rector\Renaming\Rector\Cast\RenameCastRector;
12+
use Rector\Renaming\ValueObject\RenameCast;
1113

12-
return staticfunction (RectorConfig$rectorConfig): void {
13-
$rectorConfig->paths([
14+
return RectorConfig::configure()
15+
->withPaths([
1416
__DIR__ . '/examples',
1517
__DIR__ . '/src',
1618
__DIR__ . '/tests',
1719
__DIR__ . '/tools',
18-
]);
19-
20-
// Modernize code
21-
$rectorConfig->sets([
22-
LevelSetList::UP_TO_PHP_74,
23-
PHPUnitSetList::PHPUNIT_100,
24-
]);
25-
26-
$rectorConfig->rule(ChangeSwitchToMatchRector::class);
27-
$rectorConfig->rule(StaticDataProviderClassMethodRector::class);
28-
20+
])
21+
->withPhpSets(php74: true)
22+
->withComposerBased(phpunit: true)
23+
->withRules([
24+
ChangeSwitchToMatchRector::class,
25+
])
26+
// All classes are public API by default, unless marked with @internal.
27+
->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+
)
2937
// phpcs:disable Squiz.Arrays.ArrayDeclaration.KeySpecified
30-
$rectorConfig->skip([
38+
->withSkip([
3139
RemoveExtraParametersRector::class,
3240
// Do not use ternaries extensively
3341
IfIssetToCoalescingRector::class,
3442
ChangeSwitchToMatchRector::class => [
3543
__DIR__ . '/tests/SpecTests/Operation.php',
3644
],
37-
]);
45+
])
3846
// phpcs:enable
39-
40-
// All classes are public API by default, unless marked with @internal.
41-
$rectorConfig->ruleWithConfiguration(RemoveAnnotationRector::class, ['api']);
42-
};
47+
->withImportNames(importNames: false, removeUnusedImports: true);

‎src/GridFS/Bucket.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use MongoDB\GridFS\Exception\StreamException;
3636
use MongoDB\Model\BSONArray;
3737
use MongoDB\Model\BSONDocument;
38-
use MongoDB\Operation\Find;
3938

4039
use function array_intersect_key;
4140
use function array_key_exists;

‎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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /