-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added regression tests for fixed issues.
- Loading branch information
1 parent
fe07a03
commit 7114662
Showing
8 changed files
with
276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug10283; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class JsExpressionable {} | ||
|
||
class Cl | ||
{ | ||
/** | ||
* @param \Closure(): JsExpressionable|\Closure(): int $fx | ||
*/ | ||
public function test($fx): ?JsExpressionable | ||
{ | ||
$res = $fx(); | ||
assertType('Bug10283\JsExpressionable|int', $res); | ||
|
||
if (is_int($res)) { | ||
return null; | ||
} | ||
|
||
return $res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug6633; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class CreateServiceSolrData | ||
{ | ||
public ?string $name; | ||
public ?string $version; | ||
} | ||
|
||
class CreateServiceRedisData | ||
{ | ||
public ?string $name; | ||
public ?string $version; | ||
public ?bool $persistent; | ||
|
||
} | ||
|
||
class ServiceSolr | ||
{ | ||
public function __construct( | ||
private string $name, | ||
private string $version, | ||
) {} | ||
|
||
public function touchAll() : string{ | ||
return $this->name . $this->version; | ||
} | ||
} | ||
|
||
class ServiceRedis | ||
{ | ||
public function __construct( | ||
private string $name, | ||
private string $version, | ||
private bool $persistent, | ||
) {} | ||
|
||
public function touchAll() : string{ | ||
return $this->persistent ? $this->name : $this->version; | ||
} | ||
} | ||
|
||
function test(?string $type = NULL) : void { | ||
$types = [ | ||
'solr' => [ | ||
'label' => 'SOLR Search', | ||
'data_class' => CreateServiceSolrData::class, | ||
'to_entity' => function (CreateServiceSolrData $data) { | ||
assert($data->name !== NULL && $data->version !== NULL, "Incorrect form validation"); | ||
return new ServiceSolr($data->name, $data->version); | ||
}, | ||
], | ||
'redis' => [ | ||
'label' => 'Redis', | ||
'data_class' => CreateServiceRedisData::class, | ||
'to_entity' => function (CreateServiceRedisData $data) { | ||
assert($data->name !== NULL && $data->version !== NULL && $data->persistent !== NULL, "Incorrect form validation"); | ||
return new ServiceRedis($data->name, $data->version, $data->persistent); | ||
}, | ||
], | ||
]; | ||
|
||
if ($type === NULL || !isset($types[$type])) { | ||
throw new \RuntimeException("404 or choice form here"); | ||
} | ||
|
||
$data = new $types[$type]['data_class'](); | ||
|
||
$service = $types[$type]['to_entity']($data); | ||
|
||
assertType('Bug6633\ServiceRedis|Bug6633\ServiceSolr', $service); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug3818b; | ||
|
||
class A | ||
{ | ||
} | ||
|
||
class B | ||
{ | ||
} | ||
|
||
class Foo | ||
{ | ||
public function handle(A|B $obj): void | ||
{ | ||
$method = $obj instanceof A ? $this->handleA(...) : $this->handleB(...); | ||
|
||
$method($obj); | ||
} | ||
|
||
private function handleA(A $a): void | ||
{ | ||
} | ||
|
||
private function handleB(B $b): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug6633\Rule; | ||
|
||
class CreateServiceSolrData | ||
{ | ||
public ?string $name; | ||
public ?string $version; | ||
} | ||
|
||
class CreateServiceRedisData | ||
{ | ||
public ?string $name; | ||
public ?string $version; | ||
public ?bool $persistent; | ||
|
||
} | ||
|
||
class ServiceSolr | ||
{ | ||
public function __construct( | ||
private string $name, | ||
private string $version, | ||
) {} | ||
|
||
public function touchAll() : string{ | ||
return $this->name . $this->version; | ||
} | ||
} | ||
|
||
class ServiceRedis | ||
{ | ||
public function __construct( | ||
private string $name, | ||
private string $version, | ||
private bool $persistent, | ||
) {} | ||
|
||
public function touchAll() : string{ | ||
return $this->persistent ? $this->name : $this->version; | ||
} | ||
} | ||
|
||
function test(?string $type = NULL) : void { | ||
$types = [ | ||
'solr' => [ | ||
'label' => 'SOLR Search', | ||
'data_class' => CreateServiceSolrData::class, | ||
'to_entity' => function (CreateServiceSolrData $data) { | ||
assert($data->name !== NULL && $data->version !== NULL, "Incorrect form validation"); | ||
return new ServiceSolr($data->name, $data->version); | ||
}, | ||
], | ||
'redis' => [ | ||
'label' => 'Redis', | ||
'data_class' => CreateServiceRedisData::class, | ||
'to_entity' => function (CreateServiceRedisData $data) { | ||
assert($data->name !== NULL && $data->version !== NULL && $data->persistent !== NULL, "Incorrect form validation"); | ||
return new ServiceRedis($data->name, $data->version, $data->persistent); | ||
}, | ||
], | ||
]; | ||
|
||
if ($type === NULL || !isset($types[$type])) { | ||
throw new \RuntimeException("404 or choice form here"); | ||
} | ||
|
||
$data = new $types[$type]['data_class'](); | ||
|
||
$service = $types[$type]['to_entity']($data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug9594; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(): void | ||
{ | ||
$data = [ | ||
[ | ||
'elements' => [1, 2, 3], | ||
'greet' => fn (int $value) => 'I am '.$value, | ||
], | ||
[ | ||
'elements' => ['hello', 'world'], | ||
'greet' => fn (string $value) => 'I am '.$value, | ||
], | ||
]; | ||
|
||
foreach ($data as $entry) { | ||
foreach ($entry['elements'] as $element) { | ||
$entry['greet']($element); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug9614; | ||
|
||
class HelloWorld | ||
{ | ||
public function sayHello(string $key, ?string $a = null, ?string $b = null): string | ||
{ | ||
$funcs = [ | ||
'test' => function() { | ||
return 'test'; | ||
}, | ||
'foo' => function($a) { | ||
return 'foo'; | ||
}, | ||
'bar' => function($a, $b) { | ||
return 'bar'; | ||
} | ||
]; | ||
|
||
if (!isset($funcs[$key])) { | ||
return ''; | ||
} | ||
|
||
return $funcs[$key]($a, $b); | ||
} | ||
} |