@@ -5381,12 +5381,67 @@ private function getBooleanExpressionDepth(Expr $expr, int $depth = 0): int
5381
5381
return $ depth ;
5382
5382
}
5383
5383
5384
- /** @api */
5384
+ /**
5385
+ * @api
5386
+ * @deprecated Use canReadProperty() or canWriteProperty()
5387
+ */
5385
5388
public function canAccessProperty (PropertyReflection $ propertyReflection ): bool
5386
5389
{
5387
5390
return $ this ->canAccessClassMember ($ propertyReflection );
5388
5391
}
5389
5392
5393
+ /** @api */
5394
+ public function canReadProperty (ExtendedPropertyReflection $ propertyReflection ): bool
5395
+ {
5396
+ return $ this ->canAccessClassMember ($ propertyReflection );
5397
+ }
5398
+
5399
+ /** @api */
5400
+ public function canWriteProperty (ExtendedPropertyReflection $ propertyReflection ): bool
5401
+ {
5402
+ if (!$ propertyReflection ->isPrivateSet () && !$ propertyReflection ->isProtectedSet ()) {
5403
+ return $ this ->canAccessClassMember ($ propertyReflection );
5404
+ }
5405
+
5406
+ if (!$ this ->phpVersion ->supportsAsymmetricVisibility ()) {
5407
+ return $ this ->canAccessClassMember ($ propertyReflection );
5408
+ }
5409
+
5410
+ $ classReflectionName = $ propertyReflection ->getDeclaringClass ()->getName ();
5411
+ $ canAccessClassMember = static function (ClassReflection $ classReflection ) use ($ propertyReflection , $ classReflectionName ) {
5412
+ if ($ propertyReflection ->isPrivateSet ()) {
5413
+ return $ classReflection ->getName () === $ classReflectionName ;
5414
+ }
5415
+
5416
+ // protected set
5417
+
5418
+ if (
5419
+ $ classReflection ->getName () === $ classReflectionName
5420
+ || $ classReflection ->isSubclassOf ($ classReflectionName )
5421
+ ) {
5422
+ return true ;
5423
+ }
5424
+
5425
+ return $ propertyReflection ->getDeclaringClass ()->isSubclassOf ($ classReflection ->getName ());
5426
+ };
5427
+
5428
+ foreach ($ this ->inClosureBindScopeClasses as $ inClosureBindScopeClass ) {
5429
+ if (!$ this ->reflectionProvider ->hasClass ($ inClosureBindScopeClass )) {
5430
+ continue ;
5431
+ }
5432
+
5433
+ if ($ canAccessClassMember ($ this ->reflectionProvider ->getClass ($ inClosureBindScopeClass ))) {
5434
+ return true ;
5435
+ }
5436
+ }
5437
+
5438
+ if ($ this ->isInClass ()) {
5439
+ return $ canAccessClassMember ($ this ->getClassReflection ());
5440
+ }
5441
+
5442
+ return false ;
5443
+ }
5444
+
5390
5445
/** @api */
5391
5446
public function canCallMethod (MethodReflection $ methodReflection ): bool
5392
5447
{
0 commit comments