Skip to content

Commit 3a0f60d

Browse files
authored
Merge pull request #8734 from VincentLanglet/fixMetadata
Fix metadata constructor inference by phpstan
2 parents ee19cf5 + 249c4fe commit 3a0f60d

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"autoload-dev": {
5353
"psr-4": {
5454
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
55+
"Doctrine\\StaticAnalysis\\": "tests/Doctrine/StaticAnalysis",
5556
"Doctrine\\Performance\\": "tests/Doctrine/Performance"
5657
}
5758
},

lib/Doctrine/ORM/Mapping/ClassMetadata.php

+12
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@
2929
*/
3030
class ClassMetadata extends ClassMetadataInfo
3131
{
32+
/**
33+
* Repeating the ClassMetadataInfo constructor to infer correctly the template with PHPStan
34+
*
35+
* @see https://github.com/doctrine/orm/issues/8709
36+
*
37+
* @param string $entityName The name of the entity class the new instance is used for.
38+
* @psalm-param class-string<T> $entityName
39+
*/
40+
public function __construct($entityName, ?NamingStrategy $namingStrategy = null)
41+
{
42+
parent::__construct($entityName, $namingStrategy);
43+
}
3244
}

phpstan.neon

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ includes:
44
parameters:
55
level: 5
66
paths:
7-
- %currentWorkingDirectory%/lib
7+
- lib
8+
- tests/Doctrine/StaticAnalysis
89
earlyTerminatingMethodCalls:
910
Doctrine\ORM\Query\Parser:
1011
- syntaxError

psalm.xml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
>
1010
<projectFiles>
1111
<directory name="lib/Doctrine/ORM" />
12+
<directory name="tests/Doctrine/StaticAnalysis" />
1213
<ignoreFiles>
1314
<directory name="vendor" />
1415
</ignoreFiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Doctrine\StaticAnalysis\Mapping;
4+
5+
use Doctrine\ORM\Mapping\ClassMetadata;
6+
7+
/**
8+
* @template T of object
9+
*/
10+
class MetadataGenerator
11+
{
12+
/**
13+
* @psalm-param class-string<T> $entityName
14+
*
15+
* @psalm-return ClassMetadata<T>
16+
*/
17+
public function createMetadata(string $entityName): ClassMetadata
18+
{
19+
return new ClassMetadata($entityName);
20+
}
21+
}

0 commit comments

Comments
 (0)