Skip to content

Commit

Permalink
Fix metadata constructor inference by phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed May 31, 2021
1 parent 75b4b88 commit 89673c6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"autoload-dev": {
"psr-4": {
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
"Doctrine\\StaticAnalysis\\": "tests/Doctrine/StaticAnalysis",
"Doctrine\\Performance\\": "tests/Doctrine/Performance"
}
},
Expand Down
12 changes: 12 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@
*/
class ClassMetadata extends ClassMetadataInfo
{
/**
* Repeating the ClassMetadataInfo constructor to infer correctly the template with PHPStan
*
* @see https://github.com/doctrine/orm/issues/8709
*
* @param string $entityName The name of the entity class the new instance is used for.
* @psalm-param class-string<T> $entityName
*/
public function __construct($entityName, ?NamingStrategy $namingStrategy = null)
{
parent::__construct($entityName, $namingStrategy);
}
}
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ parameters:
level: 5
paths:
- %currentWorkingDirectory%/lib
- %currentWorkingDirectory%/tests/Doctrine/StaticAnalysis
earlyTerminatingMethodCalls:
Doctrine\ORM\Query\Parser:
- syntaxError
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<projectFiles>
<directory name="lib/Doctrine/ORM" />
<directory name="tests/Doctrine/StaticAnalysis" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Doctrine\StaticAnalysis\Mapping;

use Doctrine\ORM\Mapping\ClassMetadata;

/**
* @template T of object
*/
class MetadataGenerator
{
/**
* @psalm-param class-string<T> $entityName
*
* @psalm-return ClassMetadata<T>
*/
public function createMetadata(string $entityName): ClassMetadata
{
return new ClassMetadata($entityName);
}
}

0 comments on commit 89673c6

Please sign in to comment.