FIX: Remove some unnecessary ClassInfo calls in DataObjectSchema

This commit is contained in:
Loz Calver 2017-12-01 16:17:44 +00:00
parent d57dea0318
commit 91bd92df31
2 changed files with 12 additions and 6 deletions

View File

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

View File

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