-
Notifications
You must be signed in to change notification settings - Fork 11
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
EnforceReadonlyPublicPropertyRule false positive with property override #162
Comments
I think you should change the default value in constructor of the child. But I think we can change the rule not to report when public prop is overridden. It would be reported in the parent anyway (if that one is analysed and is not in vendor). |
I found this pretty hard to implement when considering the same issue with traits. I believe it should behave like this: <?php
namespace EnforceReadonlyPublicPropertyRuleOverride;
trait MyTraitParent {
public int $parentTraitProperty; // error: Public property `parentTraitProperty` not marked as readonly.
public int $parentTraitPropertyOverridden; // error: Public property `parentTraitPropertyOverridden` not marked as readonly.
}
trait MyTrait {
use MyTraitParent;
public int $traitProperty; // error: Public property `traitProperty` not marked as readonly.
public int $traitPropertyOverridden; // error: Public property `traitPropertyOverridden` not marked as readonly.
public int $parentTraitPropertyOverridden;
}
abstract class MyParentClass {
public int $parentPropertyOverridden; // error: Public property `parentPropertyOverridden` not marked as readonly.
public int $parentProperty; // error: Public property `parentProperty` not marked as readonly.
}
class MyClass extends MyParentClass
{
use MyTrait;
public int $traitPropertyOverridden;
public int $parentPropertyOverridden;
public int $ownProperty; // error: Public property `ownProperty` not marked as readonly.
} But detecting all the cases properly is non-trivial. If you are able to send PR with this testcase green, I'll accept it. But I dont want to invest that much time into this. Thanks for understanding. |
Unfortunately, I cannot. Okay, I'll try to implement it by myself. Also it would be great if the repository has |
Hi there!
In case of property override that rule fails, but PHP doesn't allow to add
readonly
modifier to overriden property.It happened with Laravel Eloquent Model: https://github.com/laravel/framework/blob/ef76b3a4dc0616960a1532c29cad3b8c429f8597/src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php#L14C31-L14C31
Simple code example:
PHPStan output:
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%Line Foo.php
3 Multiple class/interface/trait is not allowed in single file
✏️ Foo.php
9 Property B2B\TCA\VendorClass::$property has no type specified.
✏️ Foo.php
9 Public property
property
not marked as readonly.✏️ Foo.php
14 Property B2B\TCA\User::$property has no type specified.
✏️ Foo.php
14 Public property
property
not marked as readonly.✏️ Foo.php
The text was updated successfully, but these errors were encountered: