Skip to content

Commit

Permalink
Merge pull request #374 from greg0ire/fix-types
Browse files Browse the repository at this point in the history
Make types compatible with ORM/ODM drivers
  • Loading branch information
greg0ire authored Jun 20, 2024
2 parents 53c572a + bce9a5e commit b337726
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
13 changes: 7 additions & 6 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 @@ -78,8 +80,7 @@ public function getGlobalBasename()
*
* @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 @@ public function getAllClassNames()
*
* @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 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
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

0 comments on commit b337726

Please sign in to comment.