You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 07d57b7
Browse filesBrowse the repository at this point in the historyBrowse files
Allow initializing readonly properties in methods only the constructor calls
PreservedPropertiesVisitor now records which methods call each method on $this.
A private method, or a protected one in a final class without a parent, that is only
run from the constructors (directly or through other such methods) may initialize
readonly and @readonly properties.
A method the constructor calls twice now reports the second initialization as
already assigned: the call sites are combined with extremeIdentity instead of and.
Amp-Thread-ID: https://ampcode.com/threads/T-01a213ea-2998-7296-a072-5e436e1454ce
@@ -107,6 +109,15 @@ final class PreservedPropertiesClassScan
107
109
/** @var list<array{Expr, self::CALL_*, string}> calls on $this outside closures, with their kind and lowercase method name */
108
110
publicarray$calls = [];
109
111
112
+
/** @var array<string, array<string, true>> the methods calling each method of the class on $this by lowercase name, self::CLOSURES for calls in closures */
113
+
publicarray$callers = [];
114
+
115
+
/** @var array<string, true> lowercase method names called other than on $this, handed out, or mentioned in a string, which can name a callable */
116
+
publicarray$calledElsewhere = [];
117
+
118
+
/** Some code calls a method by a name that is not written in it, which can be any method of the class. */
119
+
publicbool$hasDynamicCalls = false;
120
+
110
121
publicfunction__construct(
111
122
publicbool$isFinal,
112
123
publicbool$hasParent,
@@ -133,6 +144,81 @@ public function addProperty(string $propertyName, bool $isPrivate, bool $isProte
/** Attached to a method only the class's own code calls: the lowercase names of the methods it is only ever run from (see PreservedPropertiesClassScan::annotateOnlyCalledFrom()). */
// a method the constructor calls initializes the property
128
+
continue;
129
+
}
130
+
123
131
$errors[] = RuleErrorBuilder::message(sprintf('@readonly property %s::$%s is assigned outside of the constructor.', $declaringClass->getDisplayName(), $propertyReflection->getName()))
// a method the constructor calls initializes the property
141
+
continue;
142
+
}
143
+
136
144
$errors[] = RuleErrorBuilder::message(sprintf('Readonly property %s::$%s is assigned outside of the constructor.', $declaringClass->getDisplayName(), $propertyReflection->getName()))
0 commit comments