Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.4.x up into 4.0.x #377

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Persistence/AbstractManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use InvalidArgumentException;
use ReflectionClass;

use function assert;
use function sprintf;

/**
Expand Down Expand Up @@ -36,9 +37,9 @@
private $proxyInterfaceName;

/**
* @param array<string, string> $connections

Check failure on line 40 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.3)

MismatchingDocblockReturnType

src/Persistence/AbstractManagerRegistry.php:40:16: MismatchingDocblockReturnType: Docblock has incorrect return type 'object', should be 'Doctrine\Persistence\ObjectManager' (see https://psalm.dev/142)
* @param array<string, string> $managers
* @psalm-param class-string $proxyInterfaceName

Check failure on line 42 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

PHPDoc tag @return with type object is not subtype of native type Doctrine\Persistence\ObjectManager.
*/
public function __construct(
string $name,
Expand All @@ -55,7 +56,7 @@
$this->defaultManager = $defaultManager;
$this->proxyInterfaceName = $proxyInterfaceName;
}

Check failure on line 59 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.3)

MoreSpecificReturnType

src/Persistence/AbstractManagerRegistry.php:59:62: MoreSpecificReturnType: The declared return type 'Doctrine\Persistence\ObjectManager' for Doctrine\Persistence\AbstractManagerRegistry::getConnection is more specific than the inferred return type 'object' (see https://psalm.dev/070)
/**
* Fetches/creates the given services.
*
Expand All @@ -63,11 +64,11 @@
*
* @param string $name The name of the service.
*
* @return ObjectManager The instance of the given service.
* @return object The instance of the given service.
*/
abstract protected function getService(string $name);

/**

Check failure on line 71 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.3)

LessSpecificReturnStatement

src/Persistence/AbstractManagerRegistry.php:71:16: LessSpecificReturnStatement: The type 'object' is more general than the declared return type 'Doctrine\Persistence\ObjectManager' for Doctrine\Persistence\AbstractManagerRegistry::getConnection (see https://psalm.dev/129)
* Resets the given services.
*
* A service in this context is connection or a manager instance.
Expand Down Expand Up @@ -119,7 +120,7 @@
*/
public function getConnections()
{
$connections = [];

Check failure on line 123 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Call to function assert() with true will always evaluate to true.

Check failure on line 123 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Instanceof between Doctrine\Persistence\ObjectManager and Doctrine\Persistence\ObjectManager will always evaluate to true.
foreach ($this->connections as $name => $id) {
$connections[$name] = $this->getService($id);
}
Expand All @@ -143,7 +144,7 @@
return $this->defaultManager;
}

/**

Check failure on line 147 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Call to function assert() with true will always evaluate to true.

Check failure on line 147 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Instanceof between Doctrine\Persistence\ObjectManager and Doctrine\Persistence\ObjectManager will always evaluate to true.
* {@inheritDoc}
*
* @throws InvalidArgumentException
Expand All @@ -160,14 +161,17 @@
);
}

return $this->getService($this->managers[$name]);
$service = $this->getService($this->managers[$name]);
assert($service instanceof ObjectManager);

return $service;
}

/**
* {@inheritDoc}
*/
public function getManagerForClass(string $class)
{

Check failure on line 174 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Call to function assert() with true will always evaluate to true.

Check failure on line 174 in src/Persistence/AbstractManagerRegistry.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Instanceof between Doctrine\Persistence\ObjectManager and Doctrine\Persistence\ObjectManager will always evaluate to true.
$proxyClass = new ReflectionClass($class);
if ($proxyClass->isAnonymous()) {
return null;
Expand All @@ -185,6 +189,7 @@

foreach ($this->managers as $id) {
$manager = $this->getService($id);
assert($manager instanceof ObjectManager);

if (! $manager->getMetadataFactory()->isTransient($class)) {
return $manager;
Expand All @@ -210,7 +215,8 @@
$managers = [];

foreach ($this->managers as $name => $id) {
$manager = $this->getService($id);
$manager = $this->getService($id);
assert($manager instanceof ObjectManager);
$managers[$name] = $manager;
}

Expand Down
15 changes: 8 additions & 7 deletions src/Persistence/Mapping/Driver/FileDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
* classes on demand. This requires the user to adhere to the convention of 1 mapping
* file per class and the file names of the mapping files must correspond to the full
* class name, including namespace, with the namespace delimiters '\', replaced by dots '.'.
*
* @template T
*/
abstract class FileDriver implements MappingDriver
{
/** @var FileLocator */
protected $locator;

/**
* @var ClassMetadata[]|null
* @psalm-var array<class-string, ClassMetadata<object>>|null
* @var mixed[]|null
* @psalm-var array<class-string, T>|null
*/
protected $classCache;

Expand Down Expand Up @@ -70,7 +72,7 @@
public function getGlobalBasename()
{
return $this->globalBasename;
}

Check failure on line 75 in src/Persistence/Mapping/Driver/FileDriver.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

Method Doctrine\Persistence\Mapping\Driver\FileDriver::getElement() return type with generic interface Doctrine\Persistence\Mapping\ClassMetadata does not specify its types: T

Check failure on line 75 in src/Persistence/Mapping/Driver/FileDriver.php

View workflow job for this annotation

GitHub Actions / Static Analysis / PHPStan (8.3)

PHPDoc tag @return with type T is not subtype of native type Doctrine\Persistence\Mapping\ClassMetadata.

/**
* Gets the element of schema meta data for the class from the mapping file.
Expand All @@ -78,8 +80,7 @@
*
* @psalm-param class-string $className
*
* @return ClassMetadata The element of schema meta data.
* @psalm-return ClassMetadata<object>
* @return T The element of schema meta data.
*
* @throws MappingException
*/
Expand Down Expand Up @@ -154,8 +155,8 @@
*
* @param string $file The mapping file to load.
*
* @return ClassMetadata[]
* @psalm-return array<class-string, ClassMetadata<object>>
* @return mixed[]
* @psalm-return array<class-string, T>
*/
abstract protected function loadMappingFile(string $file);

Expand All @@ -173,7 +174,7 @@
protected function initialize()
{
$this->classCache = [];
if ($this->globalBasename === null) {
if ($this->globalBasename === '') {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Persistence/Mapping/Driver/PHPDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/**
* The PHPDriver includes php files which just populate ClassMetadataInfo
* instances with plain PHP code.
*
* @template-extends FileDriver<ClassMetadata<object>>
*/
class PHPDriver extends FileDriver
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Persistence/Mapping/ColocatedMappingDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testGetAllClassNames(string $path): void
}

/** @return Generator<string, array{string}> */
public function pathProvider(): Generator
public static function pathProvider(): Generator
{
yield 'straigthforward path' => [__DIR__ . '/_files/colocated'];
yield 'winding path' => [__DIR__ . '/../Mapping/_files/colocated'];
Expand Down
1 change: 1 addition & 0 deletions tests/Persistence/Mapping/FileDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private function createTestFileDriver($locator, ?string $fileExtension = null):
}
}

/** @template-extends FileDriver<TestClassMetadata<object>> */
class TestFileDriver extends FileDriver
{
/** @var ClassMetadata<object> */
Expand Down
2 changes: 1 addition & 1 deletion tests/Persistence/Mapping/Fixtures/TestClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use ReflectionClass;

/**
* @template T of object
* @template-covariant T of object
* @template-implements ClassMetadata<T>
*/
final class TestClassMetadata implements ClassMetadata
Expand Down
4 changes: 2 additions & 2 deletions tests/Persistence/Mapping/SymfonyFileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testInvalidCustomNamespaceSeparator(): void
}

/** @return array<string, array{string, string}> */
public function customNamespaceSeparatorProvider(): array
public static function customNamespaceSeparatorProvider(): array
{
return [
'directory separator' => [DIRECTORY_SEPARATOR, '/_custom_ns/dir'],
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testGetClassNamesWithCustomNsSeparator(string $separator, string
}

/** @return array<array{string, string, array<string, string>}> */
public function customNamespaceLookupQueryProvider(): array
public static function customNamespaceLookupQueryProvider(): array
{
return [
'directory separator' => [
Expand Down
Loading