Skip to content

Commit a51bfc0

Browse files
authored
Merge pull request #2593 from alcaeus/fix-phpstan
Fix phpstan errors
2 parents 2996c0a + d66e2bf commit a51bfc0

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
use function strtoupper;
5252
use function trigger_deprecation;
5353

54-
use const PHP_VERSION_ID;
55-
5654
/**
5755
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
5856
* of a document and it's references.
@@ -2616,17 +2614,16 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
26162614
return $mapping;
26172615
}
26182616

2619-
if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) {
2620-
$mapping['enumType'] = $type->getName();
2621-
2617+
if (! $type->isBuiltin() && enum_exists($type->getName())) {
26222618
$reflection = new ReflectionEnum($type->getName());
2623-
$type = $reflection->getBackingType();
26242619

2625-
if ($type === null) {
2626-
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $mapping['enumType']);
2620+
if (! $reflection->isBacked()) {
2621+
throw MappingException::nonBackedEnumMapped($this->name, $mapping['fieldName'], $reflection->getName());
26272622
}
26282623

2624+
$type = $reflection->getBackingType();
26292625
assert($type instanceof ReflectionNamedType);
2626+
$mapping['enumType'] = $reflection->getName();
26302627
}
26312628

26322629
switch ($type->getName()) {

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ parameters:
445445
count: 1
446446
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
447447

448+
-
449+
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\:\\:validateAndCompleteTypedFieldMapping\\(\\) should return array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\} but returns array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}\\.$#"
450+
count: 1
451+
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
452+
453+
-
454+
message: "#^Parameter \\#2 \\$enumType of class Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty constructor expects class\\-string\\<BackedEnum\\>, class\\-string\\<UnitEnum\\> given\\.$#"
455+
count: 1
456+
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
457+
448458
-
449459
message: "#^Parameter \\#2 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Driver\\\\XmlDriver\\:\\:addFieldMapping\\(\\) expects array\\{type\\?\\: string, fieldName\\?\\: string, name\\?\\: string, strategy\\?\\: string, association\\?\\: int, id\\?\\: bool, isOwningSide\\?\\: bool, collectionClass\\?\\: class\\-string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<int, string\\>\\|bool\\|string\\> given\\.$#"
450460
count: 1

psalm-baseline.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
2+
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
33
<file src="lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php">
44
<MissingTemplateParam>
55
<code>IteratorAggregate</code>
@@ -82,6 +82,7 @@
8282
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php">
8383
<InvalidArgument>
8484
<code>$mapping</code>
85+
<code>$options</code>
8586
</InvalidArgument>
8687
</file>
8788
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php">

0 commit comments

Comments
 (0)