Skip to content
Permalink
Browse files

Fix a couple of tests, and track file references to classes

  • Loading branch information...
muglug committed Apr 28, 2019
1 parent 2ae0f92 commit b4f24d1fa6cd92f70471315342fed8ef7124581f
@@ -257,6 +257,7 @@ function () {
$file_reference_provider = $codebase->file_reference_provider;
$file_reference_provider->setFileReferencesToClasses([]);
$file_reference_provider->setCallingMethodReferencesToClassMembers([]);
$file_reference_provider->setFileReferencesToClassMembers([]);
$file_reference_provider->setCallingMethodReferencesToMissingClassMembers([]);
@@ -446,6 +447,8 @@ public function loadCachedResults(ProjectAnalyzer $project_analyzer)
$all_referencing_methods = $method_references_to_class_members + $method_references_to_missing_class_members;
$file_references_to_classes = $file_reference_provider->getAllFileReferencesToClasses();
$file_references_to_class_members
= $file_reference_provider->getAllFileReferencesToClassMembers();
$file_references_to_missing_class_members
@@ -511,6 +514,11 @@ public function loadCachedResults(ProjectAnalyzer $project_analyzer)
$member_stub = preg_replace('/::.*$/', '::*', $member_id);
if (strpos($member_id, '::')) {
$fqcln = explode('::', $member_id)[0];
unset($file_references_to_classes[$fqcln]);
}
if (isset($all_referencing_methods[$member_stub])) {
$newly_invalidated_methods = array_merge(
$all_referencing_methods[$member_stub],
@@ -563,6 +571,10 @@ public function loadCachedResults(ProjectAnalyzer $project_analyzer)
unset($referencing_file_paths[$file_path]);
}
foreach ($file_references_to_classes as &$referencing_file_paths) {
unset($referencing_file_paths[$file_path]);
}
foreach ($references_to_mixed_member_names as &$references) {
unset($references[$file_path]);
}
@@ -607,6 +619,13 @@ function (array $a) : bool {
}
);
$file_references_to_classes = array_filter(
$file_references_to_classes,
function (array $a) : bool {
return !!$a;
}
);
$file_reference_provider->setCallingMethodReferencesToClassMembers(
$method_references_to_class_members
);
@@ -626,6 +645,10 @@ function (array $a) : bool {
$file_reference_provider->setReferencesToMixedMemberNames(
$references_to_mixed_member_names
);
$file_reference_provider->setFileReferencesToClasses(
$file_references_to_classes
);
}
/**
@@ -594,6 +594,17 @@ public function isClassReferenced(string $fq_class_name_lc) : bool
return isset(self::$file_references_to_classes[$fq_class_name_lc]);
}
/**
* @param array<string, array<string,bool>> $references
* @psalm-suppress MixedTypeCoercion
*
* @return void
*/
public function setFileReferencesToClasses(array $references)
{
self::$file_references_to_classes = $references;
}
/**
* @return array<string, array<int, CodeLocation>>
*/
@@ -646,6 +646,25 @@ public function foo() : void {}
],
'error_message' => 'DuplicateMethod',
],
'unusedClassReferencedInFile' => [
'file_stages' => [
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {}
$a = new A();',
],
[
getcwd() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'A.php' => '<?php
namespace Foo;
class A {}',
],
],
'error_message' => 'UnusedClass',
],
'unusedMethodReferencedInFile' => [
'file_stages' => [
[
@@ -664,7 +683,9 @@ public function foo() : void {}
class A {
public function foo() : void {}
}',
}
$a = new A();',
],
],
'error_message' => 'PossiblyUnusedMethod',
@@ -697,6 +718,7 @@ public function foo() : void {}
class B {
public function bar() : void {
new A();
}
}
@@ -725,7 +747,9 @@ class A {
class A {
/** @var string */
public $foo = "hello";
}',
}
$a = new A();',
],
],
'error_message' => 'PossiblyUnusedProperty',
@@ -760,6 +784,7 @@ class A {
class B {
public function bar() : void {
new A();
}
}
@@ -10,6 +10,9 @@ class FakeFileReferenceCacheProvider extends \Psalm\Internal\Provider\FileRefere
/** @var ?array */
private $cached_file_references;
/** @var ?array */
private $cached_file_class_references;
/** @var ?array */
private $cached_method_member_references;
@@ -50,6 +53,17 @@ public function getCachedFileReferences()
return $this->cached_file_references;
}
/**
* @return ?array
*
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedTypeCoercion
*/
public function getCachedFileClassReferences()
{
return $this->cached_file_class_references;
}
/**
* @return ?array
*
@@ -124,6 +138,14 @@ public function setCachedFileReferences(array $file_references)
$this->cached_file_references = $file_references;
}
/**
* @return void
*/
public function setCachedFileClassReferences(array $file_references)
{
$this->cached_file_class_references = $file_references;
}
/**
* @return void
*/

0 comments on commit b4f24d1

Please sign in to comment.
You can’t perform that action at this time.