Skip to content

Commit 37ac643

Browse files
authored
Merge pull request #2332 from franmomu/psalm_to_level_6_mix
Fix some psalm findings
2 parents 7cafcdc + b48ca21 commit 37ac643

File tree

13 files changed

+33
-37
lines changed

13 files changed

+33
-37
lines changed

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,9 @@ public function getReflectionProperty(string $name): ReflectionProperty
13091309
return $this->reflFields[$name];
13101310
}
13111311

1312+
/**
1313+
* @psalm-return class-string<T>
1314+
*/
13121315
public function getName(): string
13131316
{
13141317
return $this->name;

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ final class DocumentPersister
120120
/** @var HydratorFactory */
121121
private $hydratorFactory;
122122

123+
/**
124+
* @psalm-param ClassMetadata<T> $class
125+
*/
123126
public function __construct(
124127
PersistenceBuilder $pb,
125128
DocumentManager $dm,

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/CreateCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ protected function configure()
3939

4040
protected function execute(InputInterface $input, OutputInterface $output)
4141
{
42-
$create = array_filter($this->createOrder, static function ($option) use ($input) {
43-
return $input->getOption($option);
42+
$create = array_filter($this->createOrder, static function (string $option) use ($input): bool {
43+
return (bool) $input->getOption($option);
4444
});
4545

4646
// Default to the full creation order if no options were specified

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/Schema/DropCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected function configure()
3636

3737
protected function execute(InputInterface $input, OutputInterface $output)
3838
{
39-
$drop = array_filter($this->dropOrder, static function ($option) use ($input) {
40-
return $input->getOption($option);
39+
$drop = array_filter($this->dropOrder, static function (string $option) use ($input): bool {
40+
return (bool) $input->getOption($option);
4141
});
4242

4343
// Default to the full drop order if no options were specified

phpstan-baseline.neon

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ parameters:
114114
count: 2
115115
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/InheritanceTest.php
116116

117-
-
118-
message: "#^Access to an undefined property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\AbstractVersionBase\\:\\:\\$version\\.$#"
119-
count: 1
120-
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php
121-
122117
-
123118
message: "#^Cannot access property \\$blogPosts on array\\|object\\.$#"
124119
count: 2
@@ -149,16 +144,6 @@ parameters:
149144
count: 1
150145
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH267Test.php
151146

152-
-
153-
message: "#^Cannot assign offset '1' to Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\<int, mixed\\>\\.$#"
154-
count: 1
155-
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php
156-
157-
-
158-
message: "#^Cannot unset offset '1' on Doctrine\\\\Common\\\\Collections\\\\ArrayCollection\\<int, mixed\\>\\.$#"
159-
count: 1
160-
path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php
161-
162147
-
163148
message: "#^Cannot access property \\$ref on array\\|object\\.$#"
164149
count: 2
@@ -204,11 +189,6 @@ parameters:
204189
count: 1
205190
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php
206191

207-
-
208-
message: "#^Access to an undefined property Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Mapping\\\\ClassMetadataTest\\>\\:\\:\\$namespace\\.$#"
209-
count: 1
210-
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
211-
212192
-
213193
message: "#^Parameter \\#1 \\$primer of method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Builder\\:\\:prime\\(\\) expects bool\\|\\(callable\\(\\)\\: mixed\\), 1 given\\.$#"
214194
count: 1

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FacetTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public function testFacetThrowsExceptionWithoutFieldName()
6666
$facetStage->pipeline($this->getTestAggregationBuilder());
6767
}
6868

69+
/**
70+
* @psalm-suppress InvalidArgument on purpose to throw exception
71+
*/
6972
public function testFacetThrowsExceptionOnInvalidPipeline()
7073
{
7174
$facetStage = new Facet($this->getTestAggregationBuilder());

tests/Doctrine/ODM/MongoDB/Tests/Functional/LockTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ abstract class AbstractVersionBase
570570
/** @ODM\EmbedMany(targetDocument=Issue::class) */
571571
public $issues;
572572

573+
public $version;
574+
573575
public function __construct($title = null)
574576
{
575577
$this->issues = new ArrayCollection();

tests/Doctrine/ODM/MongoDB/Tests/Functional/MemoryUsageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ private function formatMemory($size)
6161
{
6262
$unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
6363

64-
return round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
64+
return round($size / pow(1024, ($i = (int) floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
6565
}
6666
}

tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ODM\MongoDB\Tests\Functional;
66

7+
use Doctrine\ODM\MongoDB\Iterator\Iterator;
78
use Doctrine\ODM\MongoDB\Tests\BaseTest;
89
use Documents\Article;
910
use Documents\CmsComment;
@@ -18,6 +19,7 @@
1819
use MongoDB\BSON\UTCDateTime;
1920

2021
use function array_values;
22+
use function assert;
2123
use function get_class;
2224
use function iterator_to_array;
2325
use function strtotime;
@@ -396,7 +398,11 @@ public function testNestedQueryReference()
396398
->field('indirectlyReferencedUsers.user.id')->equals(new ObjectId($referencedUser->getId()))
397399
->getQuery();
398400

399-
$referencedUsers = iterator_to_array($referencedUsersQuery->execute(), false);
401+
$referencedUsersIterator = $referencedUsersQuery->execute();
402+
403+
assert($referencedUsersIterator instanceof Iterator);
404+
405+
$referencedUsers = iterator_to_array($referencedUsersIterator, false);
400406

401407
$this->assertCount(1, $referencedUsers);
402408
$this->assertSame($user, $referencedUsers[0]);

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH453Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testEmbedMany()
146146
$this->assertBsonArray($doc->id, 'embedManyAddToSet');
147147

148148
// Check that the value is changed properly
149-
unset($colPush[1], $colSet[1], $colSetArray[1], $colAddToSet['1']);
149+
unset($colPush[1], $colSet[1], $colSetArray[1], $colAddToSet[1]);
150150
$doc = $this->dm->merge($doc);
151151
$doc->embedManyPush = $colPush;
152152
$doc->embedManySet = $colSet;

0 commit comments

Comments
 (0)