Skip to content

Commit

Permalink
Fix #30 by consolidating properties into single storage array
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 2, 2017
1 parent 65282ea commit 3eb902d
Show file tree
Hide file tree
Showing 15 changed files with 1,061 additions and 720 deletions.
60 changes: 13 additions & 47 deletions src/Psalm/Checker/ClassChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ class ClassChecker extends ClassLikeChecker
*/
protected $class;

/**
* A lookup table of existing classes
*
* @var array<string, bool>
*/
protected static $existing_classes = [];

/**
* A lookup table of existing classes, all lowercased
*
* @var array<string, bool>
*/
protected static $existing_classes_ci = [];

/**
* A lookup table used for caching the results of classExtends calls
*
* @var array<string, array<string, bool>>
*/
protected static $class_extends = [];

/**
* @var integer
*/
Expand Down Expand Up @@ -59,14 +38,14 @@ public function __construct(PhpParser\Node\Stmt\ClassLike $class, StatementsSour
self::$existing_classes[$fq_class_name] = true;
self::$existing_classes_ci[strtolower($fq_class_name)] = true;

self::$class_extends[$this->fq_class_name] = [];

if ($this->class->extends) {
$this->parent_class = self::getFQCLNFromNameObject(
$this->class->extends,
$this->namespace,
$this->aliased_classes
);

self::$class_extends[$this->fq_class_name][$this->parent_class] = true;
}

foreach ($class->implements as $interface_name) {
Expand Down Expand Up @@ -100,27 +79,19 @@ public static function classExists($fq_class_name)
return true;
}

$old_level = error_reporting();
error_reporting(0);
$class_exists = class_exists($fq_class_name);
error_reporting($old_level);

if ($class_exists) {
$old_level = error_reporting();
error_reporting(0);
$reflected_class = new \ReflectionClass($fq_class_name);
error_reporting($old_level);

self::$existing_classes_ci[strtolower($fq_class_name)] = true;
self::$existing_classes[$reflected_class->getName()] = true;
if (parent::registerClassLike($fq_class_name) === false) {
self::$existing_classes[$fq_class_name] = false;

return true;
return false;
}

// we can only be sure that the case-sensitive version does not exist
self::$existing_classes[$fq_class_name] = false;
if (!isset(self::$existing_classes_ci[strtolower($fq_class_name)])) {
// it exists, but it's not a class
self::$existing_classes_ci[strtolower($fq_class_name)] = false;
return false;
}

return false;
return true;
}

/**
Expand Down Expand Up @@ -179,7 +150,7 @@ public static function classExtends($fq_class_name, $possible_parent)
*/
public static function getInterfacesForClass($fq_class_name)
{
self::registerClass($fq_class_name);
self::registerClassLike($fq_class_name);

return self::$storage[$fq_class_name]->class_implements;
}
Expand All @@ -203,7 +174,7 @@ public static function classImplements($fq_class_name, $interface)
return false;
}

if (self::registerClass($fq_class_name) === false) {
if (self::registerClassLike($fq_class_name) === false) {
return false;
}

Expand All @@ -217,11 +188,6 @@ public static function classImplements($fq_class_name, $interface)
*/
public static function clearCache()
{
self::$existing_classes = [];
self::$existing_classes_ci = [];

self::$class_extends = [];

self::$anonymous_class_count = 0;

MethodChecker::clearCache();
Expand Down

0 comments on commit 3eb902d

Please sign in to comment.