Skip to content

Commit 9622613

Browse files
authored
Psalm level 4 (#2409)
1 parent 9d22a8f commit 9622613

File tree

16 files changed

+116
-42
lines changed

16 files changed

+116
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,7 +1082,7 @@ public function setDiscriminatorValue(string $value): void
10821082
/**
10831083
* Add a index for this Document.
10841084
*
1085-
* @param array<string, mixed> $keys
1085+
* @param array<string, int|string> $keys
10861086
* @psalm-param IndexKeys $keys
10871087
* @psalm-param IndexOptions $options
10881088
*/

lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
251251
}
252252

253253
foreach ($reflClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
254-
assert($method instanceof ReflectionMethod);
255254
/* Filter for the declaring class only. Callbacks from parent
256255
* classes will already be registered.
257256
*/
@@ -292,8 +291,8 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
292291
}
293292

294293
/**
295-
* @param ClassMetadata<object> $class
296-
* @param string[] $keys
294+
* @param ClassMetadata<object> $class
295+
* @param array<string, int|string> $keys
297296
*/
298297
private function addIndex(ClassMetadata $class, AbstractIndex $index, array $keys = []): void
299298
{

lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeReader.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use ReflectionProperty;
1313

1414
use function assert;
15-
use function is_string;
1615
use function is_subclass_of;
1716

1817
/**
@@ -100,7 +99,6 @@ private function convertToAttributeInstances(array $attributes): array
10099

101100
foreach ($attributes as $attribute) {
102101
$attributeName = $attribute->getName();
103-
assert(is_string($attributeName));
104102
// Make sure we only get Doctrine Annotations
105103
if (! is_subclass_of($attributeName, Annotation::class)) {
106104
continue;

lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
/**
4343
* XmlDriver is a metadata driver that enables mapping through XML files.
4444
*
45-
* @method SimpleXMLElement getElement(string $className)
4645
* @psalm-import-type FieldMappingConfig from ClassMetadata
4746
*/
4847
class XmlDriver extends FileDriver
@@ -81,6 +80,7 @@ public function loadMetadataForClass($className, \Doctrine\Persistence\Mapping\C
8180
{
8281
assert($metadata instanceof ClassMetadata);
8382
$xmlRoot = $this->getElement($className);
83+
assert($xmlRoot instanceof SimpleXMLElement);
8484

8585
if ($xmlRoot->getName() === 'document') {
8686
if (isset($xmlRoot['repository-class'])) {

lib/Doctrine/ODM/MongoDB/PersistentCollection/DefaultPersistentCollectionGenerator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ private function buildParametersString(ReflectionMethod $method): string
226226
$parameterDefinitions = [];
227227

228228
foreach ($parameters as $param) {
229-
assert($param instanceof ReflectionParameter);
230229
$parameterDefinition = '';
231230
if ($param->hasType()) {
232231
$parameterDefinition .= $this->getParameterType($param) . ' ';

lib/Doctrine/ODM/MongoDB/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ public function getQuery(array $options = []): Query
698698
$includeMode = 0 < count(array_filter($query['select'], static function ($mode) {
699699
return $mode === 1;
700700
}));
701-
if ($includeMode && ! isset($query['select'][$this->class->discriminatorField])) {
701+
if ($includeMode) {
702702
$query['select'][$this->class->discriminatorField] = 1;
703703
}
704704
}

lib/Doctrine/ODM/MongoDB/Types/Type.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
use InvalidArgumentException;
1111
use MongoDB\BSON\ObjectId;
1212

13-
use function assert;
1413
use function end;
1514
use function explode;
1615
use function gettype;
1716
use function is_object;
18-
use function is_string;
1917
use function sprintf;
2018
use function str_replace;
2119

@@ -263,7 +261,6 @@ public function __toString()
263261
{
264262
$e = explode('\\', static::class);
265263
$className = end($e);
266-
assert(is_string($className));
267264

268265
return str_replace('Type', '', $className);
269266
}

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ parameters:
4343
count: 1
4444
path: tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/FacetTest.php
4545

46-
-
47-
message: "#^Class Documents\\\\Account does not have a constructor and must be instantiated without any parameters\\.$#"
48-
count: 4
49-
path: tests/Doctrine/ODM/MongoDB/Tests/DocumentRepositoryTest.php
50-
5146
-
5247
message: "#^Cannot access property \\$username on array\\|object\\.$#"
5348
count: 1

psalm-baseline.xml

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,49 @@
88
<code>self</code>
99
</InvalidReturnType>
1010
</file>
11+
<file src="lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php">
12+
<ImplementedReturnTypeMismatch occurrences="1">
13+
<code>TValue|false</code>
14+
</ImplementedReturnTypeMismatch>
15+
</file>
16+
<file src="lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php">
17+
<ImplementedReturnTypeMismatch occurrences="1">
18+
<code>TDocument|null</code>
19+
</ImplementedReturnTypeMismatch>
20+
</file>
1121
<file src="lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php">
22+
<ImplementedReturnTypeMismatch occurrences="1">
23+
<code>array&lt;string|null&gt;</code>
24+
</ImplementedReturnTypeMismatch>
1225
<InvalidArrayOffset occurrences="1">
1326
<code>[$this-&gt;identifier =&gt; $this-&gt;getIdentifierValue($object)]</code>
1427
</InvalidArrayOffset>
1528
</file>
1629
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php">
17-
<InvalidArgument occurrences="1">
30+
<InvalidArgument occurrences="2">
31+
<code>$mapping</code>
1832
<code>$mapping</code>
1933
</InvalidArgument>
34+
<RedundantCondition occurrences="15">
35+
<code>assert($attributes instanceof SimpleXMLElement)</code>
36+
<code>isset($xmlRoot-&gt;field)</code>
37+
<code>isset($xmlRoot-&gt;id)</code>
38+
<code>isset($xmlRoot-&gt;{'default-discriminator-value'})</code>
39+
<code>isset($xmlRoot-&gt;{'discriminator-field'})</code>
40+
<code>isset($xmlRoot-&gt;{'discriminator-map'})</code>
41+
<code>isset($xmlRoot-&gt;{'embed-many'})</code>
42+
<code>isset($xmlRoot-&gt;{'embed-one'})</code>
43+
<code>isset($xmlRoot-&gt;{'indexes'})</code>
44+
<code>isset($xmlRoot-&gt;{'lifecycle-callbacks'})</code>
45+
<code>isset($xmlRoot-&gt;{'read-preference'})</code>
46+
<code>isset($xmlRoot-&gt;{'reference-many'})</code>
47+
<code>isset($xmlRoot-&gt;{'reference-one'})</code>
48+
<code>isset($xmlRoot-&gt;{'schema-validation'})</code>
49+
<code>isset($xmlRoot-&gt;{'shard-key'})</code>
50+
</RedundantCondition>
51+
<TypeDoesNotContainType occurrences="1">
52+
<code>isset($xmlRoot-&gt;{'also-load-methods'})</code>
53+
</TypeDoesNotContainType>
2054
</file>
2155
<file src="lib/Doctrine/ODM/MongoDB/PersistentCollection/AbstractPersistentCollectionFactory.php">
2256
<InvalidArgument occurrences="1">
@@ -38,6 +72,11 @@
3872
<code>getTypeClass</code>
3973
</InvalidReturnType>
4074
</file>
75+
<file src="lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php">
76+
<RedundantFunctionCall occurrences="1">
77+
<code>array_values</code>
78+
</RedundantFunctionCall>
79+
</file>
4180
<file src="lib/Doctrine/ODM/MongoDB/Proxy/Resolver/ProxyManagerClassNameResolver.php">
4281
<MoreSpecificImplementedParamType occurrences="1">
4382
<code>$className</code>
@@ -48,6 +87,11 @@
4887
<code>$options + ['metadata' =&gt; (object) $metadata]</code>
4988
</InvalidReturnStatement>
5089
</file>
90+
<file src="lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php">
91+
<RedundantCondition occurrences="1">
92+
<code>$datetime instanceof DateTime</code>
93+
</RedundantCondition>
94+
</file>
5195
<file src="lib/Doctrine/ODM/MongoDB/UnitOfWork.php">
5296
<InvalidPropertyAssignmentValue occurrences="2">
5397
<code>$this-&gt;identityMap</code>
@@ -77,6 +121,17 @@
77121
<code>$j</code>
78122
</InvalidArgument>
79123
</file>
124+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/NestedDocumentsTest.php">
125+
<InvalidScalarArgument occurrences="2">
126+
<code>$name</code>
127+
<code>$name</code>
128+
</InvalidScalarArgument>
129+
</file>
130+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH245Test.php">
131+
<RedundantCondition occurrences="1">
132+
<code>assertIsInt</code>
133+
</RedundantCondition>
134+
</file>
80135
<file src="tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php">
81136
<InvalidNullableReturnType occurrences="1">
82137
<code>DocumentManager</code>
@@ -85,4 +140,40 @@
85140
<code>$this-&gt;dm</code>
86141
</NullableReturnStatement>
87142
</file>
143+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php">
144+
<InvalidScalarArgument occurrences="1">
145+
<code>1</code>
146+
</InvalidScalarArgument>
147+
</file>
148+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Query/QueryExpressionVisitorTest.php">
149+
<TooManyArguments occurrences="1">
150+
<code>andX</code>
151+
</TooManyArguments>
152+
</file>
153+
<file src="tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php">
154+
<InternalClass occurrences="2">
155+
<code>new IndexInfoIteratorIterator(new ArrayIterator($indexes))</code>
156+
<code>new IndexInfoIteratorIterator(new ArrayIterator([]))</code>
157+
</InternalClass>
158+
<InternalMethod occurrences="2">
159+
<code>new IndexInfoIteratorIterator(new ArrayIterator($indexes))</code>
160+
<code>new IndexInfoIteratorIterator(new ArrayIterator([]))</code>
161+
</InternalMethod>
162+
</file>
163+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Types/DateImmutableTypeTest.php">
164+
<TypeDoesNotContainType occurrences="1">
165+
<code>assert($return instanceof DateTimeImmutable)</code>
166+
</TypeDoesNotContainType>
167+
</file>
168+
<file src="tests/Doctrine/ODM/MongoDB/Tests/Types/DateTypeTest.php">
169+
<TypeDoesNotContainType occurrences="1">
170+
<code>assert($return instanceof DateTime)</code>
171+
</TypeDoesNotContainType>
172+
</file>
173+
<file src="tests/Documents/CommentRepository.php">
174+
<InternalMethod occurrences="2">
175+
<code>loadAll</code>
176+
<code>loadAll</code>
177+
</InternalMethod>
178+
</file>
88179
</files>

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="5"
3+
errorLevel="4"
44
findUnusedPsalmSuppress="true"
55
resolveFromConfigFile="true"
66
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

0 commit comments

Comments
 (0)