2016-05-16 05:06:03 +02:00
|
|
|
<?php
|
2016-08-13 20:20:46 +02:00
|
|
|
namespace Psalm\Checker;
|
2016-05-16 05:06:03 +02:00
|
|
|
|
|
|
|
use PhpParser;
|
2016-08-14 00:54:49 +02:00
|
|
|
use Psalm\StatementsSource;
|
2016-05-16 05:06:03 +02:00
|
|
|
|
2016-08-13 20:20:46 +02:00
|
|
|
class InterfaceChecker extends ClassLikeChecker
|
2016-05-16 05:06:03 +02:00
|
|
|
{
|
2016-10-15 06:12:57 +02:00
|
|
|
/**
|
2017-07-25 22:11:02 +02:00
|
|
|
* @param PhpParser\Node\Stmt\Interface_ $interface
|
2016-10-15 06:12:57 +02:00
|
|
|
* @param StatementsSource $source
|
2017-01-09 05:58:06 +01:00
|
|
|
* @param string $fq_interface_name
|
2016-10-15 06:12:57 +02:00
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function __construct(PhpParser\Node\Stmt\Interface_ $interface, StatementsSource $source, $fq_interface_name)
|
2016-08-08 20:36:18 +02:00
|
|
|
{
|
2017-01-09 05:58:06 +01:00
|
|
|
parent::__construct($interface, $source, $fq_interface_name);
|
2016-08-13 20:20:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
/**
|
2017-11-09 05:32:22 +01:00
|
|
|
* @param ProjectChecker $project_checker
|
|
|
|
* @param string $fq_interface_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-05-25 04:07:49 +02:00
|
|
|
* @return bool
|
2016-10-15 06:12:57 +02:00
|
|
|
*/
|
2017-07-29 21:05:06 +02:00
|
|
|
public static function interfaceExists(ProjectChecker $project_checker, $fq_interface_name)
|
2016-08-13 20:20:46 +02:00
|
|
|
{
|
2017-01-09 07:48:55 +01:00
|
|
|
if (isset(self::$SPECIAL_TYPES[strtolower($fq_interface_name)])) {
|
2016-08-14 00:54:49 +02:00
|
|
|
return false;
|
2016-08-13 20:20:46 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
return $project_checker->hasFullyQualifiedInterfaceName($fq_interface_name);
|
2016-05-16 05:06:03 +02:00
|
|
|
}
|
2016-08-14 00:54:49 +02:00
|
|
|
|
2016-10-15 06:12:57 +02:00
|
|
|
/**
|
2017-11-09 05:32:22 +01:00
|
|
|
* @param ProjectChecker $project_checker
|
|
|
|
* @param string $fq_interface_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-05-25 04:07:49 +02:00
|
|
|
* @return bool
|
2016-10-15 06:12:57 +02:00
|
|
|
*/
|
2017-07-29 21:05:06 +02:00
|
|
|
public static function hasCorrectCasing(ProjectChecker $project_checker, $fq_interface_name)
|
2016-08-14 00:54:49 +02:00
|
|
|
{
|
2017-07-29 21:05:06 +02:00
|
|
|
return isset($project_checker->existing_interfaces[$fq_interface_name]);
|
2016-08-14 00:54:49 +02:00
|
|
|
}
|
2016-08-15 17:01:50 +02:00
|
|
|
|
2016-10-30 17:46:18 +01:00
|
|
|
/**
|
2017-11-09 05:32:22 +01:00
|
|
|
* @param ProjectChecker $project_checker
|
|
|
|
* @param string $interface_name
|
|
|
|
* @param string $possible_parent
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-05-25 04:07:49 +02:00
|
|
|
* @return bool
|
2016-10-30 17:46:18 +01:00
|
|
|
*/
|
2017-07-29 21:05:06 +02:00
|
|
|
public static function interfaceExtends(ProjectChecker $project_checker, $interface_name, $possible_parent)
|
2016-10-25 17:20:06 +02:00
|
|
|
{
|
2017-07-29 21:05:06 +02:00
|
|
|
return in_array($possible_parent, self::getParentInterfaces($project_checker, $interface_name), true);
|
2016-10-25 17:20:06 +02:00
|
|
|
}
|
|
|
|
|
2016-10-25 00:49:07 +02:00
|
|
|
/**
|
2017-11-09 05:32:22 +01:00
|
|
|
* @param ProjectChecker $project_checker
|
|
|
|
* @param string $fq_interface_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-10-25 00:49:07 +02:00
|
|
|
* @return array<string> all interfaces extended by $interface_name
|
|
|
|
*/
|
2017-07-29 21:05:06 +02:00
|
|
|
public static function getParentInterfaces(ProjectChecker $project_checker, $fq_interface_name)
|
2016-10-25 00:49:07 +02:00
|
|
|
{
|
2017-01-09 05:58:06 +01:00
|
|
|
$fq_interface_name = strtolower($fq_interface_name);
|
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
$storage = $project_checker->classlike_storage_provider->get($fq_interface_name);
|
2016-10-25 00:49:07 +02:00
|
|
|
|
2017-07-29 21:05:06 +02:00
|
|
|
return $storage->parent_interfaces;
|
2016-10-25 00:49:07 +02:00
|
|
|
}
|
2016-05-16 05:06:03 +02:00
|
|
|
}
|