File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed
tests/PHPStan/Analyser/data Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change 4545use PHPStan \Type \Generic \TemplateTypeVariance ;
4646use PHPStan \Type \Generic \TemplateTypeVarianceMap ;
4747use PHPStan \Type \Generic \TypeProjectionHelper ;
48+ use PHPStan \Type \ObjectType ;
4849use PHPStan \Type \Type ;
4950use PHPStan \Type \TypeAlias ;
5051use PHPStan \Type \TypehintHelper ;
@@ -421,7 +422,30 @@ private function allowsDynamicPropertiesExtensions(): bool
421422 return true ;
422423 }
423424
424- return $ this ->hasNativeMethod ('__get ' ) || $ this ->hasNativeMethod ('__set ' ) || $ this ->hasNativeMethod ('__isset ' );
425+ $ hasMagicMethod = $ this ->hasNativeMethod ('__get ' ) || $ this ->hasNativeMethod ('__set ' ) || $ this ->hasNativeMethod ('__isset ' );
426+ if ($ hasMagicMethod ) {
427+ return true ;
428+ }
429+
430+ foreach ($ this ->getRequireExtendsTags () as $ extendsTag ) {
431+ $ type = $ extendsTag ->getType ();
432+ if (!$ type instanceof ObjectType) {
433+ continue ;
434+ }
435+
436+ $ reflection = $ type ->getClassReflection ();
437+ if ($ reflection === null ) {
438+ continue ;
439+ }
440+
441+ if (!$ reflection ->allowsDynamicPropertiesExtensions ()) {
442+ continue ;
443+ }
444+
445+ return true ;
446+ }
447+
448+ return false ;
425449 }
426450
427451 public function hasProperty (string $ propertyName ): bool
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ interface BatchAware
1414}
1515
1616/**
17- * @property-read bool $busy
17+ * @property-read bool $busy2
1818 */
1919class Model
2020{
@@ -27,12 +27,29 @@ public function __get(string $name)
2727 }
2828}
2929
30- class SomeModel extends Model implements BatchAware
30+ function (BatchAware $ b ): void
31+ {
32+ assertType ('bool ' , $ b ->busy );
33+ assertType ('bool ' , $ b ->busy2 );
34+ };
35+
36+ class ModelWithoutAllowDynamicProperties
3137{
3238
3339}
3440
35- function (BatchAware $ b ): void
41+ /**
42+ * @property-read bool $busy
43+ * @phpstan-require-extends ModelWithoutAllowDynamicProperties
44+ */
45+ interface BatchAwareWithoutAllowDynamicProperties
3646{
37- assertType ('bool ' , $ b ->busy );
47+
48+ }
49+
50+ function (BatchAwareWithoutAllowDynamicProperties $ b ): void
51+ {
52+ $ result = $ b ->busy ; // @phpstan-ignore-line
53+
54+ assertType ('*ERROR* ' , $ result );
3855};
You can’t perform that action at this time.
0 commit comments