2016-05-16 05:06:03 +02:00
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Analyzer;
|
2016-05-16 05:06:03 +02:00
|
|
|
|
|
|
|
use PhpParser;
|
2018-01-14 19:08:24 +01:00
|
|
|
use Psalm\CodeLocation;
|
2019-03-07 17:16:40 +01:00
|
|
|
use Psalm\Issue\UndefinedInterface;
|
2016-05-16 05:06:03 +02:00
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
class InterfaceAnalyzer extends ClassLikeAnalyzer
|
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
|
2017-01-09 05:58:06 +01:00
|
|
|
* @param string $fq_interface_name
|
2016-10-15 06:12:57 +02:00
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
public function __construct(PhpParser\Node\Stmt\Interface_ $interface, SourceAnalyzer $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
|
|
|
}
|
|
|
|
|
2018-01-14 19:08:24 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function analyze()
|
|
|
|
{
|
|
|
|
if (!$this->class instanceof PhpParser\Node\Stmt\Interface_) {
|
|
|
|
throw new \LogicException('Something went badly wrong');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->class->extends) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$project_analyzer = $this->file_analyzer->project_analyzer;
|
|
|
|
$codebase = $project_analyzer->getCodebase();
|
2018-11-02 04:40:36 +01:00
|
|
|
|
2018-01-14 19:08:24 +01:00
|
|
|
foreach ($this->class->extends as $extended_interface) {
|
|
|
|
$extended_interface_name = self::getFQCLNFromNameObject(
|
|
|
|
$extended_interface,
|
|
|
|
$this->getAliases()
|
|
|
|
);
|
|
|
|
|
|
|
|
$parent_reference_location = new CodeLocation($this, $extended_interface);
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
if (!$codebase->classOrInterfaceExists(
|
2018-01-14 19:08:24 +01:00
|
|
|
$extended_interface_name,
|
|
|
|
$parent_reference_location
|
|
|
|
)) {
|
|
|
|
// we should not normally get here
|
|
|
|
return;
|
|
|
|
}
|
2018-11-02 04:40:36 +01:00
|
|
|
|
2019-03-07 17:16:40 +01:00
|
|
|
try {
|
|
|
|
$extended_interface_storage = $codebase->classlike_storage_provider->get($extended_interface_name);
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$extended_interface_storage->is_interface) {
|
|
|
|
$code_location = new CodeLocation(
|
|
|
|
$this,
|
|
|
|
$extended_interface
|
|
|
|
);
|
|
|
|
|
|
|
|
if (\Psalm\IssueBuffer::accepts(
|
|
|
|
new UndefinedInterface(
|
|
|
|
$extended_interface_name . ' is not an interface',
|
|
|
|
$code_location
|
|
|
|
),
|
|
|
|
$this->getSuppressedIssues()
|
|
|
|
)) {
|
|
|
|
// fall through
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:33:25 +01:00
|
|
|
if ($codebase->store_node_types && $extended_interface_name) {
|
2018-11-02 04:40:36 +01:00
|
|
|
$bounds = $parent_reference_location->getSelectionBounds();
|
|
|
|
|
|
|
|
$codebase->analyzer->addOffsetReference(
|
|
|
|
$this->getFilePath(),
|
|
|
|
$bounds[0],
|
|
|
|
$bounds[1],
|
|
|
|
$extended_interface_name
|
|
|
|
);
|
|
|
|
}
|
2018-01-14 19:08:24 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 18:19:51 +01:00
|
|
|
|
|
|
|
foreach ($this->class->stmts as $stmt) {
|
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\ClassMethod) {
|
|
|
|
$method_analyzer = new MethodAnalyzer($stmt, $this);
|
|
|
|
|
|
|
|
$method_analyzer->analyze(new \Psalm\Context($this->getFQCLN()));
|
|
|
|
}
|
|
|
|
}
|
2018-01-14 19:08:24 +01:00
|
|
|
}
|
2016-05-16 05:06:03 +02:00
|
|
|
}
|