From a0e040a4624b1e81a12cf37b7f46dd9b457cf5ec Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Wed, 20 Feb 2019 13:54:01 +0200 Subject: [PATCH] Expose more internal methods through Codebase - `bool Codebase::canTypeBeContainedByType(Union $input, Union $container)` - `array{Union,Union} Codebase::getKeyValueParamsForTraversableObject(Atomic $type)` For usage, see psalm/phpunit-psalm-plugin#15 --- src/Psalm/Codebase.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 5ee588a95..e585039ac 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -3,6 +3,7 @@ namespace Psalm; use LanguageServerProtocol\{Position, Range}; use PhpParser; +use Psalm\Internal\Analyzer\Statements\Block\ForeachAnalyzer; use Psalm\Internal\Analyzer\ProjectAnalyzer; use Psalm\Internal\Analyzer\TypeAnalyzer; use Psalm\Internal\Provider\ClassLikeStorageProvider; @@ -1149,7 +1150,7 @@ class Codebase { $this->file_provider->removeTemporaryFileChanges($file_path); } - + /** * @psalm-suppress PossiblyUnusedMethod */ @@ -1159,4 +1160,31 @@ class Codebase ): bool { return TypeAnalyzer::isContainedBy($this, $input_type, $container_type); } + + /** + * @psalm-suppress PossiblyUnusedMethod + */ + public function canTypeBeContainedByType( + Type\Union $input_type, + Type\Union $container_type + ): bool { + return TypeAnalyzer::canBeContainedBy($this, $input_type, $container_type); + } + + /** + * @return array{Type\Union,Type\Union} + * @psalm-suppress PossiblyUnusedMethod + */ + public function getKeyValueParamsForTraversableObject(Type\Atomic $type): array + { + $key_type = null; + $value_type = null; + + ForeachAnalyzer::getKeyValueParamsForTraversableObject($type, $this, $key_type, $value_type); + + return [ + $key_type ?? Type::getMixed(), + $value_type ?? Type::getMixed(), + ]; + } }