Skip to content

Commit

Permalink
Merge pull request #2462 from malarzm/fix-failing-jobs
Browse files Browse the repository at this point in the history
Fix failing CI checks
  • Loading branch information
malarzm authored Sep 20, 2022
2 parents 89a5bfd + 36827e4 commit 8e048f8
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
5 changes: 4 additions & 1 deletion lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,15 @@ public function getReference(string $documentName, $identifier): object
/** @psalm-var ClassMetadata<T> $class */
$class = $this->metadataFactory->getMetadataFor(ltrim($documentName, '\\'));
assert($class instanceof ClassMetadata);
/** @psalm-var T|false $document */
$document = $this->unitOfWork->tryGetById($identifier, $class);

// Check identity map first, if its already in there just return it.
if ($document) {
if ($document !== false) {
return $document;
}

/** @psalm-var T&GhostObjectInterface<T> $document */
$document = $this->proxyFactory->getProxy($class, $identifier);
$this->unitOfWork->registerManaged($document, $identifier, []);

Expand Down Expand Up @@ -689,6 +691,7 @@ public function find($className, $id, $lockMode = LockMode::NONE, $lockVersion =
{
$repository = $this->getRepository($className);
if ($repository instanceof DocumentRepository) {
/** @psalm-var DocumentRepository<T> $repository */
return $repository->find($id, $lockMode, $lockVersion);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -2247,7 +2247,7 @@ public function mapField(array $mapping): array
break;
default:
if (! empty($this->generatorOptions['type'])) {
$mapping['type'] = $this->generatorOptions['type'];
$mapping['type'] = (string) $this->generatorOptions['type'];
} elseif (empty($mapping['type'])) {
$mapping['type'] = $this->generatorType === self::GENERATOR_TYPE_INCREMENT ? Type::INT : Type::CUSTOMID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

use function class_exists;

if (class_exists(PersistenceAnnotationDriver::class)) {
if (! class_exists(PersistenceAnnotationDriver::class)) {
/**
* @internal This class will be removed in ODM 3.0.
*/
abstract class CompatibilityAnnotationDriver extends PersistenceAnnotationDriver
abstract class CompatibilityAnnotationDriver implements MappingDriver
{
}
} else {
/**
* @internal This class will be removed in ODM 3.0.
*/
abstract class CompatibilityAnnotationDriver implements MappingDriver
abstract class CompatibilityAnnotationDriver extends PersistenceAnnotationDriver
{
}
}
14 changes: 6 additions & 8 deletions lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ static function (): bool {
* @param DocumentPersister<TDocument> $documentPersister
*
* @psalm-return Closure(
* TDocument&GhostObjectInterface<TDocument>,
* string,
* array<string, mixed>,
* TDocument&GhostObjectInterface<TDocument>=,
* string=,
* array<string, mixed>=,
* ?Closure=,
* array<string, mixed>
* array<string, mixed>=
* ) : bool
*
* @template TDocument of object
Expand All @@ -103,10 +103,8 @@ private function createInitializer(
): Closure {
return function (
GhostObjectInterface $ghostObject,
string $method,
// we don't care
array $parameters,
// we don't care
string $method, // we don't care
array $parameters, // we don't care
&$initializer,
array $properties // we currently do not use this
) use (
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ public function getDocumentPersister(string $documentName): Persisters\DocumentP
$this->persisters[$documentName] = new Persisters\DocumentPersister($pb, $this->dm, $this, $this->hydratorFactory, $class);
}

/** @psalm-var Persisters\DocumentPersister<T> */
return $this->persisters[$documentName];
}

Expand Down
26 changes: 24 additions & 2 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ parameters:

# When iterating over SimpleXMLElement, we cannot know the key values
-
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\\<int\\|string, non\\-empty\\-array\\<int, string\\>\\|bool\\|string\\> given\\.$#"
count: 1
message: "#^Parameter \\#2 \\$mapping of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\Driver\\\\XmlDriver\\:\\:addFieldMapping\\(\\) expects array#"
count: 2
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php

# This is handled by a try-catch block
Expand All @@ -163,6 +163,17 @@ parameters:
count: 1
path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php

# complains about types for arguments we do not use/care
-
message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\Proxy\\\\Factory\\\\StaticProxyFactory\\:\\:createInitializer\\(\\) should return Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface\\<TDocument of object\\>&TDocument of object\\=, string\\=, array\\<string, mixed\\>\\=, Closure\\|null\\=, array\\<string, mixed\\>\\=\\)\\: bool but returns Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface, string, array, mixed, array\\)\\: true\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php

-
message: "#^Parameter \\#1 \\$initializer of method ProxyManager\\\\Proxy\\\\GhostObjectInterface\\<object\\>\\:\\:setProxyInitializer\\(\\) expects \\(Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface\\<object\\>\\=, string\\=, array\\<string, mixed\\>\\=, Closure\\|null\\=, array\\<string, mixed\\>\\=\\)\\: bool\\)\\|null, Closure\\(ProxyManager\\\\Proxy\\\\GhostObjectInterface, string, array, mixed, array\\)\\: true given\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php

# compatibility layer for doctrine/persistence ^2.4 || ^3.0
-
message: "#.*#"
Expand Down Expand Up @@ -220,3 +231,14 @@ parameters:
message: "#.+mapField\\(\\) expects.+enumType\\: 'Documents81#"
count: 2
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

# it loads an empty class ReflectionEnum of ReflectionEnumPolyfill.php file from laminas/laminas-code, see https://github.com/phpstan/phpstan/issues/7290
-
message: "#^Call to an undefined method ReflectionEnum\\:\\:isBacked\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php

-
message: "#^Call to an undefined method ReflectionEnum\\:\\:getBackingType\\(\\)\\.$#"
count: 1
path: lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ private function getRepository(string $className = File::class): GridFSRepositor

assert($repository instanceof GridFSRepository);

/** @psalm-var GridFSRepository<T> */
return $repository;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Documents81/Suit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

enum Suit: string
{
case Hearts = 'H';
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
case Clubs = 'C';
case Spades = 'S';
}
6 changes: 3 additions & 3 deletions tests/Documents81/SuitInt.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

enum SuitInt: int
{
case Hearts = 1;
case Hearts = 1;
case Diamonds = 2;
case Clubs = 3;
case Spades = 4;
case Clubs = 3;
case Spades = 4;
}

0 comments on commit 8e048f8

Please sign in to comment.