|
42 | 42 | use PHPStan\Type\ErrorType; |
43 | 43 | use PHPStan\Type\FileTypeMapper; |
44 | 44 | use PHPStan\Type\GeneralizePrecision; |
| 45 | +use PHPStan\Type\Generic\TemplateMixedType; |
45 | 46 | use PHPStan\Type\Generic\TemplateTypeHelper; |
46 | 47 | use PHPStan\Type\Generic\TemplateTypeMap; |
47 | 48 | use PHPStan\Type\Generic\TemplateTypeVariance; |
@@ -212,7 +213,7 @@ private function createProperty( |
212 | 213 | $types[] = $value; |
213 | 214 | } |
214 | 215 |
|
215 | | - return new PhpPropertyReflection($declaringClassReflection, null, null, TypeCombinator::union(...$types), $classReflection->getNativeReflection()->getProperty($propertyName), null, false, false, false, false); |
| 216 | + return new PhpPropertyReflection($declaringClassReflection, null, null, TypeCombinator::union(...$types), $classReflection->getNativeReflection()->getProperty($propertyName), null, null, null, false, false, false, false); |
216 | 217 | } |
217 | 218 | } |
218 | 219 |
|
@@ -353,12 +354,72 @@ private function createProperty( |
353 | 354 | $declaringTrait = $reflectionProvider->getClass($declaringTraitName); |
354 | 355 | } |
355 | 356 |
|
| 357 | + $getHook = null; |
| 358 | + $setHook = null; |
| 359 | + |
| 360 | + $betterReflection = $propertyReflection->getBetterReflection(); |
| 361 | + if ($betterReflection->hasHook('get')) { |
| 362 | + $betterReflectionGetHook = $betterReflection->getHook('get'); |
| 363 | + if ($betterReflectionGetHook === null) { |
| 364 | + throw new ShouldNotHappenException(); |
| 365 | + } |
| 366 | + $getHook = $this->createUserlandMethodReflection( |
| 367 | + $declaringClassReflection, |
| 368 | + $declaringClassReflection, |
| 369 | + new ReflectionMethod($betterReflectionGetHook), |
| 370 | + $declaringTraitName, |
| 371 | + ); |
| 372 | + |
| 373 | + if ($phpDocType !== null) { |
| 374 | + $getHookMethodReflectionVariant = $getHook->getOnlyVariant(); |
| 375 | + $getHookMethodReflectionVariantPhpDocReturnType = $getHookMethodReflectionVariant->getPhpDocReturnType(); |
| 376 | + if ( |
| 377 | + $getHookMethodReflectionVariantPhpDocReturnType instanceof MixedType |
| 378 | + && !$getHookMethodReflectionVariantPhpDocReturnType instanceof TemplateMixedType |
| 379 | + && !$getHookMethodReflectionVariantPhpDocReturnType->isExplicitMixed() |
| 380 | + ) { |
| 381 | + $getHook = $getHook->changePropertyGetHookPhpDocType($phpDocType); |
| 382 | + } |
| 383 | + } |
| 384 | + } |
| 385 | + |
| 386 | + if ($betterReflection->hasHook('set')) { |
| 387 | + $betterReflectionSetHook = $betterReflection->getHook('set'); |
| 388 | + if ($betterReflectionSetHook === null) { |
| 389 | + throw new ShouldNotHappenException(); |
| 390 | + } |
| 391 | + $setHook = $this->createUserlandMethodReflection( |
| 392 | + $declaringClassReflection, |
| 393 | + $declaringClassReflection, |
| 394 | + new ReflectionMethod($betterReflectionSetHook), |
| 395 | + $declaringTraitName, |
| 396 | + ); |
| 397 | + |
| 398 | + if ($phpDocType !== null) { |
| 399 | + $setHookMethodReflectionVariant = $setHook->getOnlyVariant(); |
| 400 | + $setHookMethodReflectionParameters = $setHookMethodReflectionVariant->getParameters(); |
| 401 | + if (isset($setHookMethodReflectionParameters[0])) { |
| 402 | + $setHookMethodReflectionParameter = $setHookMethodReflectionParameters[0]; |
| 403 | + $setHookMethodReflectionParameterPhpDocType = $setHookMethodReflectionParameter->getPhpDocType(); |
| 404 | + if ( |
| 405 | + $setHookMethodReflectionParameterPhpDocType instanceof MixedType |
| 406 | + && !$setHookMethodReflectionParameterPhpDocType instanceof TemplateMixedType |
| 407 | + && !$setHookMethodReflectionParameterPhpDocType->isExplicitMixed() |
| 408 | + ) { |
| 409 | + $setHook = $setHook->changePropertySetHookPhpDocType($setHookMethodReflectionParameter->getName(), $phpDocType); |
| 410 | + } |
| 411 | + } |
| 412 | + } |
| 413 | + } |
| 414 | + |
356 | 415 | return new PhpPropertyReflection( |
357 | 416 | $declaringClassReflection, |
358 | 417 | $declaringTrait, |
359 | 418 | $nativeType, |
360 | 419 | $phpDocType, |
361 | 420 | $propertyReflection, |
| 421 | + $getHook, |
| 422 | + $setHook, |
362 | 423 | $deprecatedDescription, |
363 | 424 | $isDeprecated, |
364 | 425 | $isInternal, |
|
0 commit comments