File tree Expand file tree Collapse file tree
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1735,21 +1735,20 @@ public function getNakedClassReflection(): ?ClassReflection
17351735
17361736 public function getClassReflection (): ?ClassReflection
17371737 {
1738- if ($ this ->classReflection !== null ) {
1739- return $ this ->classReflection ;
1740- }
1738+ if ($ this ->classReflection === null ) {
1739+ $ reflectionProvider = ReflectionProviderStaticAccessor::getInstance ();
1740+ if (!$ reflectionProvider ->hasClass ($ this ->className )) {
1741+ return null ;
1742+ }
17411743
1742- $ reflectionProvider = ReflectionProviderStaticAccessor::getInstance ();
1743- if (!$ reflectionProvider ->hasClass ($ this ->className )) {
1744- return null ;
1744+ $ this ->classReflection = $ reflectionProvider ->getClass ($ this ->className );
17451745 }
17461746
1747- $ classReflection = $ reflectionProvider ->getClass ($ this ->className );
1748- if ($ classReflection ->isGeneric ()) {
1749- return $ this ->classReflection = $ classReflection ->withTypes (array_values ($ classReflection ->getTemplateTypeMap ()->map (static fn (): Type => new ErrorType ())->getTypes ()));
1747+ if ($ this ->classReflection ->isGeneric ()) {
1748+ return $ this ->classReflection ->withTypes (array_values ($ this ->classReflection ->getTemplateTypeMap ()->map (static fn (): Type => new ErrorType ())->getTypes ()));
17501749 }
17511750
1752- return $ this ->classReflection = $ classReflection ;
1751+ return $ this ->classReflection ;
17531752 }
17541753
17551754 public function getAncestorWithClassName (string $ className ): ?self
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Bug13985 ;
4+
5+ use SplObjectStorage ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ function example (mixed $ param ): void
9+ {
10+ if ($ param instanceof SplObjectStorage) {
11+ foreach ($ param as $ key => $ value ) {
12+ assertType ('int ' , $ key );
13+ assertType ('object ' , $ value );
14+ }
15+ }
16+ }
17+
18+ class X {}
19+
20+ /**
21+ * @param SplObjectStorage<X, int> $splObjectStorage
22+ * @return void
23+ */
24+ function genericExample (SplObjectStorage $ splObjectStorage ): void
25+ {
26+ foreach ($ splObjectStorage as $ key => $ value ) {
27+ assertType ('int ' , $ key );
28+ assertType ('Bug13985\X ' , $ value );
29+ }
30+ assertType ('int ' , $ splObjectStorage ->getInfo ());
31+
32+ }
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.0
2+
3+ namespace Bug4789 ;
4+
5+ use function PHPStan \Testing \assertType ;
6+
7+ function doFoo (\DatePeriod $ p ) {
8+ foreach ($ p as $ dt ) {
9+ assertType ('DateTimeInterface ' , $ dt );
10+ }
11+ }
You can’t perform that action at this time.
0 commit comments