Merge pull request #7670 from kinglozzer/dataobject-schema-ancestry

FIX: Remove some unnecessary ClassInfo calls in DataObjectSchema
This commit is contained in:
Damian Mooyman 2017-12-06 11:02:49 +13:00 committed by GitHub
commit 01b48e2dd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -138,11 +138,11 @@ class DataObjectSchema
*/ */
public function baseDataClass($class) public function baseDataClass($class)
{ {
$class = ClassInfo::class_name($class);
$current = $class; $current = $class;
while ($next = get_parent_class($current)) { while ($next = get_parent_class($current)) {
if ($next === DataObject::class) { if ($next === DataObject::class) {
return $current; // Only use ClassInfo::class_name() to format the class if we've not used get_parent_class()
return ($current === $class) ? ClassInfo::class_name($current) : $current;
} }
$current = $next; $current = $next;
} }
@ -201,6 +201,11 @@ class DataObjectSchema
$db = []; $db = [];
$classes = $uninherited ? [$class] : ClassInfo::ancestry($class); $classes = $uninherited ? [$class] : ClassInfo::ancestry($class);
foreach ($classes as $tableClass) { foreach ($classes as $tableClass) {
// Skip irrelevant parent classes
if (!is_subclass_of($tableClass, DataObject::class)) {
continue;
}
// Find all fields on this class // Find all fields on this class
$fields = $this->databaseFields($tableClass, false); $fields = $this->databaseFields($tableClass, false);
// Merge with composite fields // Merge with composite fields
@ -394,6 +399,10 @@ class DataObjectSchema
*/ */
public function classHasTable($class) public function classHasTable($class)
{ {
if (!is_subclass_of($class, DataObject::class)) {
return false;
}
$fields = $this->databaseFields($class, false); $fields = $this->databaseFields($class, false);
return !empty($fields); return !empty($fields);
} }

View File

@ -1341,10 +1341,7 @@ class DataObjectTest extends SapphireTest
$this->assertFalse($schema->classHasTable(DataObject::class)); $this->assertFalse($schema->classHasTable(DataObject::class));
$this->assertFalse($schema->classHasTable(ViewableData::class)); $this->assertFalse($schema->classHasTable(ViewableData::class));
// Invalid class /* Invalid class name */
$this->expectException(ReflectionException::class);
$this->expectExceptionMessage('Class ThisIsntADataObject does not exist');
$this->assertFalse($schema->classHasTable("ThisIsntADataObject")); $this->assertFalse($schema->classHasTable("ThisIsntADataObject"));
} }