2018-02-04 00:52:35 +01:00
|
|
|
<?php
|
2018-11-12 16:46:55 +01:00
|
|
|
namespace Psalm\Internal\Codebase;
|
2018-02-04 00:52:35 +01:00
|
|
|
|
2018-10-07 02:11:19 +02:00
|
|
|
use PhpParser;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Analyzer\FileAnalyzer;
|
|
|
|
use Psalm\Internal\Analyzer\ProjectAnalyzer;
|
2018-02-04 00:52:35 +01:00
|
|
|
use Psalm\Config;
|
2018-11-12 16:46:55 +01:00
|
|
|
use Psalm\FileManipulation;
|
|
|
|
use Psalm\Internal\FileManipulation\FileManipulationBuffer;
|
|
|
|
use Psalm\Internal\FileManipulation\FunctionDocblockManipulator;
|
2018-02-04 00:52:35 +01:00
|
|
|
use Psalm\IssueBuffer;
|
2018-11-06 03:57:36 +01:00
|
|
|
use Psalm\Internal\Provider\ClassLikeStorageProvider;
|
|
|
|
use Psalm\Internal\Provider\FileProvider;
|
|
|
|
use Psalm\Internal\Provider\FileReferenceProvider;
|
|
|
|
use Psalm\Internal\Provider\FileStorageProvider;
|
2018-02-04 00:52:35 +01:00
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
|
|
|
* @psalm-type IssueData = array{
|
2018-09-26 22:33:59 +02:00
|
|
|
* severity: string,
|
|
|
|
* line_from: int,
|
|
|
|
* line_to: int,
|
|
|
|
* type: string,
|
|
|
|
* message: string,
|
|
|
|
* file_name: string,
|
|
|
|
* file_path: string,
|
|
|
|
* snippet: string,
|
|
|
|
* from: int,
|
|
|
|
* to: int,
|
|
|
|
* snippet_from: int,
|
|
|
|
* snippet_to: int,
|
|
|
|
* column_from: int,
|
|
|
|
* column_to: int
|
|
|
|
* }
|
|
|
|
*
|
2018-10-26 22:17:15 +02:00
|
|
|
* @psalm-type TaggedCodeType = array<int, array{0: int, 1: string}>
|
|
|
|
*
|
2018-09-26 22:33:59 +02:00
|
|
|
* @psalm-type WorkerData = array{
|
|
|
|
* issues: array<int, IssueData>,
|
|
|
|
* file_references: array<string, array<string,bool>>,
|
|
|
|
* mixed_counts: array<string, array{0: int, 1: int}>,
|
|
|
|
* method_references: array<string, array<string,bool>>,
|
2018-11-02 02:52:39 +01:00
|
|
|
* analyzed_methods: array<string, array<string, int>>,
|
2018-10-26 22:17:15 +02:00
|
|
|
* file_maps: array<
|
|
|
|
* string,
|
|
|
|
* array{0: TaggedCodeType, 1: TaggedCodeType}
|
|
|
|
* >
|
2018-09-26 22:33:59 +02:00
|
|
|
* }
|
2018-09-26 00:37:24 +02:00
|
|
|
*/
|
|
|
|
|
2018-02-09 23:51:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
* Called in the analysis phase of Psalm's execution
|
|
|
|
*/
|
2018-02-04 00:52:35 +01:00
|
|
|
class Analyzer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Config
|
|
|
|
*/
|
|
|
|
private $config;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var FileProvider
|
|
|
|
*/
|
|
|
|
private $file_provider;
|
|
|
|
|
2018-06-04 00:31:43 +02:00
|
|
|
/**
|
|
|
|
* @var FileStorageProvider
|
|
|
|
*/
|
|
|
|
private $file_storage_provider;
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $debug_output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to store counts of mixed vs non-mixed variables
|
|
|
|
*
|
|
|
|
* @var array<string, array{0: int, 1: int}
|
|
|
|
*/
|
|
|
|
private $mixed_counts = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $count_mixed = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We analyze more files than we necessarily report errors in
|
|
|
|
*
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
private $files_to_analyze = [];
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
2018-10-07 04:58:21 +02:00
|
|
|
* @var array<string, array<string, int>>
|
2018-09-26 00:37:24 +02:00
|
|
|
*/
|
2018-11-02 02:52:39 +01:00
|
|
|
private $analyzed_methods = [];
|
2018-09-26 00:37:24 +02:00
|
|
|
|
2018-09-26 22:33:59 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, array<int, IssueData>>
|
|
|
|
*/
|
|
|
|
private $existing_issues = [];
|
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
/**
|
|
|
|
* @var array<string, array<int, array{0: int, 1: string}>>
|
|
|
|
*/
|
|
|
|
private $reference_map = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array<string, array<int, array{0: int, 1: string}>>
|
|
|
|
*/
|
|
|
|
private $type_map = [];
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
/**
|
|
|
|
* @param bool $debug_output
|
|
|
|
*/
|
2018-06-04 00:31:43 +02:00
|
|
|
public function __construct(
|
|
|
|
Config $config,
|
|
|
|
FileProvider $file_provider,
|
|
|
|
FileStorageProvider $file_storage_provider,
|
|
|
|
$debug_output
|
|
|
|
) {
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->config = $config;
|
|
|
|
$this->file_provider = $file_provider;
|
2018-06-04 00:31:43 +02:00
|
|
|
$this->file_storage_provider = $file_storage_provider;
|
2018-02-04 00:52:35 +01:00
|
|
|
$this->debug_output = $debug_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, string> $files_to_analyze
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addFiles(array $files_to_analyze)
|
|
|
|
{
|
|
|
|
$this->files_to_analyze += $files_to_analyze;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canReportIssues($file_path)
|
|
|
|
{
|
|
|
|
return isset($this->files_to_analyze[$file_path]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
2019-01-02 15:00:45 +01:00
|
|
|
* @param array<string, class-string<FileAnalyzer>> $filetype_analyzers
|
2018-02-04 00:52:35 +01:00
|
|
|
*
|
2018-11-06 03:57:36 +01:00
|
|
|
* @return FileAnalyzer
|
2018-02-12 02:56:34 +01:00
|
|
|
*
|
|
|
|
* @psalm-suppress MixedOperand
|
2018-02-04 00:52:35 +01:00
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
private function getFileAnalyzer(ProjectAnalyzer $project_analyzer, $file_path, array $filetype_analyzers)
|
2018-02-04 00:52:35 +01:00
|
|
|
{
|
2018-10-19 19:13:55 +02:00
|
|
|
$extension = (string) (pathinfo($file_path)['extension'] ?? '');
|
2018-02-04 00:52:35 +01:00
|
|
|
|
|
|
|
$file_name = $this->config->shortenFileName($file_path);
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
if (isset($filetype_analyzers[$extension])) {
|
|
|
|
$file_analyzer = new $filetype_analyzers[$extension]($project_analyzer, $file_path, $file_name);
|
2018-02-04 00:52:35 +01:00
|
|
|
} else {
|
2018-11-11 18:01:14 +01:00
|
|
|
$file_analyzer = new FileAnalyzer($project_analyzer, $file_path, $file_name);
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->debug_output) {
|
2018-04-13 01:42:24 +02:00
|
|
|
echo 'Getting ' . $file_path . "\n";
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
return $file_analyzer;
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-11 18:01:14 +01:00
|
|
|
* @param ProjectAnalyzer $project_analyzer
|
2018-02-04 00:52:35 +01:00
|
|
|
* @param int $pool_size
|
|
|
|
* @param bool $alter_code
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public function analyzeFiles(ProjectAnalyzer $project_analyzer, $pool_size, $alter_code)
|
2018-02-04 00:52:35 +01:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->loadCachedResults($project_analyzer);
|
2018-09-26 22:33:59 +02:00
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$filetype_analyzers = $this->config->getFiletypeAnalyzers();
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase = $project_analyzer->getCodebase();
|
2018-02-04 00:52:35 +01:00
|
|
|
|
|
|
|
$analysis_worker =
|
|
|
|
/**
|
2018-02-27 17:39:26 +01:00
|
|
|
* @param int $_
|
2018-02-04 00:52:35 +01:00
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
function ($_, $file_path) use ($project_analyzer, $filetype_analyzers) {
|
|
|
|
$file_analyzer = $this->getFileAnalyzer($project_analyzer, $file_path, $filetype_analyzers);
|
2018-02-04 00:52:35 +01:00
|
|
|
|
|
|
|
if ($this->debug_output) {
|
2018-11-11 18:01:14 +01:00
|
|
|
echo 'Analyzing ' . $file_analyzer->getFilePath() . "\n";
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$file_analyzer->analyze(null);
|
2018-02-04 00:52:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if ($pool_size > 1 && count($this->files_to_analyze) > $pool_size) {
|
|
|
|
$process_file_paths = [];
|
|
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
foreach ($this->files_to_analyze as $file_path) {
|
|
|
|
$process_file_paths[$i % $pool_size][] = $file_path;
|
|
|
|
++$i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run analysis one file at a time, splitting the set of
|
|
|
|
// files up among a given number of child processes.
|
2018-11-06 03:57:36 +01:00
|
|
|
$pool = new \Psalm\Internal\Fork\Pool(
|
2018-02-04 00:52:35 +01:00
|
|
|
$process_file_paths,
|
|
|
|
/** @return void */
|
|
|
|
function () {
|
|
|
|
},
|
|
|
|
$analysis_worker,
|
2018-09-26 22:33:59 +02:00
|
|
|
/** @return WorkerData */
|
2018-02-04 00:52:35 +01:00
|
|
|
function () {
|
2018-11-11 18:01:14 +01:00
|
|
|
$project_analyzer = ProjectAnalyzer::getInstance();
|
|
|
|
$codebase = $project_analyzer->getCodebase();
|
2018-11-06 03:57:36 +01:00
|
|
|
$analyzer = $codebase->analyzer;
|
|
|
|
$file_reference_provider = $codebase->file_reference_provider;
|
2018-09-26 00:37:24 +02:00
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
return [
|
|
|
|
'issues' => IssueBuffer::getIssuesData(),
|
2018-09-28 22:18:45 +02:00
|
|
|
'file_references' => $file_reference_provider->getAllFileReferences(),
|
|
|
|
'method_references' => $file_reference_provider->getClassMethodReferences(),
|
2018-09-26 00:37:24 +02:00
|
|
|
'mixed_counts' => $analyzer->getMixedCounts(),
|
2018-11-02 02:52:39 +01:00
|
|
|
'analyzed_methods' => $analyzer->getAnalyzedMethods(),
|
2018-10-26 22:17:15 +02:00
|
|
|
'file_maps' => $analyzer->getFileMaps(),
|
2018-02-04 00:52:35 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
// Wait for all tasks to complete and collect the results.
|
|
|
|
/**
|
2018-09-26 22:33:59 +02:00
|
|
|
* @var array<int, WorkerData>
|
2018-02-04 00:52:35 +01:00
|
|
|
*/
|
|
|
|
$forked_pool_data = $pool->wait();
|
|
|
|
|
|
|
|
foreach ($forked_pool_data as $pool_data) {
|
|
|
|
IssueBuffer::addIssues($pool_data['issues']);
|
2018-09-26 22:33:59 +02:00
|
|
|
|
|
|
|
foreach ($pool_data['issues'] as $issue_data) {
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->addIssue($issue_data['file_path'], $issue_data);
|
2018-09-26 22:33:59 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->addFileReferences($pool_data['file_references']);
|
|
|
|
$codebase->file_reference_provider->addClassMethodReferences($pool_data['method_references']);
|
2018-11-02 02:52:39 +01:00
|
|
|
$this->analyzed_methods = array_merge($pool_data['analyzed_methods'], $this->analyzed_methods);
|
2018-02-04 00:52:35 +01:00
|
|
|
|
|
|
|
foreach ($pool_data['mixed_counts'] as $file_path => list($mixed_count, $nonmixed_count)) {
|
|
|
|
if (!isset($this->mixed_counts[$file_path])) {
|
|
|
|
$this->mixed_counts[$file_path] = [$mixed_count, $nonmixed_count];
|
|
|
|
} else {
|
|
|
|
$this->mixed_counts[$file_path][0] += $mixed_count;
|
|
|
|
$this->mixed_counts[$file_path][1] += $nonmixed_count;
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
foreach ($pool_data['file_maps'] as $file_path => list($reference_map, $type_map)) {
|
|
|
|
$this->reference_map[$file_path] = $reference_map;
|
|
|
|
$this->type_map[$file_path] = $type_map;
|
|
|
|
}
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
2018-10-15 23:40:42 +02:00
|
|
|
if ($pool->didHaveError()) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2018-02-04 00:52:35 +01:00
|
|
|
} else {
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
foreach ($this->files_to_analyze as $file_path => $_) {
|
|
|
|
$analysis_worker($i, $file_path);
|
|
|
|
++$i;
|
|
|
|
}
|
2018-09-26 22:33:59 +02:00
|
|
|
|
|
|
|
foreach (IssueBuffer::getIssuesData() as $issue_data) {
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->addIssue($issue_data['file_path'], $issue_data);
|
2018-09-26 22:33:59 +02:00
|
|
|
}
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase = $project_analyzer->getCodebase();
|
2018-11-06 03:57:36 +01:00
|
|
|
$scanned_files = $codebase->scanner->getScannedFiles();
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->setAnalyzedMethods($this->analyzed_methods);
|
|
|
|
$codebase->file_reference_provider->setFileMaps($this->getFileMaps());
|
|
|
|
$codebase->file_reference_provider->updateReferenceCache($codebase, $scanned_files);
|
2018-10-07 02:11:19 +02:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
if ($codebase->diff_methods) {
|
|
|
|
$codebase->statements_provider->resetDiffs();
|
2018-09-26 00:37:24 +02:00
|
|
|
}
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
if ($alter_code) {
|
|
|
|
foreach ($this->files_to_analyze as $file_path) {
|
2018-11-11 18:01:14 +01:00
|
|
|
$this->updateFile($file_path, $project_analyzer->dry_run, true);
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-11 18:01:14 +01:00
|
|
|
public function loadCachedResults(ProjectAnalyzer $project_analyzer)
|
2018-09-28 22:18:45 +02:00
|
|
|
{
|
2018-11-11 18:01:14 +01:00
|
|
|
$codebase = $project_analyzer->getCodebase();
|
2018-11-06 03:57:36 +01:00
|
|
|
if ($codebase->diff_methods
|
|
|
|
&& (!$codebase->collect_references || $codebase->server_mode)
|
2018-09-28 22:18:45 +02:00
|
|
|
) {
|
2018-11-11 18:19:53 +01:00
|
|
|
$this->analyzed_methods = $codebase->file_reference_provider->getAnalyzedMethods();
|
|
|
|
$this->existing_issues = $codebase->file_reference_provider->getExistingIssues();
|
|
|
|
$file_maps = $codebase->file_reference_provider->getFileMaps();
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
foreach ($file_maps as $file_path => list($reference_map, $type_map)) {
|
|
|
|
$this->reference_map[$file_path] = $reference_map;
|
|
|
|
$this->type_map[$file_path] = $type_map;
|
|
|
|
}
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
$statements_provider = $codebase->statements_provider;
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
$changed_members = $statements_provider->getChangedMembers();
|
2018-10-04 05:52:01 +02:00
|
|
|
$unchanged_signature_members = $statements_provider->getUnchangedSignatureMembers();
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
$diff_map = $statements_provider->getDiffMap();
|
|
|
|
|
2018-11-11 18:19:53 +01:00
|
|
|
$all_referencing_methods = $codebase->file_reference_provider->getMethodsReferencing();
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
$classlikes = $codebase->classlikes;
|
2018-10-18 15:51:28 +02:00
|
|
|
|
2018-10-03 19:58:32 +02:00
|
|
|
foreach ($all_referencing_methods as $member_id => $referencing_method_ids) {
|
2018-10-03 23:11:08 +02:00
|
|
|
$member_class_name = preg_replace('/::.*$/', '', $member_id);
|
|
|
|
|
2018-10-18 15:51:28 +02:00
|
|
|
if ($classlikes->hasFullyQualifiedClassLikeName($member_class_name)
|
|
|
|
&& !$classlikes->hasFullyQualifiedTraitName($member_class_name)
|
|
|
|
) {
|
2018-10-03 23:11:08 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$member_stub = $member_class_name . '::*';
|
2018-10-03 19:58:32 +02:00
|
|
|
|
|
|
|
if (!isset($all_referencing_methods[$member_stub])) {
|
|
|
|
$all_referencing_methods[$member_stub] = $referencing_method_ids;
|
|
|
|
} else {
|
|
|
|
$all_referencing_methods[$member_stub] += $referencing_method_ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
$newly_invalidated_methods = [];
|
|
|
|
|
2018-10-04 05:52:01 +02:00
|
|
|
foreach ($unchanged_signature_members as $file_unchanged_signature_members) {
|
|
|
|
$newly_invalidated_methods = array_merge($newly_invalidated_methods, $file_unchanged_signature_members);
|
2018-10-07 04:58:21 +02:00
|
|
|
|
|
|
|
foreach ($file_unchanged_signature_members as $unchanged_signature_member_id => $_) {
|
|
|
|
// also check for things that might invalidate constructor property initialisation
|
|
|
|
if (isset($all_referencing_methods[$unchanged_signature_member_id])) {
|
|
|
|
foreach ($all_referencing_methods[$unchanged_signature_member_id] as $referencing_method_id => $_) {
|
|
|
|
if (substr($referencing_method_id, -13) === '::__construct') {
|
|
|
|
$newly_invalidated_methods[$referencing_method_id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-04 05:52:01 +02:00
|
|
|
}
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
foreach ($changed_members as $file_changed_members) {
|
|
|
|
foreach ($file_changed_members as $member_id => $_) {
|
2018-10-04 00:16:33 +02:00
|
|
|
$newly_invalidated_methods[$member_id] = true;
|
|
|
|
|
2018-09-28 22:18:45 +02:00
|
|
|
if (isset($all_referencing_methods[$member_id])) {
|
2018-10-03 19:58:32 +02:00
|
|
|
$newly_invalidated_methods = array_merge(
|
|
|
|
$all_referencing_methods[$member_id],
|
|
|
|
$newly_invalidated_methods
|
|
|
|
);
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
2018-10-03 23:11:08 +02:00
|
|
|
|
|
|
|
$member_stub = preg_replace('/::.*$/', '::*', $member_id);
|
|
|
|
|
|
|
|
if (isset($all_referencing_methods[$member_stub])) {
|
|
|
|
$newly_invalidated_methods = array_merge(
|
|
|
|
$all_referencing_methods[$member_stub],
|
|
|
|
$newly_invalidated_methods
|
|
|
|
);
|
|
|
|
}
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-02 02:52:39 +01:00
|
|
|
foreach ($this->analyzed_methods as $file_path => $analyzed_methods) {
|
|
|
|
foreach ($analyzed_methods as $correct_method_id => $_) {
|
2018-10-04 00:16:33 +02:00
|
|
|
$trait_safe_method_id = $correct_method_id;
|
2018-10-03 19:58:32 +02:00
|
|
|
|
2018-10-04 00:16:33 +02:00
|
|
|
$correct_method_ids = explode('&', $correct_method_id);
|
|
|
|
|
|
|
|
$correct_method_id = $correct_method_ids[0];
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-10-04 00:16:33 +02:00
|
|
|
if (isset($newly_invalidated_methods[$correct_method_id])
|
|
|
|
|| (isset($correct_method_ids[1])
|
|
|
|
&& isset($newly_invalidated_methods[$correct_method_ids[1]]))
|
2018-09-28 22:18:45 +02:00
|
|
|
) {
|
2018-11-02 02:52:39 +01:00
|
|
|
unset($this->analyzed_methods[$file_path][$trait_safe_method_id]);
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 02:11:19 +02:00
|
|
|
$this->shiftFileOffsets($diff_map);
|
|
|
|
|
|
|
|
foreach ($this->files_to_analyze as $file_path) {
|
2018-11-11 18:19:53 +01:00
|
|
|
$codebase->file_reference_provider->clearExistingIssuesForFile($file_path);
|
|
|
|
$codebase->file_reference_provider->clearExistingFileMapsForFile($file_path);
|
2018-10-07 02:11:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string, array<int, array{0: int, 1: int, 2: int, 3: int}>> $diff_map
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function shiftFileOffsets(array $diff_map)
|
|
|
|
{
|
2018-09-28 22:18:45 +02:00
|
|
|
foreach ($this->existing_issues as $file_path => &$file_issues) {
|
2018-11-02 02:52:39 +01:00
|
|
|
if (!isset($this->analyzed_methods[$file_path])) {
|
2018-09-28 22:18:45 +02:00
|
|
|
unset($this->existing_issues[$file_path]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-30 05:51:06 +02:00
|
|
|
$file_diff_map = $diff_map[$file_path] ?? [];
|
2018-09-28 22:18:45 +02:00
|
|
|
|
|
|
|
if (!$file_diff_map) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$first_diff_offset = $file_diff_map[0][0];
|
|
|
|
$last_diff_offset = $file_diff_map[count($file_diff_map) - 1][1];
|
|
|
|
|
|
|
|
foreach ($file_issues as $i => &$issue_data) {
|
|
|
|
if ($issue_data['to'] < $first_diff_offset || $issue_data['from'] > $last_diff_offset) {
|
2019-01-08 06:54:48 +01:00
|
|
|
unset($file_issues[$i]);
|
2018-09-28 22:18:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($file_diff_map as list($from, $to, $file_offset, $line_offset)) {
|
|
|
|
if ($issue_data['from'] >= $from && $issue_data['from'] <= $to) {
|
2018-10-26 22:17:15 +02:00
|
|
|
$issue_data['from'] += $file_offset;
|
|
|
|
$issue_data['to'] += $file_offset;
|
|
|
|
$issue_data['snippet_from'] += $file_offset;
|
|
|
|
$issue_data['snippet_to'] += $file_offset;
|
|
|
|
$issue_data['line_from'] += $line_offset;
|
|
|
|
$issue_data['line_to'] += $line_offset;
|
2019-01-08 06:54:48 +01:00
|
|
|
} else {
|
|
|
|
unset($file_issues[$i]);
|
2018-10-26 22:17:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->reference_map as $file_path => &$reference_map) {
|
2018-11-02 02:52:39 +01:00
|
|
|
if (!isset($this->analyzed_methods[$file_path])) {
|
2018-10-26 22:17:15 +02:00
|
|
|
unset($this->reference_map[$file_path]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_diff_map = $diff_map[$file_path] ?? [];
|
|
|
|
|
|
|
|
if (!$file_diff_map) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$first_diff_offset = $file_diff_map[0][0];
|
|
|
|
$last_diff_offset = $file_diff_map[count($file_diff_map) - 1][1];
|
|
|
|
|
|
|
|
foreach ($reference_map as $reference_from => list($reference_to, $tag)) {
|
|
|
|
if ($reference_to < $first_diff_offset || $reference_from > $last_diff_offset) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($file_diff_map as list($from, $to, $file_offset)) {
|
|
|
|
if ($reference_from >= $from && $reference_from <= $to) {
|
|
|
|
unset($reference_map[$reference_from]);
|
|
|
|
$reference_map[$reference_from += $file_offset] = [
|
|
|
|
$reference_to += $file_offset,
|
|
|
|
$tag
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->type_map as $file_path => &$type_map) {
|
2018-11-02 02:52:39 +01:00
|
|
|
if (!isset($this->analyzed_methods[$file_path])) {
|
2018-10-26 22:17:15 +02:00
|
|
|
unset($this->type_map[$file_path]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$file_diff_map = $diff_map[$file_path] ?? [];
|
|
|
|
|
|
|
|
if (!$file_diff_map) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$first_diff_offset = $file_diff_map[0][0];
|
|
|
|
$last_diff_offset = $file_diff_map[count($file_diff_map) - 1][1];
|
2018-09-28 22:18:45 +02:00
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
foreach ($type_map as $type_from => list($type_to, $tag)) {
|
|
|
|
if ($type_to < $first_diff_offset || $type_from > $last_diff_offset) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($file_diff_map as list($from, $to, $file_offset)) {
|
|
|
|
if ($type_from >= $from && $type_from <= $to) {
|
|
|
|
unset($type_map[$type_from]);
|
|
|
|
$type_map[$type_from += $file_offset] = [
|
|
|
|
$type_to += $file_offset,
|
|
|
|
$tag
|
|
|
|
];
|
2018-09-28 22:18:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:26:07 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return array{0:int, 1:int}
|
|
|
|
*/
|
|
|
|
public function getMixedCountsForFile($file_path)
|
|
|
|
{
|
|
|
|
if (!isset($this->mixed_counts[$file_path])) {
|
|
|
|
$this->mixed_counts[$file_path] = [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->mixed_counts[$file_path];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param array{0:int, 1:int} $mixed_counts
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setMixedCountsForFile($file_path, array $mixed_counts)
|
|
|
|
{
|
|
|
|
$this->mixed_counts[$file_path] = $mixed_counts;
|
|
|
|
}
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function incrementMixedCount($file_path)
|
|
|
|
{
|
|
|
|
if (!$this->count_mixed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->mixed_counts[$file_path])) {
|
|
|
|
$this->mixed_counts[$file_path] = [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++$this->mixed_counts[$file_path][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function incrementNonMixedCount($file_path)
|
|
|
|
{
|
|
|
|
if (!$this->count_mixed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isset($this->mixed_counts[$file_path])) {
|
|
|
|
$this->mixed_counts[$file_path] = [0, 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
++$this->mixed_counts[$file_path][1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array<string, array{0: int, 1: int}>
|
|
|
|
*/
|
|
|
|
public function getMixedCounts()
|
|
|
|
{
|
|
|
|
return $this->mixed_counts;
|
|
|
|
}
|
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addNodeType(string $file_path, PhpParser\Node $node, string $node_type)
|
|
|
|
{
|
|
|
|
$this->type_map[$file_path][(int)$node->getAttribute('startFilePos')] = [
|
|
|
|
(int)$node->getAttribute('endFilePos'),
|
|
|
|
$node_type
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addNodeReference(string $file_path, PhpParser\Node $node, string $reference)
|
|
|
|
{
|
|
|
|
$this->reference_map[$file_path][(int)$node->getAttribute('startFilePos')] = [
|
|
|
|
(int)$node->getAttribute('endFilePos'),
|
|
|
|
$reference
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addOffsetReference(string $file_path, int $start, int $end, string $reference)
|
|
|
|
{
|
|
|
|
$this->reference_map[$file_path][$start] = [
|
|
|
|
$end,
|
|
|
|
$reference
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
/**
|
2018-06-04 00:34:25 +02:00
|
|
|
* @return string
|
2018-02-04 00:52:35 +01:00
|
|
|
*/
|
2018-06-04 00:31:43 +02:00
|
|
|
public function getTypeInferenceSummary()
|
2018-02-04 00:52:35 +01:00
|
|
|
{
|
|
|
|
$mixed_count = 0;
|
|
|
|
$nonmixed_count = 0;
|
|
|
|
|
2018-06-04 00:31:43 +02:00
|
|
|
$all_deep_scanned_files = [];
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
foreach ($this->files_to_analyze as $file_path => $_) {
|
2018-06-04 00:31:43 +02:00
|
|
|
$all_deep_scanned_files[$file_path] = true;
|
|
|
|
|
|
|
|
foreach ($this->file_storage_provider->get($file_path)->required_file_paths as $required_file_path) {
|
|
|
|
$all_deep_scanned_files[$required_file_path] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($all_deep_scanned_files as $file_path => $_) {
|
2018-08-24 23:46:13 +02:00
|
|
|
if (!$this->config->reportTypeStatsForFile($file_path)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
if (isset($this->mixed_counts[$file_path])) {
|
|
|
|
list($path_mixed_count, $path_nonmixed_count) = $this->mixed_counts[$file_path];
|
|
|
|
$mixed_count += $path_mixed_count;
|
|
|
|
$nonmixed_count += $path_nonmixed_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$total = $mixed_count + $nonmixed_count;
|
|
|
|
|
2018-06-04 00:31:43 +02:00
|
|
|
$total_files = count($all_deep_scanned_files);
|
|
|
|
|
|
|
|
if (!$total_files) {
|
|
|
|
return 'No files analyzed';
|
|
|
|
}
|
|
|
|
|
2018-06-27 19:41:50 +02:00
|
|
|
if (!$total) {
|
|
|
|
return 'Psalm was unable to infer types in any of '
|
|
|
|
. $total_files . ' file' . ($total_files > 1 ? 's' : '');
|
|
|
|
}
|
|
|
|
|
2018-06-04 00:34:25 +02:00
|
|
|
return 'Psalm was able to infer types for ' . number_format(100 * $nonmixed_count / $total, 3) . '%'
|
2018-06-04 00:31:43 +02:00
|
|
|
. ' of analyzed code (' . $total_files . ' file' . ($total_files > 1 ? 's' : '') . ')';
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getNonMixedStats()
|
|
|
|
{
|
|
|
|
$stats = '';
|
|
|
|
|
2018-06-04 00:31:43 +02:00
|
|
|
$all_deep_scanned_files = [];
|
|
|
|
|
2018-02-04 00:52:35 +01:00
|
|
|
foreach ($this->files_to_analyze as $file_path => $_) {
|
2018-06-04 00:31:43 +02:00
|
|
|
$all_deep_scanned_files[$file_path] = true;
|
|
|
|
|
2018-08-24 23:46:13 +02:00
|
|
|
if (!$this->config->reportTypeStatsForFile($file_path)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-04 00:31:43 +02:00
|
|
|
foreach ($this->file_storage_provider->get($file_path)->required_file_paths as $required_file_path) {
|
|
|
|
$all_deep_scanned_files[$required_file_path] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($all_deep_scanned_files as $file_path => $_) {
|
2018-02-04 00:52:35 +01:00
|
|
|
if (isset($this->mixed_counts[$file_path])) {
|
|
|
|
list($path_mixed_count, $path_nonmixed_count) = $this->mixed_counts[$file_path];
|
|
|
|
$stats .= number_format(100 * $path_nonmixed_count / ($path_mixed_count + $path_nonmixed_count), 0)
|
|
|
|
. '% ' . $this->config->shortenFileName($file_path)
|
2018-04-13 01:42:24 +02:00
|
|
|
. ' (' . $path_mixed_count . ' mixed)' . "\n";
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function disableMixedCounts()
|
|
|
|
{
|
|
|
|
$this->count_mixed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function enableMixedCounts()
|
|
|
|
{
|
|
|
|
$this->count_mixed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param bool $dry_run
|
|
|
|
* @param bool $output_changes to console
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updateFile($file_path, $dry_run, $output_changes = false)
|
|
|
|
{
|
|
|
|
$new_return_type_manipulations = FunctionDocblockManipulator::getManipulationsForFile($file_path);
|
|
|
|
|
|
|
|
$other_manipulations = FileManipulationBuffer::getForFile($file_path);
|
|
|
|
|
|
|
|
$file_manipulations = array_merge($new_return_type_manipulations, $other_manipulations);
|
|
|
|
|
|
|
|
usort(
|
|
|
|
$file_manipulations,
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function (FileManipulation $a, FileManipulation $b) {
|
|
|
|
if ($a->start === $b->start) {
|
|
|
|
if ($b->end === $a->end) {
|
|
|
|
return $b->insertion_text > $a->insertion_text ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $b->end > $a->end ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $b->start > $a->start ? 1 : -1;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$docblock_update_count = count($file_manipulations);
|
|
|
|
|
|
|
|
$existing_contents = $this->file_provider->getContents($file_path);
|
|
|
|
|
|
|
|
foreach ($file_manipulations as $manipulation) {
|
|
|
|
$existing_contents
|
|
|
|
= substr($existing_contents, 0, $manipulation->start)
|
|
|
|
. $manipulation->insertion_text
|
|
|
|
. substr($existing_contents, $manipulation->end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($docblock_update_count) {
|
|
|
|
if ($dry_run) {
|
2018-04-13 01:42:24 +02:00
|
|
|
echo $file_path . ':' . "\n";
|
2018-02-04 00:52:35 +01:00
|
|
|
|
|
|
|
$differ = new \PhpCsFixer\Diff\v2_0\Differ(
|
|
|
|
new \PhpCsFixer\Diff\GeckoPackages\DiffOutputBuilder\UnifiedDiffOutputBuilder([
|
|
|
|
'fromFile' => 'Original',
|
|
|
|
'toFile' => 'New',
|
|
|
|
])
|
|
|
|
);
|
|
|
|
|
|
|
|
echo (string) $differ->diff($this->file_provider->getContents($file_path), $existing_contents);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($output_changes) {
|
2018-04-13 01:42:24 +02:00
|
|
|
echo 'Altering ' . $file_path . "\n";
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->file_provider->setContents($file_path, $existing_contents);
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 00:37:24 +02:00
|
|
|
|
2018-09-26 22:33:59 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param int $start
|
|
|
|
* @param int $end
|
|
|
|
*
|
|
|
|
* @return array<int, IssueData>
|
|
|
|
*/
|
|
|
|
public function getExistingIssuesForFile($file_path, $start, $end)
|
|
|
|
{
|
|
|
|
if (!isset($this->existing_issues[$file_path])) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$applicable_issues = [];
|
|
|
|
|
|
|
|
foreach ($this->existing_issues[$file_path] as $issue_data) {
|
|
|
|
if ($issue_data['from'] >= $start && $issue_data['from'] <= $end) {
|
|
|
|
$applicable_issues[] = $issue_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $applicable_issues;
|
|
|
|
}
|
|
|
|
|
2018-10-26 06:59:14 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param int $start
|
|
|
|
* @param int $end
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function removeExistingDataForFile($file_path, $start, $end)
|
|
|
|
{
|
|
|
|
if (isset($this->existing_issues[$file_path])) {
|
|
|
|
foreach ($this->existing_issues[$file_path] as $i => $issue_data) {
|
|
|
|
if ($issue_data['from'] >= $start && $issue_data['from'] <= $end) {
|
|
|
|
unset($this->existing_issues[$file_path][$i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 22:17:15 +02:00
|
|
|
|
|
|
|
if (isset($this->type_map[$file_path])) {
|
|
|
|
foreach ($this->type_map[$file_path] as $map_start => $_) {
|
|
|
|
if ($map_start >= $start && $map_start <= $end) {
|
|
|
|
unset($this->type_map[$file_path][$map_start]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->reference_map[$file_path])) {
|
|
|
|
foreach ($this->reference_map[$file_path] as $map_start => $_) {
|
|
|
|
if ($map_start >= $start && $map_start <= $end) {
|
|
|
|
unset($this->reference_map[$file_path][$map_start]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-26 06:59:14 +02:00
|
|
|
}
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
2018-10-07 04:58:21 +02:00
|
|
|
* @return array<string, array<string, int>>
|
2018-09-26 00:37:24 +02:00
|
|
|
*/
|
2018-11-02 02:52:39 +01:00
|
|
|
public function getAnalyzedMethods()
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
2018-11-02 02:52:39 +01:00
|
|
|
return $this->analyzed_methods;
|
2018-09-26 00:37:24 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 22:17:15 +02:00
|
|
|
/**
|
|
|
|
* @return array<string, array{0: TaggedCodeType, 1: TaggedCodeType}>
|
|
|
|
*/
|
|
|
|
public function getFileMaps()
|
|
|
|
{
|
|
|
|
$file_maps = [];
|
|
|
|
|
|
|
|
foreach ($this->reference_map as $file_path => $reference_map) {
|
|
|
|
$file_maps[$file_path] = [$reference_map, []];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->type_map as $file_path => $type_map) {
|
|
|
|
if (isset($file_maps[$file_path])) {
|
|
|
|
$file_maps[$file_path][1] = $type_map;
|
|
|
|
} else {
|
|
|
|
$file_maps[$file_path] = [[], $type_map];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $file_maps;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array{0: array<int, array{0: int, 1: string}>, 1: array<int, array{0: int, 1: string}>}
|
|
|
|
*/
|
|
|
|
public function getMapsForFile(string $file_path)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
$this->reference_map[$file_path] ?? [],
|
|
|
|
$this->type_map[$file_path] ?? []
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param string $method_id
|
2018-10-07 04:58:21 +02:00
|
|
|
* @param bool $is_constructor
|
2018-09-26 00:37:24 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-11-02 02:52:39 +01:00
|
|
|
public function setAnalyzedMethod($file_path, $method_id, $is_constructor = false)
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
2018-11-02 02:52:39 +01:00
|
|
|
$this->analyzed_methods[$file_path][$method_id] = $is_constructor ? 2 : 1;
|
2018-09-26 00:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param string $method_id
|
2018-10-07 04:58:21 +02:00
|
|
|
* @param bool $is_constructor
|
|
|
|
*
|
2018-09-26 00:37:24 +02:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-11-02 02:52:39 +01:00
|
|
|
public function isMethodAlreadyAnalyzed($file_path, $method_id, $is_constructor = false)
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
2018-10-07 04:58:21 +02:00
|
|
|
if ($is_constructor) {
|
2018-11-02 02:52:39 +01:00
|
|
|
return isset($this->analyzed_methods[$file_path][$method_id])
|
|
|
|
&& $this->analyzed_methods[$file_path][$method_id] === 2;
|
2018-10-07 04:58:21 +02:00
|
|
|
}
|
|
|
|
|
2018-11-02 02:52:39 +01:00
|
|
|
return isset($this->analyzed_methods[$file_path][$method_id]);
|
2018-09-26 00:37:24 +02:00
|
|
|
}
|
2018-02-04 00:52:35 +01:00
|
|
|
}
|