Skip to content

Commit 4e5a697

Browse files
committed
Test useful example with class-level template type T and static method
1 parent 5988167 commit 4e5a697

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/PHPStan/Analyser/data/generics.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,3 +1361,32 @@ public function method($one, $two): void
13611361
assertType('float', $this->property);
13621362
}
13631363
}
1364+
1365+
/**
1366+
* @template T
1367+
*/
1368+
interface GeneralFactoryInterface {
1369+
/**
1370+
* @return T
1371+
*/
1372+
public static function create();
1373+
}
1374+
1375+
class Car {}
1376+
1377+
/**
1378+
* @implements GeneralFactoryInterface<Car>
1379+
*/
1380+
class CarFactory implements GeneralFactoryInterface {
1381+
public static function create() { return new Car(); }
1382+
}
1383+
1384+
class CarFactoryProcessor {
1385+
/**
1386+
* @param class-string<CarFactory> $class
1387+
*/
1388+
public function process($class): void {
1389+
$car = $class::create();
1390+
assertType(Car::class, $car);
1391+
}
1392+
}

0 commit comments

Comments
 (0)