-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Raise Psalm level to 3 and add generics to ClassMetadata #159
Changes from 10 commits
9a56cc0
16e8615
01707f5
5a5e6a3
d8c5f79
6b24d36
4eab605
5893ad2
54d344b
8e6fc2f
a067fdf
07ed4b6
df82d13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
use function array_map; | ||
use function array_reverse; | ||
use function array_unshift; | ||
use function assert; | ||
use function explode; | ||
use function sprintf; | ||
use function str_replace; | ||
|
@@ -163,6 +164,8 @@ abstract protected function initialize(); | |
* @param string $simpleClassName | ||
* | ||
* @return string | ||
* | ||
* @psalm-return class-string | ||
*/ | ||
abstract protected function getFqcnFromAlias($namespaceAlias, $simpleClassName); | ||
|
||
|
@@ -218,6 +221,7 @@ public function getMetadataFor($className) | |
|
||
$realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName); | ||
} else { | ||
/** @psalm-var class-string $className */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be specified in parameters instead of overrided with @var There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for reviewing! I remember struggling with this one: // Check for namespace alias
if (strpos($className, ':') !== false) {
[$namespaceAlias, $simpleClassName] = explode(':', $className, 2);
$realClassName = $this->getFqcnFromAlias($namespaceAlias, $simpleClassName);
} else {
/** @psalm-var class-string $className */
$realClassName = $this->getRealClass($className);
}
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nevermind then, I thought $className would always be a className. How naive :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe rename |
||
$realClassName = $this->getRealClass($className); | ||
} | ||
|
||
|
@@ -307,6 +311,8 @@ public function setMetadataFor($className, $class) | |
* @param string $name | ||
* | ||
* @return string[] | ||
* | ||
* @psalm-param class-string $name | ||
*/ | ||
protected function getParentClasses($name) | ||
{ | ||
|
@@ -337,6 +343,8 @@ protected function getParentClasses($name) | |
* @param string $name The name of the class for which the metadata should get loaded. | ||
* | ||
* @return string[] | ||
* | ||
* @psalm-param class-string $name | ||
*/ | ||
protected function loadMetadata($name) | ||
{ | ||
|
@@ -483,6 +491,8 @@ private function getRealClass(string $class): string | |
$this->createDefaultProxyClassNameResolver(); | ||
} | ||
|
||
assert($this->proxyClassNameResolver !== null); | ||
|
||
return $this->proxyClassNameResolver->resolveClassName($class); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,9 @@ interface ReflectionService | |||||||||||||||||
* @return string[] | ||||||||||||||||||
* | ||||||||||||||||||
* @throws MappingException | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
* @psalm-return class-string[] | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use the extensive syntax if offset type is known? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only implementation I've seen (apart from the ones returning empty array) is
So I don't know if that can be improved. |
||||||||||||||||||
*/ | ||||||||||||||||||
public function getParentClasses($class); | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -30,13 +33,17 @@ public function getParentClasses($class); | |||||||||||||||||
* @param string $class | ||||||||||||||||||
* | ||||||||||||||||||
* @return string | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getClassShortName($class); | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* @param string $class | ||||||||||||||||||
* | ||||||||||||||||||
* @return string | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getClassNamespace($class); | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -46,6 +53,8 @@ public function getClassNamespace($class); | |||||||||||||||||
* @param string $class | ||||||||||||||||||
* | ||||||||||||||||||
* @return ReflectionClass|null | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getClass($class); | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -56,6 +65,8 @@ public function getClass($class); | |||||||||||||||||
* @param string $property | ||||||||||||||||||
* | ||||||||||||||||||
* @return ReflectionProperty|null | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
*/ | ||||||||||||||||||
public function getAccessibleProperty($class, $property); | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -66,6 +77,8 @@ public function getAccessibleProperty($class, $property); | |||||||||||||||||
* @param mixed $method | ||||||||||||||||||
* | ||||||||||||||||||
* @return bool | ||||||||||||||||||
* | ||||||||||||||||||
* @psalm-param class-string $class | ||||||||||||||||||
*/ | ||||||||||||||||||
public function hasPublicMethod($class, $method); | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
totallyTyped="false" | ||
errorLevel="4" | ||
errorLevel="3" | ||
resolveFromConfigFile="true" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
|
@@ -39,5 +39,25 @@ | |
<file name="tests/Doctrine/Tests/Persistence/Mapping/SymfonyFileLocatorTest.php"/> | ||
</errorLevel> | ||
</NullArgument> | ||
<PossiblyNullReference> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe leave a comment to explain why those couldn't be fixed and had to be ignored? It will be helpful for future contributions |
||
<errorLevel type="suppress"> | ||
<!-- ReflectionProperty::getType() can return null, but there is ReflectionProperty::hasType() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been fixed in Psalm recently: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, my mistake then :) |
||
check before --> | ||
<file name="lib/Doctrine/Persistence/Reflection/TypedNoDefaultReflectionProperty.php"/> | ||
</errorLevel> | ||
</PossiblyNullReference> | ||
<ArgumentTypeCoercion> | ||
<errorLevel type="suppress"> | ||
<!-- On purpose to use a non existing class for tests --> | ||
<referencedFunction name="RuntimeReflectionServiceTest::testGetParentClassesForAbsentClass"/> | ||
<file name="tests/Doctrine/Tests/Persistence/Mapping/RuntimeReflectionServiceTest.php"/> | ||
</errorLevel> | ||
</ArgumentTypeCoercion> | ||
<MoreSpecificReturnType> | ||
<errorLevel type="suppress"> | ||
<!-- FileDriver::loadMappingFile() in tests could have a more specific return, but is not needed --> | ||
<file name="tests/Doctrine/Tests/Persistence/Mapping/FileDriverTest.php"/> | ||
</errorLevel> | ||
</MoreSpecificReturnType> | ||
</issueHandlers> | ||
</psalm> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe an assertion for class_exists could be used in the future instead of overriding? In a future version to avoid BC breaks maybe?