Code clean up and reformat.

This commit is contained in:
James Cole
2014-11-12 22:37:09 +01:00
parent 258d6a1688
commit 4aa9a04516
33 changed files with 1543 additions and 1611 deletions

View File

@@ -10,18 +10,18 @@ use LaravelBook\Ardent\Ardent;
*/
abstract class SingleTableInheritanceEntity extends Ardent
{
/**
* The field that stores the subclass
*
* @var string
*/
protected $subclassField = null;
/**
* must be overridden and set to true in subclasses
*
* @var bool
*/
protected $isSubclass = false;
/**
* The field that stores the subclass
*
* @var string
*/
protected $subclassField = null;
/**
* @param array $attributes
@@ -36,24 +36,6 @@ abstract class SingleTableInheritanceEntity extends Ardent
return $instance;
}
/**
* if no subclass is defined, function as normal
*
* @param array $attributes
*
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function mapData(array $attributes)
{
if (!$this->subclassField) {
return $this->newInstance();
}
return new $attributes[$this->subclassField];
}
/**
*
* instead of using $this->newInstance(), call
@@ -86,14 +68,6 @@ abstract class SingleTableInheritanceEntity extends Ardent
return $builder;
}
/**
* @return bool
*/
public function isSubclass()
{
return $this->isSubclass;
}
/**
* ensure that the subclass field is assigned on save
*
@@ -106,11 +80,7 @@ abstract class SingleTableInheritanceEntity extends Ardent
* @return bool
*/
public function save(
array $rules = [],
array $customMessages = [],
array $options = [],
\Closure $beforeSave = null,
\Closure $afterSave = null
array $rules = [], array $customMessages = [], array $options = [], \Closure $beforeSave = null, \Closure $afterSave = null
) {
if ($this->subclassField) {
$this->attributes[$this->subclassField] = get_class($this);
@@ -118,4 +88,28 @@ abstract class SingleTableInheritanceEntity extends Ardent
return parent::save($rules, $customMessages, $options, $beforeSave, $afterSave);
}
/**
* if no subclass is defined, function as normal
*
* @param array $attributes
*
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function mapData(array $attributes)
{
if (!$this->subclassField) {
return $this->newInstance();
}
return new $attributes[$this->subclassField];
}
/**
* @return bool
*/
public function isSubclass()
{
return $this->isSubclass;
}
}