forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-8048.php
More file actions
33 lines (27 loc) · 703 Bytes
/
Copy pathbug-8048.php
File metadata and controls
33 lines (27 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php declare(strict_types=1);
namespace Bug8048;
interface CustomResponseInterface {}
class CustomResponse implements CustomResponseInterface {}
class ApiService
{
/**
* @template T of CustomResponseInterface
*
* @param class-string<T>|null $responseType
*
* @return ($responseType is class-string<T> ? T : null)
*/
public function request(?string $responseType = null): ?CustomResponseInterface
{
if ($responseType === null) {
return null;
}
return new CustomResponse();
}
}
function (): void {
(new ApiService())->request(null);
(new ApiService())->request(CustomResponse::class);
$x = rand(0, 1) ? CustomResponse::class : null;
(new ApiService())->request($x);
};