-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bleeding edge - deep inspect unresolvable types in PHPDoc
- Loading branch information
1 parent
003d235
commit 1de5de8
Showing
13 changed files
with
146 additions
and
55 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
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,47 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules\PhpDoc; | ||
|
||
use PHPStan\Type\ErrorType; | ||
use PHPStan\Type\NeverType; | ||
use PHPStan\Type\Type; | ||
use PHPStan\Type\TypeTraverser; | ||
|
||
class UnresolvableTypeHelper | ||
{ | ||
|
||
private bool $deepInspectTypes; | ||
|
||
public function __construct(bool $deepInspectTypes) | ||
{ | ||
$this->deepInspectTypes = $deepInspectTypes; | ||
} | ||
|
||
public function containsUnresolvableType(Type $type): bool | ||
{ | ||
if ($this->deepInspectTypes) { | ||
$containsUnresolvable = false; | ||
TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$containsUnresolvable): Type { | ||
if ($type instanceof ErrorType) { | ||
$containsUnresolvable = true; | ||
return $type; | ||
} | ||
if ($type instanceof NeverType && !$type->isExplicit()) { | ||
$containsUnresolvable = true; | ||
return $type; | ||
} | ||
|
||
return $traverse($type); | ||
}); | ||
|
||
return $containsUnresolvable; | ||
} | ||
|
||
if ($type instanceof ErrorType) { | ||
return true; | ||
} | ||
|
||
return $type instanceof NeverType && !$type->isExplicit(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.