-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c926144
commit 60021c2
Showing
7 changed files
with
250 additions
and
6 deletions.
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
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
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,175 @@ | ||
<?php | ||
|
||
namespace Bug5091\Monolog { | ||
/** | ||
* @phpstan-type Record array{message: string} | ||
*/ | ||
class Logger { | ||
} | ||
} | ||
|
||
namespace Bug5091\Monolog\Handler { | ||
/** | ||
* @phpstan-import-type Record from \Bug5091\Monolog\Logger | ||
*/ | ||
class Handler { | ||
use \Bug5091\Monolog\Processor\TraitA; | ||
} | ||
} | ||
|
||
namespace Bug5091\Monolog\Processor { | ||
/** | ||
* @phpstan-import-type Record from \Bug5091\Monolog\Logger | ||
*/ | ||
trait TraitA { | ||
/** | ||
* @var Record | ||
*/ | ||
public $foo; | ||
|
||
/** | ||
* @return Record | ||
*/ | ||
public function foo() { | ||
return ['message' => '']; | ||
} | ||
} | ||
} | ||
|
||
namespace Bug5091 { | ||
|
||
/** | ||
* @phpstan-type MyType array{foobar: string} | ||
*/ | ||
trait MyTrait | ||
{ | ||
/** | ||
* @return array<MyType> | ||
*/ | ||
public function MyMethod(): array | ||
{ | ||
return [['foobar' => 'foo']]; | ||
} | ||
} | ||
|
||
class MyClass | ||
{ | ||
use MyTrait; | ||
} | ||
|
||
/** | ||
* @phpstan-type TypeArrayAjaxResponse array{ | ||
* message : string, | ||
* status : int, | ||
* success : bool, | ||
* value : null|float|int|string, | ||
* } | ||
*/ | ||
trait MyTrait2 | ||
{ | ||
/** @return TypeArrayAjaxResponse */ | ||
protected function getAjaxResponse(): array | ||
{ | ||
return [ | ||
"message" => "test", | ||
"status" => 200, | ||
"success" => true, | ||
"value" => 5, | ||
]; | ||
} | ||
} | ||
|
||
class MyController | ||
{ | ||
use MyTrait2; | ||
} | ||
|
||
|
||
/** | ||
* @phpstan-type X string | ||
*/ | ||
class Types {} | ||
|
||
/** | ||
* @phpstan-import-type X from Types | ||
*/ | ||
trait t { | ||
/** @return X */ | ||
public function getX() { | ||
return "123"; | ||
} | ||
} | ||
|
||
class aClass | ||
{ | ||
use t; | ||
} | ||
|
||
/** | ||
* @phpstan-import-type X from Types | ||
*/ | ||
class Z { | ||
/** @return X */ | ||
public function getX() { // works as expected | ||
return "123"; | ||
} | ||
} | ||
|
||
/** | ||
* @phpstan-type SomePhpstanType array{ | ||
* property: mixed | ||
* } | ||
*/ | ||
trait TraitWithType | ||
{ | ||
/** | ||
* @phpstan-return SomePhpstanType | ||
*/ | ||
protected function get(): array | ||
{ | ||
return [ | ||
'property' => 'something', | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* @phpstan-import-type SomePhpstanType from TraitWithType | ||
*/ | ||
class ClassWithTraitWithType | ||
{ | ||
use TraitWithType; | ||
|
||
/** | ||
* @phpstan-return SomePhpstanType | ||
*/ | ||
public function SomeMethod(): array | ||
{ | ||
return $this->get(); | ||
} | ||
} | ||
|
||
/** | ||
* @phpstan-type FooJson array{bar: string} | ||
*/ | ||
trait Foo { | ||
/** | ||
* @phpstan-return FooJson | ||
*/ | ||
public function sayHello(\DateTime $date): array | ||
{ | ||
return [ | ||
'bar'=> 'baz' | ||
]; | ||
} | ||
} | ||
|
||
/** | ||
* @phpstan-import-type FooJson from Foo | ||
*/ | ||
class HelloWorld | ||
{ | ||
use Foo; | ||
} | ||
|
||
} |
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,54 @@ | ||
<?php | ||
|
||
namespace TraitTypeAlias; | ||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
trait NoAlias | ||
{ | ||
|
||
/** | ||
* @param Foo $p | ||
*/ | ||
public function doFoo($p): void | ||
{ | ||
assertType(Foo::class, $p); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @phpstan-type Foo array{1} | ||
*/ | ||
class UsesNoAlias | ||
{ | ||
|
||
use NoAlias; | ||
|
||
} | ||
|
||
/** | ||
* @phpstan-type Foo array{2} | ||
*/ | ||
trait WithAlias | ||
{ | ||
|
||
/** | ||
* @param Foo $p | ||
*/ | ||
public function doFoo($p): void | ||
{ | ||
assertType('array{2}', $p); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* @phpstan-type Foo array{1} | ||
*/ | ||
class UsesWithAlias | ||
{ | ||
|
||
use WithAlias; | ||
|
||
} |