Skip to content

Commit

Permalink
Merge pull request #2593 from alcaeus/fix-phpstan
Browse files Browse the repository at this point in the history
Fix phpstan errors
  • Loading branch information
malarzm authored Dec 17, 2023
2 parents 2996c0a + d66e2bf commit a51bfc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
13 changes: 5 additions & 8 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
use function strtoupper;
use function trigger_deprecation;

use const PHP_VERSION_ID;

/**
* A <tt>ClassMetadata</tt> instance holds all the object-document mapping metadata
* of a document and it's references.
Expand Down Expand Up @@ -2616,17 +2614,16 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array
return $mapping;
}

if (PHP_VERSION_ID >= 80100 && ! $type->isBuiltin() && enum_exists($type->getName())) {
$mapping['enumType'] = $type->getName();

if (! $type->isBuiltin() && enum_exists($type->getName())) {
$reflection = new ReflectionEnum($type->getName());
$type = $reflection->getBackingType();

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

$type = $reflection->getBackingType();
assert($type instanceof ReflectionNamedType);
$mapping['enumType'] = $reflection->getName();
}

switch ($type->getName()) {
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,16 @@ parameters:
count: 1
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php

-
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, \\.\\.\\.\\}\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

-
message: "#^Parameter \\#2 \\$enumType of class Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty constructor expects class\\-string\\<BackedEnum\\>, class\\-string\\<UnitEnum\\> given\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

-
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\\.$#"
count: 1
Expand Down
3 changes: 2 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.17.0@c620f6e80d0abfca532b00bda366062aaedf6e5d">
<file src="lib/Doctrine/ODM/MongoDB/Aggregation/Aggregation.php">
<MissingTemplateParam>
<code>IteratorAggregate</code>
Expand Down Expand Up @@ -82,6 +82,7 @@
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php">
<InvalidArgument>
<code>$mapping</code>
<code>$options</code>
</InvalidArgument>
</file>
<file src="lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php">
Expand Down

0 comments on commit a51bfc0

Please sign in to comment.