1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-14 02:07:37 +01:00
psalm/src/Psalm/Checker/InterfaceChecker.php
Matthew Brown 4175295113 Isolate where we load static storage objects (#195)
* Move FileChecker::$storage calls to provider

* Add ClassLikeStorageProvider

* Use ClassLikeStorageProvider everywhere

* Move storage arrays into providers
2017-07-29 15:05:06 -04:00

74 lines
2.2 KiB
PHP

<?php
namespace Psalm\Checker;
use PhpParser;
use Psalm\StatementsSource;
class InterfaceChecker extends ClassLikeChecker
{
/**
* @param PhpParser\Node\Stmt\Interface_ $interface
* @param StatementsSource $source
* @param string $fq_interface_name
*/
public function __construct(PhpParser\Node\Stmt\Interface_ $interface, StatementsSource $source, $fq_interface_name)
{
parent::__construct($interface, $source, $fq_interface_name);
}
/**
* @param string $fq_interface_name
* @param FileChecker $file_checker
*
* @return bool
*/
public static function interfaceExists(ProjectChecker $project_checker, $fq_interface_name)
{
if (isset(self::$SPECIAL_TYPES[strtolower($fq_interface_name)])) {
return false;
}
return $project_checker->hasFullyQualifiedInterfaceName($fq_interface_name);
}
/**
* @param string $fq_interface_name
* @param FileChecker $file_checker
*
* @return bool
*/
public static function hasCorrectCasing(ProjectChecker $project_checker, $fq_interface_name)
{
return isset($project_checker->existing_interfaces[$fq_interface_name]);
}
/**
* @param string $interface_name
* @param string $possible_parent
* @param FileChecker $file_checker
*
* @return bool
*/
public static function interfaceExtends(ProjectChecker $project_checker, $interface_name, $possible_parent)
{
return in_array($possible_parent, self::getParentInterfaces($project_checker, $interface_name), true);
}
/**
* @param string $fq_interface_name
* @param FileChecker $file_checker
*
* @return array<string> all interfaces extended by $interface_name
*/
public static function getParentInterfaces(ProjectChecker $project_checker, $fq_interface_name)
{
$fq_interface_name = strtolower($fq_interface_name);
$extended_interfaces = [];
$storage = $project_checker->classlike_storage_provider->get($fq_interface_name);
return $storage->parent_interfaces;
}
}