-
Notifications
You must be signed in to change notification settings - Fork 523
Asymmetric @property types #2294
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
Conversation
cc9fe7e
to
e8425b3
Compare
src/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtension.php
Outdated
Show resolved
Hide resolved
src/Reflection/Annotations/AnnotationsPropertiesClassReflectionExtension.php
Outdated
Show resolved
Hide resolved
$propertyWriteTags[$propertyName]->getType(), | ||
$classReflection->getActiveTemplateTypeMap(), | ||
); | ||
|
||
return new AnnotationPropertyReflection( | ||
$declaringClass, |
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.
The limitation that any @property{,-read,write}
will shadow all magic properties from parent. But that is probably not needed for most use cases.
131e032
to
69ec1dd
Compare
This pull request has been marked as ready for review. |
5c68b74
to
3f40360
Compare
22e7486
to
81cc328
Compare
} | ||
|
||
public function getWritableType(): Type | ||
{ | ||
return $this->type; | ||
return $this->writableType ?? new VoidType(); |
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.
Looks like nextras/orm test tries to write to @property-read
https://github.com/nextras/orm/blob/58764efa7035bd163988eaa367115fece1afbf7e/tests/inc/model/tag/Tag.php#L13. Opened nextras/orm-phpstan#28.
This comment was marked as resolved.
This comment was marked as resolved.
Isn't this fixing phpstan/phpstan#4845 as well? (Probably not :/) |
@hrach With this PR, it would be expressible as: /**
* @property DateTimeImmutable|null $createdAt
* @property-write DateTimeImmutable|'now'|null $createdAt
*/
class Entity {}
$e = new Entity();
$e->createdAt = 'now';
$e->createdAt->format(); But you would still need |
bfd7f40
to
075c3cc
Compare
075c3cc
to
4cd7b39
Compare
Allow having `@property-read` and `@property-write` with the same name but different types.
Ideally, `get{Readable,Writable}Type()` would be nullable but that would be a BC break.
We cannot make `PropertyReflection::get{Readable,Writable}Type()` nullable without breaking API compatibility. Instead, we will use `VoidType` since no values inhabit it, which is a nice fit for a property that does not exist – properties always need to have a value.
…ly properties Those will be caught by WritingToReadOnlyPropertiesRule and we would just get: Property Foo::$bar (void) does not accept string. Property Foo::$bar is not writable.
4cd7b39
to
8da5e47
Compare
Hello, thank you for your work! I took the liberty to take your tests and implement it in an easier way: #2327 We just needed to add different types to PropertyTag, there was no need to deprecate |
Fixes: phpstan/phpstan#9062