2016-01-08 00:28:27 +01:00
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Analyzer;
|
2016-01-08 00:28:27 +01:00
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
use PhpParser;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Codebase;
|
2016-08-13 20:20:46 +02:00
|
|
|
use Psalm\Context;
|
2018-08-07 19:17:23 +02:00
|
|
|
use Psalm\Exception\UnpreparedAnalysisException;
|
2018-11-12 16:46:55 +01:00
|
|
|
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
|
2017-05-19 06:48:26 +02:00
|
|
|
use Psalm\IssueBuffer;
|
2016-11-02 07:29:00 +01:00
|
|
|
use Psalm\StatementsSource;
|
2017-01-02 21:31:18 +01:00
|
|
|
use Psalm\Type;
|
2016-08-13 20:20:46 +02:00
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
class FileAnalyzer extends SourceAnalyzer implements StatementsSource
|
2016-01-08 00:28:27 +01:00
|
|
|
{
|
2017-01-07 20:35:07 +01:00
|
|
|
use CanAlias;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $file_name;
|
|
|
|
|
2016-10-14 06:53:43 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-12-04 01:11:30 +01:00
|
|
|
protected $file_path;
|
2016-10-14 06:53:43 +02:00
|
|
|
|
2017-01-07 20:35:07 +01:00
|
|
|
/**
|
2018-05-30 22:19:18 +02:00
|
|
|
* @var string|null
|
2018-05-23 05:38:27 +02:00
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
protected $root_file_path;
|
2018-05-23 05:38:27 +02:00
|
|
|
|
|
|
|
/**
|
2018-05-30 22:19:18 +02:00
|
|
|
* @var string|null
|
2017-01-07 20:35:07 +01:00
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
protected $root_file_name;
|
2017-01-07 20:35:07 +01:00
|
|
|
|
|
|
|
/**
|
2018-05-23 05:38:27 +02:00
|
|
|
* @var array<string, bool>
|
2017-01-07 20:35:07 +01:00
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
private $required_file_paths = [];
|
2017-01-07 20:35:07 +01:00
|
|
|
|
2018-05-30 22:19:18 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, bool>
|
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
private $parent_file_paths = [];
|
2018-05-30 22:19:18 +02:00
|
|
|
|
2017-01-07 20:35:07 +01:00
|
|
|
/**
|
2017-10-27 00:19:19 +02:00
|
|
|
* @var array<int, string>
|
2017-01-07 20:35:07 +01:00
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
private $suppressed_issues = [];
|
2017-01-07 20:35:07 +01:00
|
|
|
|
2016-11-13 00:51:48 +01:00
|
|
|
/**
|
|
|
|
* @var array<string, array<string, string>>
|
2016-10-31 20:42:20 +01:00
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
private $namespace_aliased_classes = [];
|
2016-02-18 21:05:13 +01:00
|
|
|
|
2016-11-13 00:51:48 +01:00
|
|
|
/**
|
|
|
|
* @var array<string, array<string, string>>
|
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
private $namespace_aliased_classes_flipped = [];
|
2016-11-13 00:51:48 +01:00
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
/**
|
2018-11-06 03:57:36 +01:00
|
|
|
* @var array<string, InterfaceAnalyzer>
|
2017-01-02 21:31:18 +01:00
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
public $interface_analyzers_to_analyze = [];
|
2017-01-02 21:31:18 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-06 03:57:36 +01:00
|
|
|
* @var array<string, ClassAnalyzer>
|
2017-01-02 21:31:18 +01:00
|
|
|
*/
|
2018-11-18 17:39:14 +01:00
|
|
|
public $class_analyzers_to_analyze = [];
|
2017-01-02 21:31:18 +01:00
|
|
|
|
|
|
|
/**
|
2018-01-28 22:52:57 +01:00
|
|
|
* @var null|Context
|
2017-01-02 21:31:18 +01:00
|
|
|
*/
|
2017-01-12 06:54:41 +01:00
|
|
|
public $context;
|
2017-01-02 21:31:18 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-06 03:57:36 +01:00
|
|
|
* @var ProjectAnalyzer
|
2017-01-02 21:31:18 +01:00
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public $project_analyzer;
|
2017-01-02 21:31:18 +01:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
/**
|
|
|
|
* @var Codebase
|
|
|
|
*/
|
|
|
|
public $codebase;
|
|
|
|
|
2016-12-31 00:08:07 +01:00
|
|
|
/**
|
2018-01-21 18:44:46 +01:00
|
|
|
* @param string $file_path
|
|
|
|
* @param string $file_name
|
2016-10-14 06:53:43 +02:00
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public function __construct(ProjectAnalyzer $project_analyzer, $file_path, $file_name)
|
2018-01-21 18:44:46 +01:00
|
|
|
{
|
2018-11-06 03:57:36 +01:00
|
|
|
$this->source = $this;
|
2016-12-31 00:08:07 +01:00
|
|
|
$this->file_path = $file_path;
|
2018-01-21 18:44:46 +01:00
|
|
|
$this->file_name = $file_name;
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer = $project_analyzer;
|
|
|
|
$this->codebase = $project_analyzer->getCodebase();
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2016-12-28 18:59:51 +01:00
|
|
|
|
2018-11-18 17:39:14 +01:00
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
/** @psalm-suppress PossiblyNullPropertyAssignmentValue */
|
|
|
|
$this->source = null;
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
2018-11-11 18:01:14 +01:00
|
|
|
* @param bool $preserve_analyzers
|
2017-07-25 22:11:02 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-10-17 21:52:26 +02:00
|
|
|
public function analyze(
|
|
|
|
Context $file_context = null,
|
2018-11-11 18:01:14 +01:00
|
|
|
$preserve_analyzers = false,
|
2018-10-17 21:52:26 +02:00
|
|
|
Context $global_context = null
|
|
|
|
) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase = $this->project_analyzer->getCodebase();
|
2018-02-21 19:54:11 +01:00
|
|
|
|
|
|
|
$file_storage = $codebase->file_storage_provider->get($this->file_path);
|
|
|
|
|
2018-10-17 21:52:26 +02:00
|
|
|
if (!$file_storage->deep_scan && !$codebase->server_mode) {
|
2018-08-07 19:17:23 +02:00
|
|
|
throw new UnpreparedAnalysisException('File ' . $this->file_path . ' has not been properly scanned');
|
2018-02-21 19:54:11 +01:00
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($file_context) {
|
|
|
|
$this->context = $file_context;
|
|
|
|
}
|
2017-02-01 01:21:33 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
if (!$this->context) {
|
|
|
|
$this->context = new Context();
|
2018-01-21 19:38:51 +01:00
|
|
|
$this->context->collect_references = $codebase->collect_references;
|
2017-07-25 22:11:02 +02:00
|
|
|
}
|
2016-11-02 07:29:00 +01:00
|
|
|
|
2018-08-29 21:10:56 +02:00
|
|
|
if ($codebase->config->useStrictTypesForFile($this->file_path)) {
|
|
|
|
$this->context->strict_types = true;
|
|
|
|
}
|
|
|
|
|
2017-12-06 06:56:00 +01:00
|
|
|
$this->context->is_global = true;
|
|
|
|
|
2018-10-17 21:52:26 +02:00
|
|
|
try {
|
|
|
|
$stmts = $codebase->getStatementsForFile($this->file_path);
|
|
|
|
} catch (PhpParser\Error $e) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-02 07:29:00 +01:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$statements_analyzer = new StatementsAnalyzer($this);
|
2017-01-02 21:31:18 +01:00
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$leftover_stmts = $this->populateCheckers($stmts);
|
2016-07-24 23:06:54 +02:00
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
// if there are any leftover statements, evaluate them,
|
|
|
|
// in turn causing the classes/interfaces be evaluated
|
|
|
|
if ($leftover_stmts) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$statements_analyzer->analyze($leftover_stmts, $this->context, $global_context, true);
|
2016-12-28 18:59:51 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
// check any leftover interfaces not already evaluated
|
2018-11-11 18:01:14 +01:00
|
|
|
foreach ($this->interface_analyzers_to_analyze as $interface_analyzer) {
|
|
|
|
$interface_analyzer->analyze();
|
2016-12-28 18:59:51 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 21:31:18 +01:00
|
|
|
// check any leftover classes not already evaluated
|
2018-10-17 21:52:26 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
foreach ($this->class_analyzers_to_analyze as $class_analyzer) {
|
|
|
|
$class_analyzer->analyze(null, $this->context);
|
2016-08-05 21:11:20 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if (!$preserve_analyzers) {
|
|
|
|
$this->class_analyzers_to_analyze = [];
|
2018-11-18 17:39:14 +01:00
|
|
|
$this->interface_analyzers_to_analyze = [];
|
2017-01-12 03:37:53 +01:00
|
|
|
}
|
2016-01-08 00:28:27 +01:00
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
/**
|
2018-04-17 18:16:25 +02:00
|
|
|
* @param array<int, PhpParser\Node\Stmt> $stmts
|
2017-07-25 22:11:02 +02:00
|
|
|
*
|
2018-04-17 18:16:25 +02:00
|
|
|
* @return array<int, PhpParser\Node\Stmt>
|
2017-07-25 22:11:02 +02:00
|
|
|
*/
|
|
|
|
public function populateCheckers(array $stmts)
|
|
|
|
{
|
|
|
|
$leftover_stmts = [];
|
|
|
|
|
|
|
|
foreach ($stmts as $stmt) {
|
2017-10-20 01:19:29 +02:00
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\ClassLike) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$this->populateClassLikeAnalyzers($stmt);
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\Namespace_) {
|
|
|
|
$namespace_name = $stmt->name ? implode('\\', $stmt->name->parts) : '';
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$namespace_analyzer = new NamespaceAnalyzer($stmt, $this);
|
|
|
|
$namespace_analyzer->collectAnalyzableInformation();
|
2017-07-25 22:11:02 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->namespace_aliased_classes[$namespace_name] = $namespace_analyzer->getAliases()->uses;
|
2017-07-25 22:11:02 +02:00
|
|
|
$this->namespace_aliased_classes_flipped[$namespace_name] =
|
2018-11-11 18:01:14 +01:00
|
|
|
$namespace_analyzer->getAliasedClassesFlipped();
|
2017-07-25 22:11:02 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\Use_) {
|
|
|
|
$this->visitUse($stmt);
|
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\GroupUse) {
|
|
|
|
$this->visitGroupUse($stmt);
|
2018-02-25 16:43:54 +01:00
|
|
|
} else {
|
2017-10-20 01:19:29 +02:00
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\If_) {
|
|
|
|
foreach ($stmt->stmts as $if_stmt) {
|
|
|
|
if ($if_stmt instanceof PhpParser\Node\Stmt\ClassLike) {
|
2018-11-06 03:57:36 +01:00
|
|
|
$this->populateClassLikeAnalyzers($if_stmt);
|
2017-10-20 01:19:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
$leftover_stmts[] = $stmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $leftover_stmts;
|
|
|
|
}
|
|
|
|
|
2017-10-20 01:19:29 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-06 03:57:36 +01:00
|
|
|
private function populateClassLikeAnalyzers(PhpParser\Node\Stmt\ClassLike $stmt)
|
2017-10-20 01:19:29 +02:00
|
|
|
{
|
|
|
|
if (!$stmt->name) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($stmt instanceof PhpParser\Node\Stmt\Class_) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$class_analyzer = new ClassAnalyzer($stmt, $this, $stmt->name->name);
|
2017-10-20 01:19:29 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$fq_class_name = $class_analyzer->getFQCLN();
|
2017-10-20 01:19:29 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->class_analyzers_to_analyze[strtolower($fq_class_name)] = $class_analyzer;
|
2017-10-20 01:19:29 +02:00
|
|
|
} elseif ($stmt instanceof PhpParser\Node\Stmt\Interface_) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$class_analyzer = new InterfaceAnalyzer($stmt, $this, $stmt->name->name);
|
2017-10-20 01:19:29 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$fq_class_name = $class_analyzer->getFQCLN();
|
2017-10-20 01:19:29 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->interface_analyzers_to_analyze[$fq_class_name] = $class_analyzer;
|
2017-10-20 01:19:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 00:11:00 +01:00
|
|
|
/**
|
|
|
|
* @param string $fq_class_name
|
2018-11-11 18:01:14 +01:00
|
|
|
* @param ClassAnalyzer $class_analyzer
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-02 00:11:00 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public function addNamespacedClassAnalyzer($fq_class_name, ClassAnalyzer $class_analyzer)
|
2017-02-02 00:11:00 +01:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->class_analyzers_to_analyze[strtolower($fq_class_name)] = $class_analyzer;
|
2017-02-02 00:11:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fq_class_name
|
2018-11-11 18:01:14 +01:00
|
|
|
* @param InterfaceAnalyzer $interface_analyzer
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-02 00:11:00 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public function addNamespacedInterfaceAnalyzer($fq_class_name, InterfaceAnalyzer $interface_analyzer)
|
2017-02-02 00:11:00 +01:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->interface_analyzers_to_analyze[strtolower($fq_class_name)] = $interface_analyzer;
|
2017-02-02 00:11:00 +01:00
|
|
|
}
|
|
|
|
|
2017-01-12 03:37:53 +01:00
|
|
|
/**
|
2017-01-12 06:54:41 +01:00
|
|
|
* @param string $method_id
|
2017-01-12 03:37:53 +01:00
|
|
|
* @param Context $this_context
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-01-12 03:37:53 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function getMethodMutations($method_id, Context $this_context)
|
2017-01-12 03:37:53 +01:00
|
|
|
{
|
2017-01-12 06:54:41 +01:00
|
|
|
list($fq_class_name, $method_name) = explode('::', $method_id);
|
2017-06-30 07:24:45 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if (isset($this->class_analyzers_to_analyze[strtolower($fq_class_name)])) {
|
|
|
|
$class_analyzer_to_examine = $this->class_analyzers_to_analyze[strtolower($fq_class_name)];
|
2017-07-25 22:11:02 +02:00
|
|
|
} else {
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->project_analyzer->getMethodMutations($method_id, $this_context);
|
2017-06-30 07:24:45 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$call_context = new Context($this_context->self);
|
2017-01-12 03:37:53 +01:00
|
|
|
$call_context->collect_mutations = true;
|
2018-01-24 19:38:53 +01:00
|
|
|
$call_context->collect_initializations = $this_context->collect_initializations;
|
|
|
|
$call_context->initialized_methods = $this_context->initialized_methods;
|
2017-06-30 07:24:45 +02:00
|
|
|
$call_context->include_location = $this_context->include_location;
|
2017-01-12 03:37:53 +01:00
|
|
|
|
2018-01-28 18:01:51 +01:00
|
|
|
foreach ($this_context->vars_possibly_in_scope as $var => $_) {
|
2017-01-12 03:37:53 +01:00
|
|
|
if (strpos($var, '$this->') === 0) {
|
|
|
|
$call_context->vars_possibly_in_scope[$var] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this_context->vars_in_scope as $var => $type) {
|
|
|
|
if (strpos($var, '$this->') === 0) {
|
|
|
|
$call_context->vars_in_scope[$var] = $type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$call_context->vars_in_scope['$this'] = $this_context->vars_in_scope['$this'];
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$class_analyzer_to_examine->getMethodMutations($method_name, $call_context);
|
2017-01-12 06:54:41 +01:00
|
|
|
|
2017-01-19 05:19:36 +01:00
|
|
|
foreach ($call_context->vars_possibly_in_scope as $var => $_) {
|
2017-01-12 03:37:53 +01:00
|
|
|
$this_context->vars_possibly_in_scope[$var] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($call_context->vars_in_scope as $var => $type) {
|
|
|
|
$this_context->vars_in_scope[$var] = $type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-27 00:42:48 +02:00
|
|
|
/**
|
2018-01-28 23:07:09 +01:00
|
|
|
* @return null|string
|
2016-04-27 00:42:48 +02:00
|
|
|
*/
|
2016-01-20 00:27:06 +01:00
|
|
|
public function getNamespace()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-11-13 00:51:48 +01:00
|
|
|
/**
|
|
|
|
* @param string|null $namespace_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2016-11-13 00:51:48 +01:00
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
|
|
|
public function getAliasedClassesFlipped($namespace_name = null)
|
|
|
|
{
|
|
|
|
if ($namespace_name && isset($this->namespace_aliased_classes_flipped[$namespace_name])) {
|
|
|
|
return $this->namespace_aliased_classes_flipped[$namespace_name];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->aliased_classes_flipped;
|
|
|
|
}
|
|
|
|
|
2016-11-02 07:29:00 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-08-10 07:09:47 +02:00
|
|
|
public static function clearCache()
|
2016-03-23 18:05:25 +01:00
|
|
|
{
|
2016-12-08 21:57:18 +01:00
|
|
|
IssueBuffer::clearCache();
|
2018-01-06 01:49:27 +01:00
|
|
|
FileManipulationBuffer::clearCache();
|
2018-11-06 03:57:36 +01:00
|
|
|
FunctionLikeAnalyzer::clearCache();
|
|
|
|
\Psalm\Internal\Provider\ClassLikeStorageProvider::deleteAll();
|
|
|
|
\Psalm\Internal\Provider\FileStorageProvider::deleteAll();
|
|
|
|
\Psalm\Internal\Provider\FileReferenceProvider::clearCache();
|
2016-05-10 20:00:44 +02:00
|
|
|
}
|
2016-11-06 05:59:29 +01:00
|
|
|
|
2017-01-07 20:35:07 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
|
|
|
return $this->file_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilePath()
|
|
|
|
{
|
|
|
|
return $this->file_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function getRootFileName()
|
2017-01-07 20:35:07 +01:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return $this->root_file_name ?: $this->file_name;
|
2017-01-07 20:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function getRootFilePath()
|
2017-01-07 20:35:07 +01:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return $this->root_file_path ?: $this->file_path;
|
2018-05-23 05:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param string $file_name
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function setRootFilePath($file_path, $file_name)
|
2018-05-23 05:38:27 +02:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
$this->root_file_name = $file_name;
|
|
|
|
$this->root_file_path = $file_path;
|
2018-05-23 05:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function addRequiredFilePath($file_path)
|
2018-05-23 05:38:27 +02:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
$this->required_file_paths[$file_path] = true;
|
|
|
|
}
|
2018-05-23 05:38:27 +02:00
|
|
|
|
2018-05-30 22:19:18 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addParentFilePath($file_path)
|
|
|
|
{
|
|
|
|
$this->parent_file_paths[$file_path] = true;
|
2018-05-23 05:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function hasParentFilePath($file_path)
|
2018-05-23 05:38:27 +02:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return $this->file_path === $file_path || isset($this->parent_file_paths[$file_path]);
|
2018-05-23 05:38:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function hasAlreadyRequiredFilePath($file_path)
|
2018-05-23 05:38:27 +02:00
|
|
|
{
|
2018-05-30 18:23:53 +02:00
|
|
|
return isset($this->required_file_paths[$file_path]);
|
2018-05-23 05:38:27 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 22:19:18 +02:00
|
|
|
/**
|
|
|
|
* @return array<int, string>
|
|
|
|
*/
|
|
|
|
public function getRequiredFilePaths()
|
|
|
|
{
|
|
|
|
return array_keys($this->required_file_paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<int, string>
|
|
|
|
*/
|
|
|
|
public function getParentFilePaths()
|
|
|
|
{
|
|
|
|
return array_keys($this->parent_file_paths);
|
|
|
|
}
|
|
|
|
|
2018-05-23 05:38:27 +02:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2018-05-30 22:19:18 +02:00
|
|
|
public function getRequireNesting()
|
2018-05-23 05:38:27 +02:00
|
|
|
{
|
2018-05-30 22:19:18 +02:00
|
|
|
return count($this->parent_file_paths);
|
2017-01-07 20:35:07 +01:00
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @return array<int, string>
|
|
|
|
*/
|
2017-01-07 20:35:07 +01:00
|
|
|
public function getSuppressedIssues()
|
|
|
|
{
|
|
|
|
return $this->suppressed_issues;
|
|
|
|
}
|
|
|
|
|
2017-10-27 00:19:19 +02:00
|
|
|
/**
|
|
|
|
* @param array<int, string> $new_issues
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addSuppressedIssues(array $new_issues)
|
|
|
|
{
|
|
|
|
$this->suppressed_issues = array_merge($new_issues, $this->suppressed_issues);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<int, string> $new_issues
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function removeSuppressedIssues(array $new_issues)
|
|
|
|
{
|
|
|
|
$this->suppressed_issues = array_diff($this->suppressed_issues, $new_issues);
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
2018-01-28 23:07:09 +01:00
|
|
|
* @return null|string
|
2017-11-26 22:03:17 +01:00
|
|
|
*/
|
2017-01-07 20:35:07 +01:00
|
|
|
public function getFQCLN()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
2018-01-28 23:07:09 +01:00
|
|
|
* @return null|string
|
2017-11-26 22:03:17 +01:00
|
|
|
*/
|
2017-01-09 06:26:40 +01:00
|
|
|
public function getClassName()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-12-18 05:29:27 +01:00
|
|
|
/**
|
|
|
|
* @return null|array<string, Type\Union>
|
|
|
|
*/
|
|
|
|
public function getTemplateTypeMap()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-11-26 22:03:17 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-01-07 20:35:07 +01:00
|
|
|
public function isStatic()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-20 04:30:20 +01:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
public function getFileAnalyzer() : FileAnalyzer
|
2017-03-20 04:30:20 +01:00
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
2018-11-06 03:57:36 +01:00
|
|
|
|
|
|
|
public function getProjectAnalyzer() : ProjectAnalyzer
|
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
return $this->project_analyzer;
|
2018-11-06 03:57:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCodebase() : Codebase
|
|
|
|
{
|
|
|
|
return $this->codebase;
|
|
|
|
}
|
2016-01-08 00:28:27 +01:00
|
|
|
}
|